mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
fix window position save spam
(and also window position being forgotten on maximizing)
This commit is contained in:
30
index.js
30
index.js
@ -142,22 +142,44 @@ function createMainWindow() {
|
|||||||
win.on("closed", onClosed);
|
win.on("closed", onClosed);
|
||||||
|
|
||||||
win.on("move", () => {
|
win.on("move", () => {
|
||||||
|
if (win.isMaximized()) return;
|
||||||
let position = win.getPosition();
|
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", () => {
|
win.on("resize", () => {
|
||||||
const windowSize = win.getSize();
|
const windowSize = win.getSize();
|
||||||
|
|
||||||
config.set("window-maximized", win.isMaximized());
|
const isMaximized = win.isMaximized();
|
||||||
if (!win.isMaximized()) {
|
if (winWasMaximized !== isMaximized) {
|
||||||
config.set("window-size", {
|
winWasMaximized = isMaximized;
|
||||||
|
config.set("window-maximized", isMaximized);
|
||||||
|
console.log('set window-maximized to ', isMaximized) // DELETE
|
||||||
|
}
|
||||||
|
if (!isMaximized) {
|
||||||
|
lateSave("window-size", {
|
||||||
width: windowSize[0],
|
width: windowSize[0],
|
||||||
height: windowSize[1],
|
height: windowSize[1],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let savedTimeout = {
|
||||||
|
"window-position": null,
|
||||||
|
"window-siza": null
|
||||||
|
}
|
||||||
|
function lateSave(key, value) {
|
||||||
|
if (savedTimeout[key]) clearTimeout(savedTimeout[key]);
|
||||||
|
|
||||||
|
savedTimeout[key] = setTimeout(() => {
|
||||||
|
config.set(key, value);
|
||||||
|
console.log('saving ', key, value); // DELETE
|
||||||
|
savedTimeout[key] = null;
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
win.webContents.on("render-process-gone", (event, webContents, details) => {
|
win.webContents.on("render-process-gone", (event, webContents, details) => {
|
||||||
showUnresponsiveDialog(win, details);
|
showUnresponsiveDialog(win, details);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user