File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
src/packages/server/projects/control Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -55,11 +55,29 @@ function pidFile(HOME: string): string {
55
55
return join ( dataPath ( HOME ) , pidFilename ) ;
56
56
}
57
57
58
+ function parseDarwinTime ( output :string ) : number {
59
+ // output = '{ sec = 1747866131, usec = 180679 } Wed May 21 15:22:11 2025';
60
+ const match = output . match ( / s e c \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
+
58
70
let _bootTime = 0 ;
59
71
export async function bootTime ( ) : Promise < number > {
60
72
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
+ }
63
81
}
64
82
return _bootTime ;
65
83
}
You can’t perform that action at this time.
0 commit comments