Skip to content

Commit 8c23092

Browse files
committed
Stop using open
1 parent f1f43ec commit 8c23092

File tree

11 files changed

+179
-94
lines changed

11 files changed

+179
-94
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ to port 5522 and killing it.
9898
Contributions welcome, as always. 🙂
9999

100100
- To support more recent node versions, the `nan` dependency in `os-version` would have to be upgraded.
101+
- It would be nice to be able to move to ESM at some point. Unfortunately, dependencies with native aspects don't play well. At least not out of the box and it's not worthwhile to invest a lot of time into workarounds.
101102
- Refactor styles so there aren't as many inline ones.
102103
- Make ramping up/down times configurable.
103104
- Prettier status UI.

alfc.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"pl1": 37,
66
"pl2": 106,
77
"doFixedSpeed": false,
8-
"fixedPercentage": 70
8+
"fixedPercentage": 50
99
}

bootstrap/esbuild.ts renamed to bootstrap/esbuild.mts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import esbuild, { Plugin } from "esbuild";
22
import { getAbi } from "node-abi";
33
import fs from "fs/promises";
44
import path from "path";
5-
import { glob } from "glob";
5+
import fg from "fast-glob";
66

77
interface PrebuildifyOptions {
88
// CSV list of prebuildify targets. Combination of os.platform() and os.arch(), e.g. `win32-x64`.
@@ -34,7 +34,7 @@ const prebuildifyPlugin = ({
3434
const outPrebuilds = path.join(outdir, "prebuilds");
3535
await fs.mkdir(outPrebuilds, { recursive: true });
3636

37-
const prebuilds = await glob("node_modules/**/prebuilds/**/*.node");
37+
const prebuilds = await fg(["node_modules/**/prebuilds/**/*.node"]);
3838

3939
// Get target ABI version if specified
4040
const targets =
@@ -55,7 +55,8 @@ const prebuildifyPlugin = ({
5555
const parsedPlatforms = prebuildifyTargets?.split(",");
5656
for (const prebuild of prebuilds) {
5757
const filename = path.basename(prebuild);
58-
const platform = path.dirname(prebuild).split(path.sep).pop();
58+
// Seems like unlike glob, fast-glob always uses / instead of a OS specific path separator.
59+
const platform = path.dirname(prebuild).split("/").pop();
5960

6061
if (
6162
platform &&
@@ -85,7 +86,10 @@ await esbuild.build({
8586
bundle: true,
8687
platform: "node",
8788
target: "node22.11.0",
89+
format: "cjs",
8890
outfile: "dist/index.js",
91+
packages: "bundle",
92+
external: ["./fancontrol"],
8993
plugins: [
9094
prebuildifyPlugin({
9195
prebuildifyTargets: "win32-x64",

bootstrap/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ const sudoOptions = {
1212
name: "Aorus Laptop Fan Control",
1313
};
1414

15+
const openBrowser = () => {
16+
const start = process.platform === "win32" ? "start" : "open";
17+
require("child_process").exec(`${start} http://localhost:5522`);
18+
};
19+
1520
const sudoOutputHandler: Parameters<(typeof sudo)["exec"]>[2] = (
1621
error,
1722
stdout,
@@ -70,9 +75,7 @@ switch (process.argv[2]) {
7075
}
7176

7277
console.log("Done.");
73-
import("open").then(({ default: open }) => {
74-
open("http://localhost:5522");
75-
});
78+
openBrowser();
7679
});
7780
},
7881
);
@@ -102,7 +105,7 @@ switch (process.argv[2]) {
102105
throw error;
103106
}
104107

105-
console.log("Done.");
108+
console.log("You can delete alfc now.");
106109
});
107110
});
108111
break;
@@ -116,9 +119,13 @@ switch (process.argv[2]) {
116119
// Need to redirect all output to a log file on Windows.
117120
// On Linux, it'll go to the systemd logs.
118121
if (isWindows) {
119-
const access = fs.createWriteStream(path.join(__dirname, "service.log"));
122+
const logStream = fs.createWriteStream(
123+
path.join(__dirname, "service.log"),
124+
{ flags: "a" },
125+
);
120126
// @ts-expect-error Undefined/null type mismatch: Type 'Error | null | undefined' is not assignable to type 'Error | undefined'.
121-
process.stdout.write = process.stderr.write = access.write.bind(access);
127+
process.stdout.write = process.stderr.write =
128+
logStream.write.bind(logStream);
122129
process.on("uncaughtException", function (err) {
123130
console.error(err && err.stack ? err.stack : err);
124131
});
@@ -127,10 +134,7 @@ switch (process.argv[2]) {
127134
process.chdir(__dirname);
128135
process.env.NODE_ENV = "production";
129136

130-
new Promise((resolve) => {
131-
setTimeout(resolve, Number.MAX_SAFE_INTEGER);
132-
});
133-
// require("./fancontrol");
137+
require("./fancontrol");
134138
break;
135139
default:
136140
console.error("If you can read this, either you or I did something wrong.");

bootstrap/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@
33
"version": "1.0.0",
44
"main": "index.ts",
55
"license": "MIT",
6-
"type": "module",
76
"scripts": {
8-
"build": "rimraf dist && pnpm tsx esbuild.ts",
7+
"build": "rimraf dist && pnpm tsx esbuild.mts",
98
"build:esfirsttry": "esbuild index.ts --bundle --platform=node --target=node22 --external:*.node --outfile=dist/index.cjs",
109
"build:old": "rimraf dist && ncc build index.ts",
1110
"start": "tsx ."
1211
},
1312
"dependencies": {
1413
"@neuralegion/os-service": "^1.2.6",
15-
"@vscode/sudo-prompt": "^9.3.1",
16-
"open": "^10.1.0"
14+
"@vscode/sudo-prompt": "^9.3.1"
1715
},
1816
"devDependencies": {
1917
"@types/node-abi": "^3.0.3",
2018
"@vercel/ncc": "0.38.3",
2119
"esbuild": "^0.24.2",
22-
"glob": "^11.0.1",
20+
"fast-glob": "^3.3.3",
2321
"node-abi": "^3.73.0",
2422
"rimraf": "6.0.1",
2523
"tsx": "^4.19.2"

0 commit comments

Comments
 (0)