Skip to content

Commit 61626b4

Browse files
committed
Modernize bootstrap project
1 parent 892c956 commit 61626b4

File tree

10 files changed

+683
-1513
lines changed

10 files changed

+683
-1513
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
.idea
44
build
55
dist
6-
*.log
6+
*.log
7+
**/*.js

bootstrap/index.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { exec } from "child_process";
33
import fs from "fs";
44
import os from "os";
55
import path from "path";
6-
import sudo from "sudo-prompt";
6+
import sudo from "@vscode/sudo-prompt";
77

88
const isWindows = os.platform() === "win32";
9+
const serviceName = "atest1";
910

1011
const sudoOptions = {
1112
name: "Aorus Laptop Fan Control",
@@ -16,7 +17,15 @@ const sudoOutputHandler: Parameters<(typeof sudo)["exec"]>[2] = (
1617
stdout,
1718
) => {
1819
if (error) {
19-
console.error(error);
20+
if (error.message.includes("already exists")) {
21+
console.log("Service already exists.");
22+
} else if (error.message.includes("grant permission")) {
23+
console.log("Please re-run and give permission to run.");
24+
} else if (error.message.includes("does not exist")) {
25+
console.log("Service doesn't exist.");
26+
} else {
27+
console.error(error);
28+
}
2029
return;
2130
}
2231

@@ -35,20 +44,22 @@ switch (process.argv[2]) {
3544
);
3645
break;
3746
case "install-as-sudo":
47+
console.log("Registering the service...");
3848
service.add(
39-
"alfc",
49+
serviceName,
4050
{
41-
args: ["run"],
51+
args: [process.argv[1], "run"],
4252
dependencies: isWindows ? ["Winmgmt"] : ["acpi_call"],
4353
},
4454
(error) => {
4555
if (error) {
4656
throw error;
4757
}
4858

59+
console.log("Starting service...");
4960
const serviceStartCommand = isWindows
50-
? "net start alfc"
51-
: "service alfc start";
61+
? "net start " + serviceName
62+
: `service ${serviceName} start`;
5263
exec(serviceStartCommand, async (error) => {
5364
if (error) {
5465
throw error;
@@ -59,7 +70,9 @@ switch (process.argv[2]) {
5970
}
6071

6172
console.log("Done.");
62-
require("react-dev-utils/openBrowser")("http://localhost:5522");
73+
import("open").then(({ default: open }) => {
74+
open("http://localhost:5522");
75+
});
6376
});
6477
},
6578
);
@@ -75,14 +88,16 @@ switch (process.argv[2]) {
7588
);
7689
break;
7790
case "uninstall-as-sudo": {
91+
console.log("Stopping service...");
7892
const serviceStopCommand = isWindows
79-
? "net stop alfc"
80-
: "service alfc stop";
93+
? "net stop " + serviceName
94+
: `service ${serviceName} stop`;
8195
exec(serviceStopCommand, () => {
8296
// exec would possibly error if the service is already stopped.
8397
// But we don't care about that and will simply attempt to remove the serivce.
8498

85-
service.remove("alfc", (error) => {
99+
console.log("Removing service...");
100+
service.remove(serviceName, (error) => {
86101
if (error) {
87102
throw error;
88103
}
@@ -93,6 +108,7 @@ switch (process.argv[2]) {
93108
break;
94109
}
95110
case "run":
111+
// Stop the service when the OS requests it.
96112
service.run(function () {
97113
service.stop(0);
98114
});
@@ -110,7 +126,11 @@ switch (process.argv[2]) {
110126

111127
process.chdir(__dirname);
112128
process.env.NODE_ENV = "production";
113-
require("./fancontrol");
129+
130+
new Promise((resolve) => {
131+
setTimeout(resolve, Number.MAX_SAFE_INTEGER);
132+
});
133+
// require("./fancontrol");
114134
break;
115135
default:
116136
console.error("If you can read this, either you or I did something wrong.");

bootstrap/package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@
44
"main": "index.ts",
55
"license": "MIT",
66
"scripts": {
7-
"build": "rimraf dist && ncc build index.ts"
7+
"build": "rimraf dist && ncc build index.ts",
8+
"start": "tsx ."
89
},
910
"dependencies": {
1011
"@neuralegion/os-service": "^1.2.6",
11-
"react-dev-utils": "12.0.1",
12-
"sudo-prompt": "9.2.1"
12+
"@vscode/sudo-prompt": "^9.3.1",
13+
"open": "^10.1.0"
1314
},
1415
"devDependencies": {
1516
"@vercel/ncc": "0.38.3",
16-
"rimraf": "6.0.1"
17+
"rimraf": "6.0.1",
18+
"tsx": "^4.19.2"
19+
},
20+
"pnpm": {
21+
"patchedDependencies": {
22+
"@vscode/sudo-prompt": "patches/@vscode__sudo-prompt.patch"
23+
}
1724
}
1825
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
diff --git a/CHANGELOG.md b/CHANGELOG.md
2+
deleted file mode 100644
3+
index 706616bdafd5d274bed13708b7367fbb309ab5ea..0000000000000000000000000000000000000000
4+
diff --git a/index.js b/index.js
5+
index 6b52ccf7e638c125319b8afec0708854ffec6bae..37f2b41edc260d44c4ee5c4234b012ec7c1dd9d6 100644
6+
--- a/index.js
7+
+++ b/index.js
8+
@@ -4,8 +4,7 @@ var Node = {
9+
fs: require('fs'),
10+
os: require('os'),
11+
path: require('path'),
12+
- process: process,
13+
- util: require('util')
14+
+ process: process
15+
};
16+
17+
function Attempt(instance, end) {
18+
@@ -32,20 +31,20 @@ function Exec() {
19+
throw new Error('Command should be a string.');
20+
}
21+
if (arguments.length === 2) {
22+
- if (Node.util.isObject(arguments[1])) {
23+
+ if (arguments[1] !== null && typeof arguments[1] === "object") {
24+
options = arguments[1];
25+
- } else if (Node.util.isFunction(arguments[1])) {
26+
+ } else if (typeof arguments[1] === "function") {
27+
end = arguments[1];
28+
} else {
29+
throw new Error('Expected options or callback.');
30+
}
31+
} else if (arguments.length === 3) {
32+
- if (Node.util.isObject(arguments[1])) {
33+
+ if (arguments[1] !== null && typeof arguments[1] === "object") {
34+
options = arguments[1];
35+
} else {
36+
throw new Error('Expected options to be an object.');
37+
}
38+
- if (Node.util.isFunction(arguments[2])) {
39+
+ if (typeof arguments[2] === "function") {
40+
end = arguments[2];
41+
} else {
42+
throw new Error('Expected callback to be a function.');

0 commit comments

Comments
 (0)