From be9ee043ccfe5823c65f55444554724401962655 Mon Sep 17 00:00:00 2001 From: Jean Brito Date: Fri, 29 Sep 2023 13:34:35 -0300 Subject: [PATCH 1/3] fix zoom level shortcuts --- src/ui/main/menuBar.ts | 52 +++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/src/ui/main/menuBar.ts b/src/ui/main/menuBar.ts index e2fb00280..26e2e637e 100644 --- a/src/ui/main/menuBar.ts +++ b/src/ui/main/menuBar.ts @@ -178,6 +178,22 @@ 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; + } + console.log('zoom url', url); + return getWebContentsByServerUrl(url); +}; + const createViewMenu = createSelector( selectViewDeps, ({ @@ -376,17 +392,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 +401,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 +418,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; From f37e8c46be255954a27b2bf9ebd362d217347b51 Mon Sep 17 00:00:00 2001 From: Jean Brito Date: Fri, 10 Nov 2023 13:50:02 -0300 Subject: [PATCH 2/3] Merge branch 'master' into fix/zoom-level From e464ac739edb4792c8ac0d211c45b238a2b8aa6e Mon Sep 17 00:00:00 2001 From: Jean Brito Date: Fri, 10 Nov 2023 14:13:31 -0300 Subject: [PATCH 3/3] remove log --- src/ui/main/menuBar.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ui/main/menuBar.ts b/src/ui/main/menuBar.ts index 26e2e637e..016149927 100644 --- a/src/ui/main/menuBar.ts +++ b/src/ui/main/menuBar.ts @@ -190,7 +190,6 @@ const getCurrentViewWebcontents = async () => { if (!url) { return null; } - console.log('zoom url', url); return getWebContentsByServerUrl(url); };