Skip to content

Commit

Permalink
pass the zoomfactor to the renderer and use it when saving width and …
Browse files Browse the repository at this point in the history
…height
  • Loading branch information
rooklift committed Jun 20, 2021
1 parent 001c0c4 commit 89bf9b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/10_globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 3 additions & 2 deletions src/95_hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},

Expand Down
9 changes: 6 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 89bf9b9

Please sign in to comment.