Skip to content

Commit a37c07a

Browse files
committed
add zoom function in electron
1 parent 85520ff commit a37c07a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function isElectron() {
2+
// Check for the presence of Electron-specific objects
3+
return typeof window !== 'undefined' && window.process && window.process.type === 'renderer';
4+
}
5+
6+
// Function to handle zoom in/out
7+
function handleZoom(event) {
8+
if (event.ctrlKey) {
9+
if (event.key === '+' || event.key === '=') {
10+
// Zoom in
11+
const { webFrame } = require('electron');
12+
webFrame.setZoomLevel(webFrame.getZoomLevel() + 1);
13+
event.preventDefault();
14+
} else if (event.key === '-' || event.key === '_') {
15+
// Zoom out
16+
const { webFrame } = require('electron');
17+
webFrame.setZoomLevel(webFrame.getZoomLevel() - 1);
18+
event.preventDefault();
19+
}
20+
}
21+
}
22+
23+
// Function to open the developer console
24+
function openDevTools(event) {
25+
if (event.ctrlKey && event.shiftKey && event.key === 'K') {
26+
console.log("Opening developer tools");
27+
const { getCurrentWindow } = require('@electron/remote');
28+
const currentWindow = getCurrentWindow();
29+
currentWindow.webContents.toggleDevTools();
30+
event.preventDefault();
31+
}
32+
}
33+
34+
// Attach event listeners only if running in Electron
35+
if (isElectron()) {
36+
document.addEventListener('keydown', handleZoom);
37+
//document.addEventListener('keydown', openDevTools);
38+
}

NetworkDynamicsInspector/src/NetworkDynamicsInspector.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const NODE_FENCE = Asset(joinpath(ASSETS, "node_fence.js"))
4141
const NODE_UNFENCE = Asset(joinpath(ASSETS, "node_unfence.js"))
4242
const TOMSELECT_ESS = ES6Module(joinpath(ASSETS, "tomselect.js"))
4343
const TOMSELECT_CSS = Asset(joinpath(ASSETS, "tomselect.css"))
44+
const ELECTRON_JS = Asset(joinpath(ASSETS, "electron.js"))
4445

4546
include("widgets.jl")
4647
include("graphplot.jl")
@@ -227,6 +228,7 @@ function get_webapp()
227228

228229
DOM.div(
229230
APP_CSS,
231+
ELECTRON_JS,
230232
DOM.div(
231233
graphplot_card(app, session),
232234
gpstate_control_card(app, :vertex),

0 commit comments

Comments
 (0)