feat: persist main window state
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
@@ -17,7 +18,8 @@ type AppService struct {
|
||||
SecondWindow *application.WebviewWindow
|
||||
MainWindow *application.WebviewWindow
|
||||
|
||||
Config *AppConfigService
|
||||
Config *AppConfigService
|
||||
windowStateMu sync.Mutex
|
||||
|
||||
Tray *application.SystemTray
|
||||
I18nFS embed.FS
|
||||
@@ -45,15 +47,16 @@ func ConfigureAppService(a *AppService, app *application.App, i18nFS embed.FS, s
|
||||
a.Config = NewAppConfigService(suidb)
|
||||
|
||||
isWindows := runtime.GOOS == "windows"
|
||||
mainWindowState := a.loadMainWindowStateOptions()
|
||||
mainWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||
Title: "main",
|
||||
Name: "main",
|
||||
Width: mainWindowWidth,
|
||||
Height: mainWindowHeight,
|
||||
Width: mainWindowState.Width,
|
||||
Height: mainWindowState.Height,
|
||||
MinWidth: mainWindowMinWidth,
|
||||
MinHeight: mainWindowMinHeight,
|
||||
InitialPosition: application.WindowCentered,
|
||||
StartState: application.WindowStateNormal,
|
||||
StartState: mainWindowState.StartState,
|
||||
DisableResize: false,
|
||||
Frameless: isWindows,
|
||||
Mac: application.MacWindow{
|
||||
@@ -83,6 +86,7 @@ func ConfigureAppService(a *AppService, app *application.App, i18nFS embed.FS, s
|
||||
secondWindow.Hide()
|
||||
a.SecondWindow = secondWindow
|
||||
a.MainWindow = mainWindow
|
||||
a.registerMainWindowStatePersistence()
|
||||
|
||||
RegisterWindowAndCallback(HotkeyShowSecondWindow, a.SecondWindow, func() {
|
||||
if a.SecondWindow == nil {
|
||||
@@ -93,6 +97,7 @@ func ConfigureAppService(a *AppService, app *application.App, i18nFS embed.FS, s
|
||||
})
|
||||
|
||||
a.MainWindow.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||
a.persistMainWindowState()
|
||||
a.MainWindow.Hide()
|
||||
e.Cancel()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user