From 4de6a751cf445ac0c0a00f1073c0bbf8efce9347 Mon Sep 17 00:00:00 2001 From: Jean Brito Date: Fri, 10 Nov 2023 14:19:15 -0300 Subject: [PATCH] fix: zoom level on servers (#2770) * fix zoom level shortcuts * Merge branch 'master' into fix/zoom-level * remove log --- src/ui/main/menuBar.ts | 51 +++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/src/ui/main/menuBar.ts b/src/ui/main/menuBar.ts index e2fb00280..016149927 100644 --- a/src/ui/main/menuBar.ts +++ b/src/ui/main/menuBar.ts @@ -178,6 +178,21 @@ const selectViewDeps = createStructuredSelector< rootWindowState: ({ rootWindowState }) => rootWindowState, }); +const getCurrentViewWebcontents = async () => { + const browserWindow = await getRootWindow(); + + if (!browserWindow.isVisible()) { + browserWindow.showInactive(); + } + browserWindow.focus(); + const currentView = select(({ currentView }) => currentView); + const url = typeof currentView === 'object' ? currentView.url : null; + if (!url) { + return null; + } + return getWebContentsByServerUrl(url); +}; + const createViewMenu = createSelector( selectViewDeps, ({ @@ -376,17 +391,7 @@ const createViewMenu = createSelector( label: t('menus.resetZoom'), accelerator: 'CommandOrControl+0', click: async () => { - const browserWindow = await getRootWindow(); - - if (!browserWindow.isVisible()) { - browserWindow.showInactive(); - } - browserWindow.focus(); - const url = typeof currentView === 'object' ? currentView.url : null; - if (!url) { - return; - } - const guestWebContents = getWebContentsByServerUrl(url); + const guestWebContents = await getCurrentViewWebcontents(); guestWebContents?.setZoomLevel(0); }, }, @@ -395,16 +400,7 @@ const createViewMenu = createSelector( label: t('menus.zoomIn'), accelerator: 'CommandOrControl+Plus', click: async () => { - const browserWindow = await getRootWindow(); - if (!browserWindow.isVisible()) { - browserWindow.showInactive(); - } - browserWindow.focus(); - const url = typeof currentView === 'object' ? currentView.url : null; - if (!url) { - return; - } - const guestWebContents = getWebContentsByServerUrl(url); + const guestWebContents = await getCurrentViewWebcontents(); if (!guestWebContents) { return; } @@ -421,21 +417,10 @@ const createViewMenu = createSelector( label: t('menus.zoomOut'), accelerator: 'CommandOrControl+-', click: async () => { - const browserWindow = await getRootWindow(); - if (!browserWindow.isVisible()) { - browserWindow.showInactive(); - } - browserWindow.focus(); - const url = typeof currentView === 'object' ? currentView.url : null; - if (!url) { - return; - } - - const guestWebContents = getWebContentsByServerUrl(url); + const guestWebContents = await getCurrentViewWebcontents(); if (!guestWebContents) { return; } - const zoomLevel = guestWebContents.getZoomLevel(); if (zoomLevel <= -9) { return;