This repository was archived by the owner on Nov 25, 2025. It is now read-only.
forked from JC-Orozco/BlocksIDE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
116 lines (97 loc) · 3.12 KB
/
Copy pathmain.js
File metadata and controls
116 lines (97 loc) · 3.12 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
var { app, BrowserWindow, dialog, ipcMain, session } = require("electron");
var path = require("path");
var { performance } = require("perf_hooks");
var latest_fps = 0;
var scriptly_version = "0.71b";
var title_update_interval;
var win;
//Initialise functions
{
var createWindow = () => {
//Declare local instance variables
win = new BrowserWindow({
width: 3840,
height: 2160,
webPreferences: {
contextIsolation: false,
enableRemoteModule: false,
nodeIntegration: true,
webSecurity: false
},
icon: path.join(__dirname, `public/favicon.png`)
});
//Load file; open Inspect Element
win.loadFile("index.html");
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 () {
var memory_usage = process.memoryUsage();
var heap_used_mb = (memory_usage.heapUsed/1024/1024).toFixed(2);
var rss_mb = (memory_usage.rss/1024/1024).toFixed(2);
var title_string = `Scriptly ${scriptly_version} - FPS: ${latest_fps} | RAM: RSS ${rss_mb}MB/Heap ${heap_used_mb}MB`;
win.setTitle(title_string);
}, 1000);
//Get the default session
try {
var 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
var event = arg0_event;
var starting_path = arg1_starting_path;
//Declare local instance variables
var actual_options = {
title: "Open Folder",
defaultPath: starting_path,
properties: ["openDirectory"]
};
//Show the dialog and wait for the user's choice
var 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);
}