5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 15:11:53 +08:00

Support named windows

Remove debug info
This commit is contained in:
Lea Anthony 2023-02-06 20:43:11 +11:00
parent f94e798c50
commit 00ee79ecdc
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
6 changed files with 18 additions and 22 deletions

View File

@ -92,10 +92,8 @@ type App struct {
applicationEventListenersLock sync.RWMutex applicationEventListenersLock sync.RWMutex
// Windows // Windows
windows map[uint]*WebviewWindow windows map[uint]*WebviewWindow
windowsLock sync.Mutex windowsLock sync.Mutex
windowAliases map[string]uint
windowAliasesLock sync.Mutex
// System Trays // System Trays
systemTrays map[uint]*SystemTray systemTrays map[uint]*SystemTray
@ -196,14 +194,6 @@ func (a *App) NewWebviewWindowWithOptions(windowOptions *options.WebviewWindow)
a.windows[id] = newWindow a.windows[id] = newWindow
a.windowsLock.Unlock() 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 { if a.running {
newWindow.run() newWindow.run()
} }
@ -245,7 +235,10 @@ func (a *App) Run() error {
for { for {
event := <-webviewRequests event := <-webviewRequests
a.handleWebViewRequest(event) 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() { go func() {

View File

@ -1,11 +1,10 @@
package application package application
import ( import (
"fmt"
"net/http" "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 { switch method {
case "Emit": case "Emit":
@ -19,7 +18,7 @@ func (m *MessageProcessor) processEventsMethod(method string, rw http.ResponseWr
m.httpError(rw, "Event name must be specified") m.httpError(rw, "Event name must be specified")
return return
} }
event.Sender = fmt.Sprintf("%d", window.id) event.Sender = window.Name()
globalApplication.Events.Emit(&event) globalApplication.Events.Emit(&event)
m.ok(rw) m.ok(rw)
default: default:

View File

@ -1,7 +1,6 @@
package application package application
import ( import (
"fmt"
"net/http" "net/http"
"github.com/wailsapp/wails/v3/pkg/logger" "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()) m.httpError(rw, "error parsing log message: %s", err.Error())
return return
} }
msg.Sender = fmt.Sprintf("%d", window.id) msg.Sender = window.Name()
globalApplication.Log(&msg) globalApplication.Log(&msg)
m.ok(rw) m.ok(rw)
default: default:

View File

@ -131,6 +131,13 @@ func (w *WebviewWindow) SetTitle(title string) *WebviewWindow {
return w 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 { func (w *WebviewWindow) SetSize(width, height int) *WebviewWindow {
// Don't set size if fullscreen // Don't set size if fullscreen
if w.IsFullscreen() { if w.IsFullscreen() {
@ -630,7 +637,7 @@ func (w *WebviewWindow) info(message string, args ...any) {
Level: "INFO", Level: "INFO",
Message: message, Message: message,
Data: args, Data: args,
Sender: fmt.Sprintf("window %d", w.id), Sender: w.Name(),
Time: time.Now(), Time: time.Now(),
}) })
} }

View File

@ -1105,7 +1105,6 @@ func (w *macosWebviewWindow) run() {
if w.parent.options.Hidden == false { if w.parent.options.Hidden == false {
C.windowShow(w.nsWindow) C.windowShow(w.nsWindow)
} }
C.printWindowStyle(w.nsWindow)
}) })
} }

View File

@ -15,8 +15,7 @@ const (
) )
type WebviewWindow struct { type WebviewWindow struct {
// Alias is a human-readable name for the window. This can be used to reference the window in the frontend. Name string
Alias string
Title string Title string
Width, Height int Width, Height int
AlwaysOnTop bool AlwaysOnTop bool