zoom persistenz
This commit is contained in:
23
main.ts
23
main.ts
@@ -709,6 +709,7 @@ if (
|
||||
|
||||
// Native resize tracking using Deno 2.9 BrowserWindow events
|
||||
let resizeTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let sizeSeenFromEvent = false;
|
||||
try {
|
||||
win.addEventListener(
|
||||
"resize",
|
||||
@@ -720,6 +721,7 @@ try {
|
||||
if (w >= 1100 && h >= 700) {
|
||||
settings.windowWidth = w;
|
||||
settings.windowHeight = h;
|
||||
sizeSeenFromEvent = true;
|
||||
}
|
||||
resizeTimer = setTimeout(() => {
|
||||
if (settings.windowWidth >= 1100 && settings.windowHeight >= 700) {
|
||||
@@ -740,17 +742,28 @@ try {
|
||||
"close",
|
||||
(() => {
|
||||
if (resizeTimer !== undefined) clearTimeout(resizeTimer);
|
||||
const [fw, fh] = win.getSize();
|
||||
if (fw >= 1100 && fh >= 700) {
|
||||
settings.windowWidth = fw;
|
||||
settings.windowHeight = fh;
|
||||
// Prefer the size reported by native resize events. getSize() has
|
||||
// been observed to return a stale value (the last programmatically
|
||||
// requested size) instead of the actual user-resized window size,
|
||||
// which caused the same size to be saved on every close. Only fall
|
||||
// back to getSize() if no resize event was ever received.
|
||||
if (!sizeSeenFromEvent) {
|
||||
try {
|
||||
const [fw, fh] = win.getSize();
|
||||
if (fw >= 1100 && fh >= 700) {
|
||||
settings.windowWidth = fw;
|
||||
settings.windowHeight = fh;
|
||||
}
|
||||
} catch { /* ok */ }
|
||||
}
|
||||
try {
|
||||
const path = resolveSettingsPath();
|
||||
Deno.mkdirSync(dirname(path), { recursive: true });
|
||||
Deno.writeTextFileSync(path, JSON.stringify(settings, null, 2));
|
||||
console.log(
|
||||
`${PREFIX} Window size saved on close: ${settings.windowWidth}x${settings.windowHeight}`,
|
||||
`${PREFIX} Window size saved on close: ${settings.windowWidth}x${settings.windowHeight} (source: ${
|
||||
sizeSeenFromEvent ? "resize events" : "getSize()"
|
||||
})`,
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
|
||||
Reference in New Issue
Block a user