diff options
author | 0neGal <mail@0negal.com> | 2023-03-05 00:25:07 +0100 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2023-03-05 00:38:53 +0100 |
commit | 5d86a3daa5f762326055469b6bcd8346e0655056 (patch) | |
tree | 110fb1395fac1510dc3bf70f39f073df555445ff /src/modules/is_running.js | |
parent | 4536aad2c4f19d32569d84a7082e8636a2be6985 (diff) | |
download | Viper-5d86a3daa5f762326055469b6bcd8346e0655056.tar.gz Viper-5d86a3daa5f762326055469b6bcd8346e0655056.zip |
modularized many functions and got rid of utils.js
Notably, winLog() and winAlert() are now win.log() and win.alert()
inside modules/window.js.
updateViper(), updateNorthstar and handleNorthstarUpdating() are now
update.viper(), update.northstar() and update.northstar_autoupdate(),
inside modules/update.js
isGameRunning() and isOriginRunning() are now is_running.origin() and
is_running.game() inside modules/is_running.js, along with a
.titanfall() and .northstar() for more specificity. Not used anywhere
right now, but may in the future be used.
setpath() and gamepathExists() are now gamepath.set() and
gamepath.exists() inside modules/gamepath.js
killOrigin() are now kill.origin() inside modules/kill.js
setlang() is now just inlined into the only event where it's used.
Diffstat (limited to 'src/modules/is_running.js')
-rw-r--r-- | src/modules/is_running.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/modules/is_running.js b/src/modules/is_running.js new file mode 100644 index 0000000..cc91ded --- /dev/null +++ b/src/modules/is_running.js @@ -0,0 +1,66 @@ +const exec = require("child_process").exec; + +let is_running = {}; + +// a simple function that checks whether any of a given set of process +// names are running, you can either input a string or an Array of +// strings +async function check_processes(processes) { + if (typeof processes == "string") { + processes = [processes]; + } + + return new Promise(resolve => { + if (! Array.isArray(processes)) { + reject(false); + } + + // While we could use a Node module to do this instead, I + // decided not to do so. As this achieves exactly the same + // thing. And it's not much more clunky. + let cmd = (() => { + switch (process.platform) { + case "linux": return "ps -A"; + case "win32": return "tasklist"; + } + })(); + + exec(cmd, (err, stdout) => { + for (let i = 0; i < processes.length; i++) { + if (stdout.includes(processes[i])) { + resolve(true); + break + } + + if (i == processes.length - 1) {resolve(false)} + } + }); + }); +} + +is_running.game = async () => { + return await check_processes([ + "NorthstarLauncher.exe", + "Titanfall2.exe", "Titanfall2-unpacked.exe" + ]) +} + +is_running.origin = async () => { + return await check_processes([ + "Origin.exe", + ]) +} + +is_running.titanfall = async () => { + return await check_processes([ + "Titanfall2.exe", "Titanfall2-unpacked.exe" + ]) +} + +is_running.northstar = async () => { + return await check_processes([ + "NorthstarLauncher.exe", + ]) +} + +module.exports = is_running; |