From 454ab1e7bd7ec50ca0764d8deeec12f4285f1431 Mon Sep 17 00:00:00 2001 From: David Kramer Date: Sun, 22 Apr 2018 12:54:29 -0700 Subject: [PATCH] Fix #474: Remember custom zoom level (PR #582) ... by using setZoomFactor instead of sending change-zoom event. --- app/src/components/mainWindow/mainWindow.js | 18 ++++++++---------- app/src/static/preload.js | 6 +----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/src/components/mainWindow/mainWindow.js b/app/src/components/mainWindow/mainWindow.js index 17a7df6..ad30bc0 100644 --- a/app/src/components/mainWindow/mainWindow.js +++ b/app/src/components/mainWindow/mainWindow.js @@ -102,20 +102,18 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) { fs.writeFileSync(path.join(__dirname, '..', 'nativefier.json'), JSON.stringify(options)); } - let currentZoom = options.zoom; - - const onZoomIn = () => { - currentZoom += ZOOM_INTERVAL; - mainWindow.webContents.send('change-zoom', currentZoom); + const adjustWindowZoom = (window, adjustment) => { + window.webContents.getZoomFactor((zoomFactor) => { + window.webContents.setZoomFactor(zoomFactor + adjustment); + }); }; - const onZoomOut = () => { - currentZoom -= ZOOM_INTERVAL; - mainWindow.webContents.send('change-zoom', currentZoom); - }; + const onZoomIn = () => adjustWindowZoom(mainWindow, ZOOM_INTERVAL); + + const onZoomOut = () => adjustWindowZoom(mainWindow, -ZOOM_INTERVAL); const onZoomReset = () => { - mainWindow.webContents.send('change-zoom', options.zoom); + mainWindow.webContents.setZoomFactor(options.zoom); }; const clearAppData = () => { diff --git a/app/src/static/preload.js b/app/src/static/preload.js index ef5d065..3ecea31 100644 --- a/app/src/static/preload.js +++ b/app/src/static/preload.js @@ -1,7 +1,7 @@ /** Preload file that will be executed in the renderer process */ -import { ipcRenderer, webFrame } from 'electron'; +import { ipcRenderer } from 'electron'; import path from 'path'; import fs from 'fs'; @@ -78,7 +78,3 @@ ipcRenderer.on('debug', (event, message) => { // eslint-disable-next-line no-console log.info('debug:', message); }); - -ipcRenderer.on('change-zoom', (event, message) => { - webFrame.setZoomFactor(message); -});