From 00ee79ecdccb21589d763e833fd864cd75170d45 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 6 Feb 2023 20:43:11 +1100 Subject: [PATCH] Support named windows Remove debug info --- v3/pkg/application/application.go | 19 ++++++------------- v3/pkg/application/messageprocessor_events.go | 5 ++--- v3/pkg/application/messageprocessor_log.go | 3 +-- v3/pkg/application/webview_window.go | 9 ++++++++- v3/pkg/application/webview_window_darwin.go | 1 - v3/pkg/options/window.go | 3 +-- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/v3/pkg/application/application.go b/v3/pkg/application/application.go index 9b8843e07..33f47f354 100644 --- a/v3/pkg/application/application.go +++ b/v3/pkg/application/application.go @@ -92,10 +92,8 @@ type App struct { applicationEventListenersLock sync.RWMutex // Windows - windows map[uint]*WebviewWindow - windowsLock sync.Mutex - windowAliases map[string]uint - windowAliasesLock sync.Mutex + windows map[uint]*WebviewWindow + windowsLock sync.Mutex // System Trays systemTrays map[uint]*SystemTray @@ -196,14 +194,6 @@ func (a *App) NewWebviewWindowWithOptions(windowOptions *options.WebviewWindow) a.windows[id] = newWindow a.windowsLock.Unlock() - if windowOptions.Alias != "" { - if a.windowAliases == nil { - a.windowAliases = make(map[string]uint) - } - a.windowAliasesLock.Lock() - a.windowAliases[windowOptions.Alias] = id - a.windowAliasesLock.Unlock() - } if a.running { newWindow.run() } @@ -245,7 +235,10 @@ func (a *App) Run() error { for { event := <-webviewRequests a.handleWebViewRequest(event) - event.request.Release() + err := event.request.Release() + if err != nil { + a.error("Failed to release webview request: %s", err.Error()) + } } }() go func() { diff --git a/v3/pkg/application/messageprocessor_events.go b/v3/pkg/application/messageprocessor_events.go index 9f7a63b01..f5023064e 100644 --- a/v3/pkg/application/messageprocessor_events.go +++ b/v3/pkg/application/messageprocessor_events.go @@ -1,11 +1,10 @@ package application import ( - "fmt" "net/http" ) -func (m *MessageProcessor) processEventsMethod(method string, rw http.ResponseWriter, r *http.Request, window *WebviewWindow, params QueryParams) { +func (m *MessageProcessor) processEventsMethod(method string, rw http.ResponseWriter, _ *http.Request, window *WebviewWindow, params QueryParams) { switch method { case "Emit": @@ -19,7 +18,7 @@ func (m *MessageProcessor) processEventsMethod(method string, rw http.ResponseWr m.httpError(rw, "Event name must be specified") return } - event.Sender = fmt.Sprintf("%d", window.id) + event.Sender = window.Name() globalApplication.Events.Emit(&event) m.ok(rw) default: diff --git a/v3/pkg/application/messageprocessor_log.go b/v3/pkg/application/messageprocessor_log.go index 092614fb8..3352a980f 100644 --- a/v3/pkg/application/messageprocessor_log.go +++ b/v3/pkg/application/messageprocessor_log.go @@ -1,7 +1,6 @@ package application import ( - "fmt" "net/http" "github.com/wailsapp/wails/v3/pkg/logger" @@ -16,7 +15,7 @@ func (m *MessageProcessor) processLogMethod(method string, rw http.ResponseWrite m.httpError(rw, "error parsing log message: %s", err.Error()) return } - msg.Sender = fmt.Sprintf("%d", window.id) + msg.Sender = window.Name() globalApplication.Log(&msg) m.ok(rw) default: diff --git a/v3/pkg/application/webview_window.go b/v3/pkg/application/webview_window.go index ca7b24c16..14076f570 100644 --- a/v3/pkg/application/webview_window.go +++ b/v3/pkg/application/webview_window.go @@ -131,6 +131,13 @@ func (w *WebviewWindow) SetTitle(title string) *WebviewWindow { return w } +func (w *WebviewWindow) Name() string { + if w.options.Name != "" { + return w.options.Name + } + return fmt.Sprintf("Window %d", w.id) +} + func (w *WebviewWindow) SetSize(width, height int) *WebviewWindow { // Don't set size if fullscreen if w.IsFullscreen() { @@ -630,7 +637,7 @@ func (w *WebviewWindow) info(message string, args ...any) { Level: "INFO", Message: message, Data: args, - Sender: fmt.Sprintf("window %d", w.id), + Sender: w.Name(), Time: time.Now(), }) } diff --git a/v3/pkg/application/webview_window_darwin.go b/v3/pkg/application/webview_window_darwin.go index 94bb8fa37..aaa2b60fb 100644 --- a/v3/pkg/application/webview_window_darwin.go +++ b/v3/pkg/application/webview_window_darwin.go @@ -1105,7 +1105,6 @@ func (w *macosWebviewWindow) run() { if w.parent.options.Hidden == false { C.windowShow(w.nsWindow) } - C.printWindowStyle(w.nsWindow) }) } diff --git a/v3/pkg/options/window.go b/v3/pkg/options/window.go index 5f2ff7679..ec49ae203 100644 --- a/v3/pkg/options/window.go +++ b/v3/pkg/options/window.go @@ -15,8 +15,7 @@ const ( ) type WebviewWindow struct { - // Alias is a human-readable name for the window. This can be used to reference the window in the frontend. - Alias string + Name string Title string Width, Height int AlwaysOnTop bool