Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
191 lines (161 loc) · 5.97 KB
/
Copy pathindex.js
File metadata and controls
191 lines (161 loc) · 5.97 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');
const electron = require('electron');
const csvParser = require('csv-parse/sync');
// Make our config DB work
if (!fs.existsSync("./databases")) fs.mkdirSync("./databases");
const Database = require('sync-json-database');
const configuration = new Database("./databases/a90-config.json", {
indented: true
});
const devMode = !electron.app.isPackaged;
/** @type {electron.BrowserWindow} */
let globalWindow = null;
const createWindow = () => {
const win = new electron.BrowserWindow({
title: "A-90",
icon: "assets/icon.png",
width: 1280,
height: 720,
frame: false,
center: true,
movable: false,
resizable: false,
transparent: true,
webPreferences: {
devTools: devMode,
sandbox: false,
spellcheck: false,
preload: path.join(__dirname, 'preload.js')
}
});
win.loadFile('index.html');
win.maximize();
if (!devMode) {
win.removeMenu();
}
globalWindow = win;
return win;
};
const quitApplication = () => {
electron.app.quit();
};
const createSystemTray = () => {
const iconPath = path.join(__dirname, './assets/icon.png');
const icon = electron.nativeImage.createFromPath(iconPath);
const tray = new electron.Tray(icon);
tray.setToolTip('A-90');
tray.setTitle('A-90');
const contextMenu = electron.Menu.buildFromTemplate([
{
label: 'Close', type: 'normal', click: () => {
quitApplication();
}
},
]);
tray.setContextMenu(contextMenu);
electron.app.on('before-quit', () => {
tray.destroy();
});
};
electron.app.whenReady().then(() => {
globalWindow = createWindow();
createSystemTray();
electron.app.setName('A-90');
electron.app.setAppUserModelId('com.jeremygamer13.A90');
});
electron.app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
quitApplication();
}
});
electron.ipcMain.handle("quitApp", () => {
quitApplication();
});
electron.ipcMain.handle("started", () => {
globalWindow.setAlwaysOnTop(true);
globalWindow.setIgnoreMouseEvents(true);
});
electron.ipcMain.handle("fullscreen", () => {
globalWindow.setFullScreen(true);
});
// TODO: Allow settings to save, not just excused processes
const getProcessList = () => {
const buffer = childProcess.execSync("wmic process get ProcessID,ExecutablePath /format:csv");
const formalizedString = buffer.toString().trim().replace(/\r/g, "");
const parsed = csvParser.parse(formalizedString, { columns: true });
const processList = parsed
.filter(program => program.ExecutablePath.trim().length > 0)
.map(program => ({
path: program.ExecutablePath.trim(),
pid: Number(program.ProcessId)
}));
return processList;
};
electron.ipcMain.handle("getActiveProcesses", () => {
const processes = getProcessList();
return processes;
});
electron.ipcMain.handle("getSavedProcesses", () => {
const processes = configuration.get("processList");
if (!processes) return [];
if (!Array.isArray(processes)) return [];
const filtered = processes.filter(execPath => execPath && typeof execPath === "string");
return filtered;
});
electron.ipcMain.handle("updateSavedProcesses", (_, changedProcesses) => {
const processes = configuration.get("processList") || [];
for (const execPath in changedProcesses) {
const isExcused = String(changedProcesses[execPath]) === "true";
if (isExcused && processes.includes(execPath)) continue;
if (!isExcused && !processes.includes(execPath)) continue;
if (isExcused) {
processes.push(execPath);
} else {
const idx = processes.indexOf(execPath);
processes.splice(idx, 1);
}
}
configuration.set("processList", processes);
});
electron.ipcMain.handle("killProgram", (_, settings) => {
const processes = getProcessList();
const excusedProcesses = configuration.get("processList") || [];
if (settings.appCloseWindows !== true) return;
const killable = processes.filter(process => {
if (excusedProcesses.includes(process.path)) return false;
// TODO: alot of these checks are dumb, we should probably just use real paths for most, might just be weird since windows can be on any letter drive
const commandCheck = process.path.toLowerCase();
if (settings.appCloseAllowSuicide !== true) {
if (commandCheck.endsWith("electron.exe")) return false;
if (commandCheck.endsWith("a90.exe")) return false;
if (commandCheck.endsWith("node.exe")) return false;
}
if (settings.appCloseAllowSystem32 !== true) {
if (commandCheck.includes("system32")) return false;
}
if (settings.appCloseAllowWindows !== true) {
if (commandCheck.includes("windowsapps")) return false;
if (commandCheck.substring(0, 12).includes("windows")) return false;
}
if (settings.appCloseAllowSystemApps !== true) {
if (commandCheck.includes("systemapps")) return false;
}
if (settings.appCloseAllowMicrosoft !== true) {
if (commandCheck.includes("microsoft")) return false;
}
if (settings.appCloseAvoidRecording) {
if (commandCheck.includes("obs-studio")) return false;
}
if (settings.appCloseTargetRoblox) {
if (!commandCheck.includes("roblox")) return false;
}
return true;
});
if (killable.length <= 0) return;
const randomProcess = killable[Math.round(Math.random() * (killable.length - 1))];
const pid = randomProcess.pid; // getProcessList ensures this is a number
console.log("Killing process with PID", pid);
childProcess.execSync(`taskkill /PID ${pid}${settings.appCloseForce ? " /F" : ""}`);
});