-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
206 lines (195 loc) · 6.64 KB
/
app.js
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
var path = require("path");
const pressAnyKey = require("press-any-key");
// "simple version management system" (patent pending)
var appName = "My Computer Can't Sleep!";
var version = "0.1";
var copyrightText =
"Made by Tan (weareblahs). Source code licensed via MIT License.";
// code start
console.log('"' + appName + '", version ' + version);
console.log(copyrightText);
console.log("\n");
console.log("Checking requests...");
require("child_process").exec(
"powercfg /requests",
function (error, stdout, stderr) {
if (stdout.length == 0) {
console.log(stderr);
process.exit();
} else {
console.log();
// remove blank arrays
array = [];
initialArray = stdout.split("\r\n");
for (i = 0; i < initialArray.length; i++) {
if (initialArray[i] !== "") {
array.push(initialArray[i]);
}
}
}
displayArrayIndex = array.indexOf("DISPLAY:");
displayArrayCount = 0;
systemArrayIndex = array.indexOf("SYSTEM:");
systemArrayCount = 0;
awaymodeArrayIndex = array.indexOf("AWAYMODE:");
awaymodeArrayCount = 0;
executionArrayIndex = array.indexOf("EXECUTION:");
executionArrayCount = 0;
perfBoostIndex = array.indexOf("PERFBOOST:");
perfBoostCount = 0;
activeLockScreenIndex = array.indexOf("ACTIVELOCKSCREEN:");
displayArray = array.slice(displayArrayIndex + 1, systemArrayIndex);
systemArray = array.slice(systemArrayIndex + 1, awaymodeArrayIndex);
awaymodeArray = array.slice(awaymodeArrayIndex + 1, executionArrayIndex);
executionArray = array.slice(executionArrayIndex + 1, perfBoostIndex);
perfBoostArray = array.slice(perfBoostIndex + 1, activeLockScreenIndex);
activeLockScreenIndex = array.slice(activeLockScreenIndex + 1);
taskkillQueue = [];
for (i = 0; i < executionArray.length; i++) {
if (executionArray[0] === "None.") {
} else {
if (i % 2 == 0) {
directory = executionArray[i].replace("[PROCESS] ", "");
executionArrayCount += 1;
taskkillQueue.push(path.basename(directory));
}
}
}
for (i = 0; i < displayArray.length; i++) {
if (displayArray[0] === "None.") {
} else {
if (i % 2 == 0) {
directory = displayArray[i].replace("[PROCESS] ", "");
displayArrayCount += 1;
taskkillQueue.push(path.basename(directory));
}
}
}
for (i = 0; i < systemArray.length; i++) {
if (systemArray[0] === "None.") {
} else {
if (i % 2 == 0) {
directory = systemArray[i].replace("[DRIVER] ", "");
systemArrayCount += 1;
}
}
}
for (i = 0; i < awaymodeArray.length; i++) {
if (awaymodeArray[0] === "None.") {
} else {
if (i % 2 == 0) {
directory = awaymodeArray[i].replace("[DRIVER] ", "");
awaymodeArrayCount += 1;
taskkillQueue.push(path.basename(directory));
}
}
}
for (i = 0; i < perfBoostArray.length; i++) {
if (perfBoostArray[0] === "None.") {
} else {
if (i % 2 == 0) {
directory = perfBoostArray[i].replace("[DRIVER] ", "");
perfBoostCount += 1;
}
}
}
// all those if/else conditions
// display-related
if (displayArrayCount == 0) {
console.log("There are no display-related issues.");
} else {
console.log(
"There are " +
displayArrayCount +
" display-related issues. Related executables has been added to the task killing queue."
);
}
// system-related
if (systemArrayCount == 0) {
console.log("There are no system-related issues.");
} else {
console.log(
"There are " +
systemArrayCount +
" system-related issues. If it is related to an application, it has been added to the task killing queue."
);
}
// away mode-related (not sure how it works)
if (awaymodeArrayCount == 0) {
console.log("There are no away mode-related issues.");
} else {
console.log(
"There are " +
awaymodeArrayCount +
" away mode-related issues. Related executables has been added to the task killing queue."
);
}
// execution-related
if (executionArrayCount == 0) {
console.log("There are no execution-related issues.");
} else {
console.log(
"There are " +
executionArrayCount +
" execution-related issues. Related executables has been added to the task killing queue."
);
}
// performance boost-related (not sure how it works)
if (perfBoostCount == 0) {
console.log("There are no performance boost-related issues.");
} else {
console.log(
"There are " + perfBoostCount + " performance boost-related issues."
);
}
//taskkill list
if (taskkillQueue.length > 0) {
console.log("\n");
console.log(
"Since there are issues related to executables, it can be done by forcifully stopping the task."
);
const prompts = require("prompts");
(async () => {
const response = await prompts({
type: "text",
name: "taskkillViewTask",
message:
"Please confirm with Y or N to view tasks to be forcifully stopped. Using other keys or 'N' will exit this application",
});
if (response.taskkillViewTask == "Y" || "y") {
console.log("These are the tasks that will be terminated:");
for (i = 0; i < taskkillQueue.length; i++) {
console.log(taskkillQueue[i]);
console.log("\n");
console.log(
"Before you proceed, please ensure that you've saved all files on the mentioned applications above."
);
const taskkillResponse = await prompts({
type: "text",
name: "taskkillResponse",
message:
"Please confirm with Y or N to stop the tasks. Using other keys or 'N' will exit this application",
});
if ((taskkillResponse.taskkillResponse = "Y" || "y")) {
console.log("Starting operation");
var cmd = require("node-cmd");
for (i = 0; i < taskkillQueue.length; i++) {
command = "taskkill /f /im " + taskkillQueue[i];
console.log(cmd.runSync(command).data);
}
}
if ((taskkillResponse.taskkillResponse = "N" || "n")) {
process.exit();
}
}
console.log("\n");
} else {
}
})();
} else {
pressAnyKey("\nPress any key to exit", {}).then(() => {
process.exit();
});
}
}
);