Skip to content

Commit

Permalink
app: Remember zoom level after restarts
Browse files Browse the repository at this point in the history
This change adds a new environment variable "ZOOM_LEVEL" to remember the
zoom level in the Electron app after restarts.

Fixes: #2681

Signed-off-by: Evangelos Skopelitis <[email protected]>
  • Loading branch information
skoeva committed Jan 13, 2025
1 parent 046cf38 commit 52ca4b8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,9 @@ function startElecron() {
const withMargin = isWSL();
const { width, height } = windowSize(screen.getPrimaryDisplay().workAreaSize, withMargin);

const defaultZoomLevel = 1;
let currentZoomLevel = parseFloat(process.env.ZOOM_LEVEL || `${defaultZoomLevel}`);

mainWindow = new BrowserWindow({
width,
height,
Expand All @@ -1042,6 +1045,18 @@ function startElecron() {
},
});

mainWindow.webContents.setZoomFactor(currentZoomLevel);

mainWindow.webContents.on('zoom-changed', (_, zoomDirection) => {
if (zoomDirection === 'in') {
currentZoomLevel += 0.1;
} else {
currentZoomLevel -= 0.1;
}
mainWindow?.webContents.setZoomFactor(currentZoomLevel);
process.env.ZOOM_LEVEL = currentZoomLevel.toString();
});

setMenu(mainWindow, currentMenu);

mainWindow.webContents.setWindowOpenHandler(({ url }) => {
Expand Down

0 comments on commit 52ca4b8

Please sign in to comment.