diff --git a/pkg/window/wails.go b/pkg/window/wails.go index b899d7b..006cc6d 100644 --- a/pkg/window/wails.go +++ b/pkg/window/wails.go @@ -45,7 +45,7 @@ func (wp *WailsPlatform) GetWindows() []PlatformWindow { out := make([]PlatformWindow, 0, len(all)) for _, w := range all { if wv, ok := w.(*application.WebviewWindow); ok { - out = append(out, &wailsWindow{w: wv}) + out = append(out, &wailsWindow{w: wv, title: wv.Name()}) } } return out @@ -58,8 +58,16 @@ type wailsWindow struct { title string } -func (ww *wailsWindow) Name() string { return ww.w.Name() } -func (ww *wailsWindow) Title() string { return ww.title } +func (ww *wailsWindow) Name() string { return ww.w.Name() } +func (ww *wailsWindow) Title() string { + if ww.title != "" { + return ww.title + } + if ww.w != nil { + return ww.w.Name() + } + return "" +} func (ww *wailsWindow) Position() (int, int) { return ww.w.Position() } func (ww *wailsWindow) Size() (int, int) { return ww.w.Size() } func (ww *wailsWindow) IsVisible() bool { return ww.w.IsVisible() } diff --git a/pkg/window/window_test.go b/pkg/window/window_test.go index e5c8a0d..e589680 100644 --- a/pkg/window/window_test.go +++ b/pkg/window/window_test.go @@ -178,6 +178,18 @@ func TestWailsWindow_DevToolsToggle_Good(t *testing.T) { assert.False(t, ww.w.DevToolsOpen()) } +func TestWailsPlatform_GetWindows_TitleFallback_Good(t *testing.T) { + app := application.NewApp() + platform := NewWailsPlatform(app) + + pw := platform.CreateWindow(PlatformWindowOptions{Name: "fallback"}) + require.NotNil(t, pw) + + windows := platform.GetWindows() + require.Len(t, windows, 1) + assert.Equal(t, "fallback", windows[0].Title()) +} + // --- StateManager Tests --- // newTestStateManager creates a clean StateManager with a temp dir for testing.