From 7b6e39134873481c3847a565c5493922f676cb54 Mon Sep 17 00:00:00 2001 From: "Mr. Stallion" Date: Mon, 6 Sep 2021 19:57:01 -0500 Subject: [PATCH] Fix zoom --- electron/Index.vue | 5 ++++ electron/Window.vue | 7 ++++++ electron/main.ts | 56 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/electron/Index.vue b/electron/Index.vue index 3a438e2..a0c22c1 100644 --- a/electron/Index.vue +++ b/electron/Index.vue @@ -330,6 +330,11 @@ (this.$refs['fixLogsModal']).show(); }); + electron.ipcRenderer.on('update-zoom', (_e, zoomLevel) => { + webContents.setZoomLevel(zoomLevel); + // log.info('INDEXVUE ZOOM UPDATE', zoomLevel); + }); + window.addEventListener('keydown', (e) => { const key = getKey(e); diff --git a/electron/Window.vue b/electron/Window.vue index 1c533bb..259ac65 100644 --- a/electron/Window.vue +++ b/electron/Window.vue @@ -49,6 +49,8 @@ const browserWindow = electron.remote.getCurrentWindow(); + // void browserWindow.webContents.setVisualZoomLevelLimits(1, 5); + function getWindowBounds(): Electron.Rectangle { const bounds = browserWindow.getContentBounds(); const height = document.body.offsetHeight; @@ -132,6 +134,11 @@ } }); + // electron.ipcRenderer.on('update-zoom', (_e: Event, zoomLevel: number) => { + // // log.info('WINDOWVUE ZOOM UPDATE', zoomLevel); + // // browserWindow.webContents.setZoomLevel(zoomLevel); + // }); + electron.ipcRenderer.on('connect', (_e: Event, id: number, name: string) => { const tab = this.tabMap[id]; tab.user = name; diff --git a/electron/main.ts b/electron/main.ts index f7f1e8b..0abb8f9 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -170,6 +170,9 @@ function setUpWebContents(webContents: Electron.WebContents): void { else return electron.shell.openExternal(linkUrl); }; + webContents.setVisualZoomLevelLimits(1, 5); + + webContents.on('will-navigate', openLinkExternally); webContents.on('new-window', openLinkExternally); } @@ -338,6 +341,8 @@ function showPatchNotes(): void { } +let zoomLevel = 0; + function onReady(): void { let hasCompletedUpgrades = false; @@ -408,9 +413,49 @@ function onReady(): void { const viewItem = { label: `&${l('action.view')}`, submenu: [ - {role: 'resetzoom'}, - {role: 'zoomin'}, - {role: 'zoomout'}, + // {role: 'resetZoom'}, + { + label: 'Reset Zoom', + click: (_m: Electron.MenuItem, w: Electron.BrowserWindow) => { + // log.info('MENU ZOOM0'); + // w.webContents.setZoomLevel(0); + + zoomLevel = 0; + + for(const win of electron.webContents.getAllWebContents()) win.send('update-zoom', 0); + for(const win of windows) win.webContents.send('update-zoom', 0); + }, + accelerator: 'CmdOrCtrl+0' + }, + { + // role: 'zoomIn', + label: 'Zoom In', + click: (_m: Electron.MenuItem, w: Electron.BrowserWindow) => { + + // log.info('MENU ZOOM+'); + zoomLevel = Math.min(zoomLevel + w.webContents.getZoomFactor()/2, 6); + // w.webContents.setZoomLevel(newZoom); + + for(const win of electron.webContents.getAllWebContents()) win.send('update-zoom', zoomLevel); + for(const win of windows) win.webContents.send('update-zoom', zoomLevel); + }, + accelerator: 'CmdOrCtrl+Plus' + }, + { + // role: 'zoomIn', + label: 'Zoom Out', + click: (_m: Electron.MenuItem, w: Electron.BrowserWindow) => { + // log.info('MENU ZOOM-'); + zoomLevel = Math.max(0, zoomLevel - w.webContents.getZoomFactor()/2); + + // w.webContents.setZoomLevel(newZoom); + + for(const win of electron.webContents.getAllWebContents()) win.send('update-zoom', zoomLevel); + for(const win of windows) win.webContents.send('update-zoom', zoomLevel); + }, + accelerator: 'CmdOrCtrl+-' + }, + // {role: 'zoomOut'}, {type: 'separator'}, {role: 'togglefullscreen'} ] @@ -658,6 +703,11 @@ function onReady(): void { for(const w of electron.webContents.getAllWebContents()) w.send('rising-upgrade-complete'); }); + electron.ipcMain.on('update-zoom', (_e, zoomLevel: number) => { + // log.info('MENU ZOOM UPDATE', zoomLevel); + for(const w of electron.webContents.getAllWebContents()) w.send('update-zoom', zoomLevel); + }); + createWindow(); }