@ctrl-spc/cli 1.1.6 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/launchd.js +18 -7
- package/package.json +1 -1
package/dist/launchd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
4
|
+
import { basename, join } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { ensureStateDir, getStatePaths } from './session.js';
|
|
7
7
|
export const PLIST_LABEL = 'com.ctrl-spc.daemon';
|
|
@@ -32,6 +32,7 @@ export function buildDaemonPath(home = homedir(), envPath = process.env.PATH ??
|
|
|
32
32
|
}
|
|
33
33
|
export function buildPlist(nodePath, scriptPath, home = homedir(), daemonPath = buildDaemonPath(home)) {
|
|
34
34
|
const { daemonLogPath } = getStatePaths(home);
|
|
35
|
+
const user = process.env.USER || process.env.LOGNAME || basename(home);
|
|
35
36
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
36
37
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
37
38
|
<plist version="1.0">
|
|
@@ -50,8 +51,14 @@ export function buildPlist(nodePath, scriptPath, home = homedir(), daemonPath =
|
|
|
50
51
|
<true/>
|
|
51
52
|
<key>EnvironmentVariables</key>
|
|
52
53
|
<dict>
|
|
54
|
+
<key>HOME</key>
|
|
55
|
+
<string>${escapeXml(home)}</string>
|
|
56
|
+
<key>LOGNAME</key>
|
|
57
|
+
<string>${escapeXml(user)}</string>
|
|
53
58
|
<key>PATH</key>
|
|
54
59
|
<string>${escapeXml(daemonPath)}</string>
|
|
60
|
+
<key>USER</key>
|
|
61
|
+
<string>${escapeXml(user)}</string>
|
|
55
62
|
</dict>
|
|
56
63
|
<key>StandardErrorPath</key>
|
|
57
64
|
<string>${escapeXml(daemonLogPath)}</string>
|
|
@@ -60,17 +67,21 @@ export function buildPlist(nodePath, scriptPath, home = homedir(), daemonPath =
|
|
|
60
67
|
</dict>
|
|
61
68
|
</plist>`;
|
|
62
69
|
}
|
|
63
|
-
|
|
64
|
-
const home = homedir();
|
|
70
|
+
function writeDaemonPlist(home = homedir()) {
|
|
65
71
|
const launchAgentsDir = join(home, 'Library', 'LaunchAgents');
|
|
66
72
|
const plistPath = getPlistPath(home);
|
|
73
|
+
ensureStateDir(home);
|
|
74
|
+
mkdirSync(launchAgentsDir, { recursive: true });
|
|
75
|
+
writeFileSync(plistPath, buildPlist(process.execPath, resolveBinPath(), home), 'utf8');
|
|
76
|
+
return plistPath;
|
|
77
|
+
}
|
|
78
|
+
export async function installDaemon() {
|
|
79
|
+
const home = homedir();
|
|
67
80
|
const uid = process.getuid?.();
|
|
68
81
|
if (uid === undefined) {
|
|
69
82
|
throw new Error(INSTALL_FAILED_MESSAGE);
|
|
70
83
|
}
|
|
71
|
-
|
|
72
|
-
mkdirSync(launchAgentsDir, { recursive: true });
|
|
73
|
-
writeFileSync(plistPath, buildPlist(process.execPath, resolveBinPath(), home), 'utf8');
|
|
84
|
+
const plistPath = writeDaemonPlist(home);
|
|
74
85
|
const domain = `gui/${uid}`;
|
|
75
86
|
try {
|
|
76
87
|
try {
|
|
@@ -113,7 +124,7 @@ export async function restartDaemon(home = homedir(), exec = defaultExec) {
|
|
|
113
124
|
const uid = process.getuid?.();
|
|
114
125
|
if (uid === undefined)
|
|
115
126
|
throw new Error(RESTART_FAILED_MESSAGE);
|
|
116
|
-
const plistPath =
|
|
127
|
+
const plistPath = writeDaemonPlist(home);
|
|
117
128
|
try {
|
|
118
129
|
exec('launchctl', kickstartArgs(uid));
|
|
119
130
|
}
|