-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
120 lines (101 loc) · 3.18 KB
/
Copy pathmain.js
File metadata and controls
120 lines (101 loc) · 3.18 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//Import libraries
let { app, BrowserWindow, dialog, ipcMain, session } = require("electron");
let path = require("path");
let { performance } = require("perf_hooks");
//Metadata - Title
let latest_fps = 0;
let unitel_version = "2026.02";
let title_update_interval;
let win;
//Initialise functions
{
function createWindow () {
//Declare local instance variables
win = new BrowserWindow({
width: 3840,
height: 2160,
webPreferences: {
contextIsolation: false,
enableRemoteModule: false,
nodeIntegration: true,
webSecurity: false,
webviewTag: true
},
icon: path.join(__dirname, `gfx/logo.png`)
});
//Load file; open Inspect Element
win.loadFile("index.html").then(() => {
win.webContents.openDevTools();
win.setMenuBarVisibility(false);
});
//Listen for FPS updates from the renderer process
ipcMain.on("update-fps", (event, fps) => {
latest_fps = fps;
});
//Update the title every second with the latest data
title_update_interval = setInterval(function () {
let memory_usage = process.memoryUsage();
let heap_used_mb = (memory_usage.heapUsed/1024/1024).toFixed(2);
let rss_mb = (memory_usage.rss/1024/1024).toFixed(2);
let title_string = `Unitel ${unitel_version} - FPS: ${latest_fps} | RAM: RSS ${rss_mb}MB/Heap ${heap_used_mb}MB`;
win.setTitle(title_string);
}, 1000);
//Get the default session
try {
let default_session = session.defaultSession;
//Set up CORS settings for the default session
default_session.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Access-Control-Allow-Origin': ['*'],
'Access-Control-Allow-Methods': ['GET', 'POST', 'OPTIONS', 'PUT', 'PATCH', 'DELETE'],
'Access-Control-Allow-Headers': ['Content-Type', 'Authorization']
}
});
});
} catch (e) {
console.warn(e);
}
}
function handleOpenFolder (arg0_event, arg1_starting_path) {
//Convert from parameters
let event = arg0_event;
let starting_path = arg1_starting_path;
//Declare local instance variables
let actual_options = {
title: "Open Folder",
defaultPath: starting_path,
properties: ["openDirectory"]
};
//Show the dialog and wait for the user's choice
let result = dialog.showOpenDialogSync(actual_options);
//Result is an array of paths, or undefined if the user cancelled
if (result && result.length > 0)
//Return statement
return result[0]; //Return the first selected path
return undefined;
}
}
//App handling
{
//Launch app when ready
app.whenReady().then(() => {
//Create the window and instantiate it
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
app.on("ready", () => {
Menu.setApplicationMenu(null);
});
});
//Window lifecycle defaults
app.on("window-all-closed", () => {
if (process.platform !== "darwin") app.quit();
});
}
//Bindings handler
{
ipcMain.handle("dialog:openFolder", handleOpenFolder);
}