mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 09:33:49 +01:00
Merge pull request #2346 from MartinFournier/feature/electron-zoom
Add zoom to electron app
This commit is contained in:
commit
ae779574b0
@ -37,6 +37,7 @@ async function createWindow(killall) {
|
|||||||
|
|
||||||
achievements.enableAchievementsInterval(window);
|
achievements.enableAchievementsInterval(window);
|
||||||
utils.attachUnresponsiveAppHandler(window);
|
utils.attachUnresponsiveAppHandler(window);
|
||||||
|
utils.setZoomFactor(window);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.initialize(window);
|
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",
|
label: "Debug",
|
||||||
submenu: [
|
submenu: [
|
||||||
|
@ -5,6 +5,9 @@ const log = require("electron-log");
|
|||||||
const achievements = require("./achievements");
|
const achievements = require("./achievements");
|
||||||
const api = require("./api-server");
|
const api = require("./api-server");
|
||||||
|
|
||||||
|
const Config = require("electron-config");
|
||||||
|
const config = new Config();
|
||||||
|
|
||||||
function reloadAndKill(window, killScripts) {
|
function reloadAndKill(window, killScripts) {
|
||||||
const setStopProcessHandler = global.app_handlers.stopProcess
|
const setStopProcessHandler = global.app_handlers.stopProcess
|
||||||
const createWindowHandler = global.app_handlers.createWindow;
|
const createWindowHandler = global.app_handlers.createWindow;
|
||||||
@ -109,8 +112,23 @@ function openExternal(url) {
|
|||||||
global.app_playerOpenedExternalLink = true;
|
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 = {
|
module.exports = {
|
||||||
reloadAndKill, showErrorBox, exportSave,
|
reloadAndKill, showErrorBox, exportSave,
|
||||||
attachUnresponsiveAppHandler, detachUnresponsiveAppHandler,
|
attachUnresponsiveAppHandler, detachUnresponsiveAppHandler,
|
||||||
openExternal, writeTerminal, writeToast,
|
openExternal, writeTerminal, writeToast,
|
||||||
|
getZoomFactor, setZoomFactor,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user