Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix window position save spam #562

Merged
merged 4 commits into from
Feb 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,39 @@ function createMainWindow() {
win.on("closed", onClosed);

win.on("move", () => {
if (win.isMaximized()) return;
let position = win.getPosition();
config.set("window-position", { x: position[0], y: position[1] });
lateSave("window-position", { x: position[0], y: position[1] });
});

let winWasMaximized;

win.on("resize", () => {
const windowSize = win.getSize();

config.set("window-maximized", win.isMaximized());
if (!win.isMaximized()) {
config.set("window-size", {
const isMaximized = win.isMaximized();
if (winWasMaximized !== isMaximized) {
winWasMaximized = isMaximized;
config.set("window-maximized", isMaximized);
}
if (!isMaximized) {
lateSave("window-size", {
width: windowSize[0],
height: windowSize[1],
});
}
});

let savedTimeouts = {};
function lateSave(key, value) {
th-ch marked this conversation as resolved.
Show resolved Hide resolved
if (savedTimeouts[key]) clearTimeout(savedTimeouts[key]);

savedTimeouts[key] = setTimeout(() => {
config.set(key, value);
savedTimeouts[key] = undefined;
}, 1000)
}

win.webContents.on("render-process-gone", (event, webContents, details) => {
showUnresponsiveDialog(win, details);
});
Expand Down