mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
desktop: save window state eagerly as soon as its updated
This commit is contained in:
committed by
Abdullah Atta
parent
f2c0c34c10
commit
f75c010ecb
@@ -43,7 +43,7 @@ export class WindowState {
|
||||
private readonly config: WindowStateOptions;
|
||||
private state: SerializableWindowState;
|
||||
private windowRef: BrowserWindow | undefined;
|
||||
private readonly eventHandlingDelay = 100;
|
||||
private readonly eventHandlingDelay = 1000;
|
||||
private stateChangeTimer: NodeJS.Timeout | undefined;
|
||||
|
||||
constructor(options?: Partial<WindowStateOptions>) {
|
||||
@@ -176,7 +176,7 @@ export class WindowState {
|
||||
// Handles both 'resize' and 'move'
|
||||
if (this.stateChangeTimer) clearTimeout(this.stateChangeTimer);
|
||||
this.stateChangeTimer = setTimeout(
|
||||
() => this.updateState(),
|
||||
() => this.saveState(this.windowRef),
|
||||
this.eventHandlingDelay
|
||||
);
|
||||
};
|
||||
@@ -199,8 +199,8 @@ export class WindowState {
|
||||
if (this.config.fullScreen && this.state.isFullScreen) {
|
||||
win.setFullScreen(true);
|
||||
}
|
||||
win.on("resize", this.stateChangeHandler);
|
||||
win.on("move", this.stateChangeHandler);
|
||||
win.on("resized", this.stateChangeHandler);
|
||||
win.on("moved", this.stateChangeHandler);
|
||||
win.on("close", this.closeHandler);
|
||||
win.on("closed", this.closedHandler);
|
||||
this.windowRef = win;
|
||||
@@ -208,8 +208,8 @@ export class WindowState {
|
||||
|
||||
unmanage() {
|
||||
if (this.windowRef) {
|
||||
this.windowRef.removeListener("resize", this.stateChangeHandler);
|
||||
this.windowRef.removeListener("move", this.stateChangeHandler);
|
||||
this.windowRef.removeListener("resized", this.stateChangeHandler);
|
||||
this.windowRef.removeListener("moved", this.stateChangeHandler);
|
||||
if (this.stateChangeTimer) clearTimeout(this.stateChangeTimer);
|
||||
this.windowRef.removeListener("close", this.closeHandler);
|
||||
this.windowRef.removeListener("closed", this.closedHandler);
|
||||
|
||||
Reference in New Issue
Block a user