-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
135 lines (114 loc) · 4.08 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const { app, BrowserWindow, nativeImage } = require('electron');
const fs = require("fs");
const path = require("path");
// now works with meshcentral and anvil.works
const URL = "ENTER_YOUR_MESHCENTRAL_SERVER_URL_HERE";
const WINDOW_TITLE = "Meshcentral Desktop App"
const windowStatePath = path.join(app.getPath("userData"), "window-state.json");
const DEBUG = false;
let mainWindowState;
function createWindow() {
let maximized = false;
try {
mainWindowState = JSON.parse(fs.readFileSync(windowStatePath, "utf-8"));
maximized = mainWindowState.maximized;
} catch (e) {
mainWindowState = {
width: 800,
height: 600,
maximized: false
};
}
const win = new BrowserWindow({
width: mainWindowState.width,
height: mainWindowState.height,
webPreferences: {
nodeIntegration: false,
contextIsolation: true, // Consider enabling this and using preload scripts for security.
enableRemoteModule: false,
},
title: WINDOW_TITLE,
icon: nativeImage.createFromPath(path.join(__dirname, '/icons/png/128x128.png')) // Set the window icon here
});
if (DEBUG == false) {
win.setMenu(null);
}
win.loadURL(URL);
if (maximized) {
win.maximize();
}
win.on("close", () => {
let bounds = win.getBounds();
// If the window is maximized, we want to save that it's maximized, but not update the bounds
if (win.isMaximized()) {
mainWindowState.maximized = true;
} else {
// Only update the window size if the window is not maximized
mainWindowState = {
width: bounds.width,
height: bounds.height,
maximized: false
};
}
fs.writeFileSync(windowStatePath, JSON.stringify(mainWindowState));
});
win.on('unmaximize', () => {
win.setSize(mainWindowState.width, mainWindowState.height);
});
win.webContents.on('did-finish-load', () => {
win.webContents.insertCSS(customCSS);
});
win.webContents.setWindowOpenHandler(({ url }) => {
// Instead of denying, we create a new modal window
let modalWindow = new BrowserWindow({
//parent: win,
modal: false,
show: false,
width: 400,
height: 300,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
},
//title: "noVNC: "+win.getTitle(),
icon: nativeImage.createFromPath(path.join(__dirname, '/icons/png/128x128.png')) // Set the window icon here
});
modalWindow.setMenu(null);
modalWindow.loadURL(url); // Load the URL that was supposed to open in a new window
modalWindow.once('ready-to-show', () => {
modalWindow.show();
});
modalWindow.webContents.on('did-finish-load', () => {
modalWindow.setTitle("noVNC: "+win.getTitle());
modalWindow.webContents.insertCSS(customCSS);
});
// We handle the window open request by saying we're going to show the window ourselves
return { action: 'deny' };
});
}
app.whenReady().then(createWindow);
// Custom CSS to style the vertical scrollbar and hide the horizontal scrollbar
const customCSS = `
/* Hide horizontal scrollbar */
body {
overflow-x: hidden;
}
/* Style the vertical scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
border-radius: 10px; /* Round the corners of the scrollbar track */
}
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px; /* Round the corners of the scrollbar thumb */
}
::-webkit-scrollbar-thumb:hover {
background: #555;
}
#footer {
overflow: hidden !important;
}
`;