-
Notifications
You must be signed in to change notification settings - Fork 237
feat(compass, preferences): implement zoom level persistence COMPASS-9905 #7363
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
Changes from 6 commits
5b41506
79e7d61
44e26f8
fa1e13d
431c5b0
4ee3f96
612e246
6b4ce4d
0683939
9fb0100
bd6d862
19c2743
fae84c3
356f727
adc6866
adec59a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,27 +367,72 @@ class Application { | |
const ZOOM_INCREMENT = 0.5; | ||
const ZOOM_MAX = 5; | ||
const ZOOM_MIN = -3; | ||
const SAVE_DEBOUNCE_DELAY = 500; // 300ms delay for save operations | ||
|
||
// Debounced save zoom level to preferences | ||
let saveTimeout: NodeJS.Timeout | null = null; | ||
|
||
const debouncedSaveZoomLevel = (zoomLevel: number) => { | ||
if (saveTimeout) { | ||
clearTimeout(saveTimeout); | ||
} | ||
|
||
saveTimeout = setTimeout(async () => { | ||
try { | ||
await defaultPreferencesInstance.savePreferences({ | ||
zoomLevel, | ||
}); | ||
} catch { | ||
// noop | ||
|
||
} | ||
}, SAVE_DEBOUNCE_DELAY); | ||
}; | ||
|
||
// Restore saved zoom level | ||
const restoreZoomLevel = () => { | ||
try { | ||
const preferences = defaultPreferencesInstance.getPreferences(); | ||
const savedZoomLevel = preferences.zoomLevel ?? ZOOM_DEFAULT; | ||
|
||
// Use saved zoom level only if it's within valid range | ||
const zoomLevel = | ||
savedZoomLevel >= ZOOM_MIN && savedZoomLevel <= ZOOM_MAX | ||
? savedZoomLevel | ||
: ZOOM_DEFAULT; | ||
miya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
webFrame.setZoomLevel(zoomLevel); | ||
} catch { | ||
// noop | ||
gribnoysup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}; | ||
|
||
const zoomReset = () => { | ||
debouncedSaveZoomLevel(ZOOM_DEFAULT); | ||
return webFrame.setZoomLevel(ZOOM_DEFAULT); | ||
}; | ||
|
||
const zoomIn = () => { | ||
const currentZoomLevel = webFrame.getZoomLevel(); | ||
const newZoomLevel = Math.min( | ||
currentZoomLevel + ZOOM_INCREMENT, | ||
ZOOM_MAX | ||
); | ||
debouncedSaveZoomLevel(newZoomLevel); | ||
return webFrame.setZoomLevel(newZoomLevel); | ||
}; | ||
|
||
const zoomOut = () => { | ||
const currentZoomLevel = webFrame.getZoomLevel(); | ||
const newZoomLevel = Math.max( | ||
currentZoomLevel - ZOOM_INCREMENT, | ||
ZOOM_MIN | ||
); | ||
debouncedSaveZoomLevel(newZoomLevel); | ||
return webFrame.setZoomLevel(newZoomLevel); | ||
}; | ||
|
||
// Restore zoom level on startup | ||
restoreZoomLevel(); | ||
|
||
ipcRenderer?.on('window:zoom-reset', zoomReset); | ||
ipcRenderer?.on('window:zoom-in', zoomIn); | ||
ipcRenderer?.on('window:zoom-out', zoomOut); | ||
|
Uh oh!
There was an error while loading. Please reload this page.