fix: bug keeping location and size of the window
This commit is contained in:
@@ -1010,12 +1010,18 @@ func (a *App) startup(ctx context.Context) {
|
||||
go a.liveStatusLoop() // multi-op: heartbeat current activity to shared MySQL
|
||||
go a.chatLoop() // multi-op: poll the shared chat + heartbeat presence
|
||||
|
||||
// Reopen where the window was last left (size + position).
|
||||
a.restoreWindowState()
|
||||
|
||||
fmt.Println("OpsLog: db ready at", a.dbPath)
|
||||
}
|
||||
|
||||
// domReady fires once the frontend has painted. The window was created hidden
|
||||
// (StartHidden), so we place it at its saved geometry FIRST and only then show
|
||||
// it — it appears already sized and positioned, never jumping into place after
|
||||
// launch. Show is unconditional: whatever happens above, the window must appear.
|
||||
func (a *App) domReady(ctx context.Context) {
|
||||
a.restoreWindowPosition()
|
||||
wruntime.WindowShow(ctx)
|
||||
}
|
||||
|
||||
// StartupStatus returns a diagnostic snapshot for the frontend.
|
||||
// dbPath is always populated; err is empty when the app is healthy.
|
||||
type StartupStatus struct {
|
||||
@@ -1353,24 +1359,22 @@ func (a *App) saveWindowState() {
|
||||
writeWindowState(a.dataDir, ws)
|
||||
}
|
||||
|
||||
// restoreWindowState reopens the window where it was last left. The window is
|
||||
// CREATED maximised (WindowStartState in main.go), which is also the first-run
|
||||
// default — so we only act when a windowed geometry was saved, leaving the
|
||||
// maximised majority untouched and flash-free.
|
||||
func (a *App) restoreWindowState() {
|
||||
// restoreWindowPosition places the window at its saved X/Y. Size and maximised
|
||||
// state are already applied at creation (main.go, from options), so only the
|
||||
// position — which options can't express — remains, and it is set here while the
|
||||
// window is still hidden, so there is no visible jump. Nothing to do for a
|
||||
// maximised or first-run window.
|
||||
func (a *App) restoreWindowPosition() {
|
||||
if a.ctx == nil {
|
||||
return
|
||||
}
|
||||
ws, ok := readWindowState(a.dataDir)
|
||||
if !ok || ws.Maximised {
|
||||
return // first run, or last closed maximised — the default already covers it
|
||||
}
|
||||
// Guard against a corrupt / absurd size that would open an unusable window.
|
||||
if ws.Width < normalMinW || ws.Height < normalMinH || ws.Width > maxW || ws.Height > maxH {
|
||||
return
|
||||
}
|
||||
wruntime.WindowUnmaximise(a.ctx)
|
||||
wruntime.WindowSetSize(a.ctx, ws.Width, ws.Height)
|
||||
if ws.Width < normalMinW || ws.Height < normalMinH || ws.Width > maxW || ws.Height > maxH {
|
||||
return // corrupt / absurd — leave the default placement
|
||||
}
|
||||
wruntime.WindowSetPosition(a.ctx, ws.X, ws.Y)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user