mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-17 13:13:49 +01:00
Add zoom to electron app
This commit is contained in:
parent
faf8389bef
commit
0b88922ab7
@ -37,6 +37,7 @@ async function createWindow(killall) {
|
||||
|
||||
achievements.enableAchievementsInterval(window);
|
||||
utils.attachUnresponsiveAppHandler(window);
|
||||
utils.setZoomFactor(window);
|
||||
|
||||
try {
|
||||
await api.initialize(window);
|
||||
|
@ -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: [
|
||||
|
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user