From 89bf9b96f41b9926ec836573207dd4c261bd5b3b Mon Sep 17 00:00:00 2001 From: rooklift <16438795+rooklift@users.noreply.github.com> Date: Sun, 20 Jun 2021 15:27:50 +0100 Subject: [PATCH] pass the zoomfactor to the renderer and use it when saving width and height --- src/10_globals.js | 1 + src/95_hub.js | 5 +++-- src/main.js | 9 ++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/10_globals.js b/src/10_globals.js index a120b6ac..043aada5 100644 --- a/src/10_globals.js +++ b/src/10_globals.js @@ -42,6 +42,7 @@ const images = require("./modules/images"); const ipcRenderer = require("electron").ipcRenderer; const messages = require("./modules/messages"); const path = require("path"); +const querystring = require("querystring"); const readline = require("readline"); const stringify = require("./modules/stringify"); const util = require("util"); diff --git a/src/95_hub.js b/src/95_hub.js index 3572d6d8..ef766b0a 100644 --- a/src/95_hub.js +++ b/src/95_hub.js @@ -2215,8 +2215,9 @@ let hub_props = { }, save_window_size: function() { - config.width = window.innerWidth; - config.height = window.innerHeight; + let zoomfactor = parseFloat(querystring.parse(global.location.search)["zoomfactor"]); + config.width = Math.floor(window.innerWidth * zoomfactor); + config.height = Math.floor(window.innerHeight * zoomfactor); this.save_config(); }, diff --git a/src/main.js b/src/main.js index fc5438e9..b39c86b3 100644 --- a/src/main.js +++ b/src/main.js @@ -54,6 +54,8 @@ if (electron.app.isReady()) { function startup() { + let desired_zoomfactor = 1 / electron.screen.getPrimaryDisplay().scaleFactor; + win = new electron.BrowserWindow({ width: config.width, height: config.height, @@ -66,15 +68,15 @@ function startup() { contextIsolation: false, nodeIntegration: true, spellcheck: false, - zoomFactor: 1 / electron.screen.getPrimaryDisplay().scaleFactor // Unreliable, see https://github.com/electron/electron/issues/10572 + zoomFactor: desired_zoomfactor // Unreliable, see https://github.com/electron/electron/issues/10572 } }); win.once("ready-to-show", () => { try { - win.webContents.setZoomFactor(1 / electron.screen.getPrimaryDisplay().scaleFactor); // This seems to work, note issue 10572 above. + win.webContents.setZoomFactor(desired_zoomfactor); // This seems to work, note issue 10572 above. } catch (err) { - win.webContents.zoomFactor = 1 / electron.screen.getPrimaryDisplay().scaleFactor; // The method above "will be removed" in future. + win.webContents.zoomFactor = desired_zoomfactor; // The method above "will be removed" in future. } win.show(); win.focus(); @@ -219,6 +221,7 @@ function startup() { let query = {}; query.user_data_path = electron.app.getPath("userData"); + query.zoomfactor = desired_zoomfactor; win.loadFile( path.join(__dirname, "nibbler.html"),