Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
12 changes: 12 additions & 0 deletions packages/compass-preferences-model/src/preferences-schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export type InternalUserPreferences = {
// TODO: Remove this as part of COMPASS-8970.
enableConnectInNewWindow: boolean;
showEndOfLifeConnectionModal: boolean;
zoomLevel?: number;
};

// UserPreferences contains all preferences stored to disk.
Expand Down Expand Up @@ -459,6 +460,17 @@ export const storedUserPreferencesProps: Required<{
),
type: 'boolean',
},
/**
* Zoom level for restoring browser zoom state.
*/
zoomLevel: {
ui: false,
cli: false,
global: false,
description: null,
validator: z.number().optional(),
type: 'number',
},
/**
* Enable/disable the AI services. This is currently set
* in the atlas-service initialization where we make a request to the
Expand Down
45 changes: 45 additions & 0 deletions packages/compass/src/app/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The saveTimeout variable is declared in function scope but needs to persist across multiple function calls. Consider moving this to a higher scope or using a closure to avoid potential issues with variable lifecycle.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: 6b4ce4d

const debouncedSaveZoomLevel = (zoomLevel: number) => {
if (saveTimeout) {
clearTimeout(saveTimeout);
}

saveTimeout = setTimeout(async () => {
try {
await defaultPreferencesInstance.savePreferences({
zoomLevel,
});
} catch {
// noop
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty catch block with 'noop' comment provides no debugging information. Consider logging the error or adding a more descriptive comment explaining why errors are intentionally ignored.

Copilot uses AI. Check for mistakes.

}
}, 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;

webFrame.setZoomLevel(zoomLevel);
} catch {
// noop
}
};

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);
Expand Down