This repository was archived by the owner on Feb 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
105 lines (92 loc) · 2.55 KB
/
main.js
File metadata and controls
105 lines (92 loc) · 2.55 KB
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
const { app, BrowserWindow, globalShortcut, ipcMain } = require("electron");
const path = require("path");
const handleDownloadFromInternet = require("./filemanagement/downloadFromInternet");
var setupDisks = require("./modules/disks");
var setupScripts = require("./modules/scripts");
var runningAsDev = process.argv[2] == "dev";
app.commandLine.appendSwitch("disable-http-cache");
var win;
function createWindow() {
win = new BrowserWindow({
fullscreen: !runningAsDev,
webPreferences: {
webviewTag: true,
preload: path.join(__dirname, "preload.js"),
icon: path.join(__dirname, "logo.png"),
contextIsolation: false,
sandbox: false,
webSecurity: false,
},
});
// Load
win.loadURL("http://localhost:10000");
win.setMenu(null);
// Error handling
win.webContents.on(
"did-fail-load",
(event, errorCode, errorDescription, validatedURL, isMainFrame) => {
if (isMainFrame) {
win.loadFile("errors/noserver.html");
}
},
);
// Dev menu
globalShortcut.register("F12", () => {
win.webContents.toggleDevTools();
});
// Set custom download dialog
win.webContents.session.on("will-download", async (event, item) => {
await handleDownloadFromInternet(win, event, item);
});
// API
ipcMain.on("set-zoom", (_, content) => {
win.webContents.setZoomFactor(content);
});
ipcMain.on("closeapp", () => {
app.quit();
});
ipcMain.on("isDev", (event) => {
event.reply("isDevResponse", runningAsDev);
});
// Set preload to all webviews
const PRELOAD_WEBVIEW_PATH = path.join(__dirname, "preload-webview.js");
setInterval(() => {
try {
win.webContents.executeJavaScript(`
var webviews = document.querySelectorAll('webview');
webviews.forEach(webview => {
webview.setAttribute('preload', 'file://${PRELOAD_WEBVIEW_PATH}');
});
`);
} catch {}
}, 1000);
// Disks
if (!runningAsDev) {
setupDisks(win.webContents);
setupScripts(win.webContents);
}
win.show();
}
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
// Catch all new window dialogs
app.on("web-contents-created", (_, wc) => {
wc.setWindowOpenHandler((details) => {
const url = details.url;
win.webContents
.executeJavaScript(`windows.open('brow', '${url}')`)
.catch(() => {});
return { action: "deny" };
});
});