-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
127 lines (116 loc) · 3.58 KB
/
index.js
File metadata and controls
127 lines (116 loc) · 3.58 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
const { exec } = require("child_process");
_timeIsSet = false;
let appData = {
discord: {
imageName: "discord.exe",
start_time: { hh: 0, mm: 0, ss: 0 },
end_time: { hh: 0, mm: 0, ss: 0 },
limit: { hh: 0, mm: 0, ss: 10 },
running_time: 0,
},
};
const defaultTime = { hh: 0, mm: 0, ss: 0 };
const timeToSimple = (time) => time.hh + time.mm / 60 + (time.ss * 0.01) / 60;
const RunningTime = (start, end) => timeToSimple(end) - timeToSimple(start);
const limitChecker = (limit, runningTime) => timeToSimple(limit) <= runningTime;
const Running = (program) => {
// return isTrue;
};
const Close = (program) => {
exec(`taskkill /f /im ${program}`, (err, stdout, stderr) => {
if (err) {
console.error(err);
console.log("stderr: ", stderr);
return false;
} else {
// console.clear();
// console.log("stdout: ", stdout);
if (stdout.toString().includes("SUCCESS")) {
console.log("Closed");
} else {
console.log("Program already Closed");
}
}
});
};
// TODO: Comment out the code.
const Run = async () => {
if (!timeToSimple(appData["discord"].start_time)) {
// console.log(Running(appData["discord"].imageName));
exec(
`tasklist /fi "imagename eq ${appData["discord"].imageName}"`,
(err, stdout, stderr) => {
if (err) {
console.error(err);
console.log("stderr: ", stderr);
} else {
console.clear();
// console.log("stdout: ", stdout);
if (!stdout.toString().includes("No tasks")) {
console.log("Running without startTime");
const date = new Date(Date.now());
appData["discord"].start_time = {
hh: date.getHours(),
mm: date.getMinutes(),
ss: date.getSeconds(),
};
}
}
}
);
} else {
exec(
`tasklist /fi "imagename eq ${appData["discord"].imageName}"`,
(err, stdout, stderr) => {
if (err) {
console.error(err);
console.log("stderr: ", stderr);
isTrue = false;
} else {
console.clear();
// console.log("stdout: ", stdout);
if (!stdout.toString().includes("No tasks")) {
console.log("Running with startTime");
const date = new Date(Date.now());
const end = {
hh: date.getHours(),
mm: date.getMinutes(),
ss: date.getSeconds(),
};
let elapsedTime = RunningTime(appData["discord"].start_time, end);
if (
limitChecker(
appData["discord"].limit,
appData["discord"].running_time + elapsedTime
)
) {
appData["discord"].start_time = defaultTime;
appData["discord"].running_time = timeToSimple(
appData["discord"].limit
);
console.log("closing...");
exec("some.vbs");
Close(appData["discord"].imageName);
}
} else {
console.log("closing with startTime");
const date = new Date(Date.now());
const end = {
hh: date.getHours(),
mm: date.getMinutes(),
ss: date.getSeconds(),
};
appData["discord"].running_time = RunningTime(
appData["discord"].start_time,
end
);
appData["discord"].start_time = defaultTime;
}
}
}
);
}
// console.log(appData);
setTimeout(Run, 1000);
};
Run();