Skip to content

Commit ecbe95f

Browse files
committed
support starting projects on macos natively
1 parent fbba0b8 commit ecbe95f

File tree

1 file changed

+20
-2
lines changed
  • src/packages/server/projects/control

1 file changed

+20
-2
lines changed

src/packages/server/projects/control/util.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,29 @@ function pidFile(HOME: string): string {
5555
return join(dataPath(HOME), pidFilename);
5656
}
5757

58+
function parseDarwinTime(output:string) : number {
59+
// output = '{ sec = 1747866131, usec = 180679 } Wed May 21 15:22:11 2025';
60+
const match = output.match(/sec\s*=\s*(\d+)/);
61+
62+
if (match) {
63+
const sec = parseInt(match[1], 10);
64+
return sec * 1000;
65+
} else {
66+
throw new Error("Could not parse sysctl output");
67+
}
68+
}
69+
5870
let _bootTime = 0;
5971
export async function bootTime(): Promise<number> {
6072
if (!_bootTime) {
61-
const { stdout } = await executeCode({ command: "uptime", args: ["-s"] });
62-
_bootTime = new Date(stdout).valueOf();
73+
if (process.platform === "darwin") {
74+
// uptime isn't available on macos.
75+
const { stdout } = await executeCode({ command: "sysctl", args: ['-n', 'kern.boottime']});
76+
_bootTime = parseDarwinTime(stdout);
77+
} else {
78+
const { stdout } = await executeCode({ command: "uptime", args: ["-s"] });
79+
_bootTime = new Date(stdout).valueOf();
80+
}
6381
}
6482
return _bootTime;
6583
}

0 commit comments

Comments
 (0)