diff --git a/electron/gameWindow.js b/electron/gameWindow.js index f105340f8..4c3e3556d 100644 --- a/electron/gameWindow.js +++ b/electron/gameWindow.js @@ -37,6 +37,7 @@ async function createWindow(killall) { achievements.enableAchievementsInterval(window); utils.attachUnresponsiveAppHandler(window); + utils.setZoomFactor(window); try { await api.initialize(window); diff --git a/electron/menu.js b/electron/menu.js index b497c897b..e51fd29bf 100644 --- a/electron/menu.js +++ b/electron/menu.js @@ -119,6 +119,43 @@ function getMenu(window) { } ] }, + { + label: "Zoom", + submenu: [ + { + label: "Zoom In", + enabled: utils.getZoomFactor() <= 2, + accelerator: "CommandOrControl+numadd", + click: () => { + const currentZoom = utils.getZoomFactor(); + const newZoom = currentZoom + 0.1; + if (newZoom <= 2.0) { + utils.setZoomFactor(window, newZoom); + refreshMenu(window); + } else { + log.log('Max zoom out') + utils.writeToast(window, "Cannot zoom in anymore", "warning"); + } + }, + }, + { + label: "Zoom Out", + enabled: utils.getZoomFactor() >= 0.5, + accelerator: "CommandOrControl+numsub", + click: () => { + const currentZoom = utils.getZoomFactor(); + const newZoom = currentZoom - 0.1; + if (newZoom >= 0.5) { + utils.setZoomFactor(window, newZoom); + refreshMenu(window); + } else { + log.log('Max zoom in') + utils.writeToast(window, "Cannot zoom out anymore", "warning"); + } + }, + }, + ], + }, { label: "Debug", submenu: [ diff --git a/electron/utils.js b/electron/utils.js index 17385b20e..7c00f22aa 100644 --- a/electron/utils.js +++ b/electron/utils.js @@ -5,6 +5,9 @@ const log = require("electron-log"); const achievements = require("./achievements"); const api = require("./api-server"); +const Config = require("electron-config"); +const config = new Config(); + function reloadAndKill(window, killScripts) { const setStopProcessHandler = global.app_handlers.stopProcess const createWindowHandler = global.app_handlers.createWindow; @@ -109,8 +112,23 @@ function openExternal(url) { global.app_playerOpenedExternalLink = true; } +function getZoomFactor() { + const configZoom = config.get('zoom', 1); + return configZoom; +} + +function setZoomFactor(window, zoom = null) { + if (zoom === null) { + zoom = 1; + } else { + config.set('zoom', zoom); + } + window.webContents.setZoomFactor(zoom); +} + module.exports = { reloadAndKill, showErrorBox, exportSave, attachUnresponsiveAppHandler, detachUnresponsiveAppHandler, openExternal, writeTerminal, writeToast, + getZoomFactor, setZoomFactor, }