From efdc7e58c4ff8455856ed4f6aeb098bba97122e0 Mon Sep 17 00:00:00 2001 From: Matthew Rheaume Date: Thu, 18 Aug 2022 06:11:38 -0700 Subject: [PATCH] Fixed reload & zoom in Flipper Desktop application. (#3840) Summary: After the upgrade to Electron in `92cdb81`, the reload functionality no longer works. I believe this is due to the main menu creation being moved to the main process where the `window` global variable is undefined (whereas previously it was on the render process, where `window` would be defined). Rather than rely on the `window` global, when a reload is requested just reload the given `focusedWindow`. Similarly, zooming was also broken, so fix that by going through `focusedWindow` rather than `webFrame` (since `webFrame` only exists in the render process). Fixes https://github.com/facebook/flipper/issues/3839, https://github.com/facebook/flipper/issues/3820 ## Changelog changelog: Fixed reload & zoom in Flipper Desktop application. Pull Request resolved: https://github.com/facebook/flipper/pull/3840 Test Plan: Built the application locally, verified that reload worked as expected (and would reload the application), verified that zooming (in, out, actual size) worked as expected. Reviewed By: passy Differential Revision: D38784319 Pulled By: mweststrate fbshipit-source-id: c219063a8aaf42425678c2c8824f6fcde1cadd52 --- desktop/static/setupMenuBar.tsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/desktop/static/setupMenuBar.tsx b/desktop/static/setupMenuBar.tsx index 96c356064..5d71eeca3 100644 --- a/desktop/static/setupMenuBar.tsx +++ b/desktop/static/setupMenuBar.tsx @@ -8,7 +8,7 @@ */ // eslint-disable-next-line no-restricted-imports -import electron, {MenuItemConstructorOptions, webFrame} from 'electron'; +import electron, {MenuItemConstructorOptions} from 'electron'; import {ElectronIpcClientMain} from './electronIpcMain'; export function setupMenuBar(electronIpcClient: ElectronIpcClientMain) { @@ -68,8 +68,10 @@ function getTemplate( accelerator: (function () { return 'CmdOrCtrl+0'; })(), - click: function (_, _focusedWindow: electron.BrowserWindow | undefined) { - webFrame.setZoomFactor(1); + click: function (_, focusedWindow: electron.BrowserWindow | undefined) { + if (focusedWindow) { + focusedWindow.webContents.setZoomLevel(0); + } }, }, { @@ -77,8 +79,11 @@ function getTemplate( accelerator: (function () { return 'CmdOrCtrl+='; })(), - click: function (_, _focusedWindow: electron.BrowserWindow | undefined) { - webFrame.setZoomFactor(webFrame.getZoomFactor() + 0.25); + click: function (_, focusedWindow: electron.BrowserWindow | undefined) { + if (focusedWindow) { + const webContents = focusedWindow.webContents; + webContents.setZoomLevel(webContents.getZoomLevel() + 1); + } }, }, { @@ -86,8 +91,11 @@ function getTemplate( accelerator: (function () { return 'CmdOrCtrl+-'; })(), - click: function (_, _focusedWindow: electron.BrowserWindow | undefined) { - webFrame.setZoomFactor(webFrame.getZoomFactor() - 0.25); + click: function (_, focusedWindow: electron.BrowserWindow | undefined) { + if (focusedWindow) { + const webContents = focusedWindow.webContents; + webContents.setZoomLevel(webContents.getZoomLevel() - 1); + } }, }, {