Skip to content

Commit 398eef9

Browse files
hrb-hubBijinDev
andcommitted
Save window bounds on move/resize
Close #9575 Co-authored-by: bir <[email protected]>
1 parent 1eef496 commit 398eef9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/common/desktop/DesktopWindowManager.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { RemoteBridge } from "./ipc/RemoteBridge.js"
1616
import { ASSET_PROTOCOL } from "./net/ProtocolProxy.js"
1717

1818
import { SseInfo } from "./sse/SseInfo.js"
19-
import { LazyLoaded } from "@tutao/tutanota-utils"
19+
import { debounce, LazyLoaded } from "@tutao/tutanota-utils"
2020

2121
const TAG = "[DesktopWindowManager]"
2222

@@ -109,6 +109,7 @@ export class WindowManager {
109109
await this.loadStartingBounds()
110110
const w: ApplicationWindow = await this._newWindowFactory(noAutoLogin)
111111
windows.unshift(w)
112+
112113
w.on("close", () => {
113114
w.setUserId(null)
114115
})
@@ -137,13 +138,20 @@ export class WindowManager {
137138
w.setBounds(this._currentBounds)
138139
if (showWhenReady) w.show()
139140
})
141+
.on("move", () => {
142+
// `move` event also fires on `resize` on windows and linux, but not on mac (so we also handle `resize`)
143+
this.saveWindowBounds(w)
144+
})
145+
.on("resize", () => {
146+
this.saveWindowBounds(w)
147+
})
140148
.webContents.on("did-start-navigation", () => {
141149
this._tray.clearBadge()
142150
})
143151
.on("zoom-changed", (ev: Event, direction: "in" | "out") => {
144152
let scale = (this._currentBounds.scale * 100 + (direction === "out" ? -5 : 5)) / 100
145153
this.changeZoom(scale)
146-
this.saveBounds(w.getBounds())
154+
this.saveWindowBounds(w)
147155
})
148156
.on("did-navigate", () => {
149157
// electron likes to override the zoom factor when the URL changes.
@@ -267,6 +275,10 @@ export class WindowManager {
267275
this._conf.setVar(DesktopConfigKey.lastBounds, this._currentBounds)
268276
}
269277

278+
saveWindowBounds = debounce(100, (w: ApplicationWindow) => {
279+
this.saveBounds(w.getBounds())
280+
})
281+
270282
_setSpellcheckLang(l: string): void {
271283
this._electron.session.defaultSession.setSpellCheckerLanguages(l === "" ? [] : [l])
272284
}

0 commit comments

Comments
 (0)