aboutsummaryrefslogtreecommitdiff
path: root/src/modules/is_running.js
blob: b9fbde1fc1c41c1cb1b9c13ad91347fac11e0cbf (plain)
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
const win = require("../win");
const exec = require("child_process").exec;

let is_running = {};

setInterval(async () => {
	win().send("is-running", await is_running.game());
}, 1000)

// 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 = () => {
	return check_processes([
		"NorthstarLauncher.exe",
		"Titanfall2.exe", "Titanfall2-unpacked.exe"
	])
}

is_running.origin = () => {
	return check_processes([
		"Origin.exe",
		"EADesktop.exe"
	])
}

is_running.titanfall = () => {
	return check_processes([
		"Titanfall2.exe", "Titanfall2-unpacked.exe"
	])
}

is_running.northstar = () => {
	return check_processes([
		"NorthstarLauncher.exe",
	])
}

module.exports = is_running;