@walldock/agent 0.2.4 → 0.2.6
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/main.js +12 -0
- package/dist/startup.js +34 -21
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -100,6 +100,18 @@ async function main() {
|
|
|
100
100
|
}
|
|
101
101
|
console.log('Device unlinked. Starting pairing…\n');
|
|
102
102
|
}
|
|
103
|
+
// --register-startup: (re-)register the startup entry without going through pairing
|
|
104
|
+
if (args.includes('--register-startup')) {
|
|
105
|
+
try {
|
|
106
|
+
await (0, startup_1.registerStartup)();
|
|
107
|
+
console.log(`✓ Registered for startup (${(0, startup_1.startupDescription)()})`);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.error(`Failed to register startup: ${err}`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
103
115
|
// --status: print current link status
|
|
104
116
|
if (args.includes('--status')) {
|
|
105
117
|
const identity = await storage.getDeviceIdentity();
|
package/dist/startup.js
CHANGED
|
@@ -45,28 +45,32 @@ const node_util_1 = require("node:util");
|
|
|
45
45
|
const exec = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
46
46
|
// ─── Global bin resolution ────────────────────────────────────────────────────
|
|
47
47
|
async function resolveGlobalBin() {
|
|
48
|
-
let prefix;
|
|
49
|
-
try {
|
|
50
|
-
const npmBin = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
51
|
-
const { stdout } = await exec(npmBin, ['prefix', '-g']);
|
|
52
|
-
prefix = stdout.trim();
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
throw new Error('Could not determine npm global prefix.\n' +
|
|
56
|
-
'Make sure npm is installed and run: npm install -g @walldock/agent');
|
|
57
|
-
}
|
|
58
48
|
const binName = process.platform === 'win32' ? 'walldock-agent.cmd' : 'walldock-agent';
|
|
59
|
-
|
|
60
|
-
? path.join(prefix, binName)
|
|
61
|
-
: path.join(prefix, 'bin', binName);
|
|
49
|
+
// First try: derive path from npm global prefix
|
|
62
50
|
try {
|
|
51
|
+
const npmBin = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
52
|
+
const { stdout } = await exec(npmBin, ['prefix', '-g'], { encoding: 'utf8' });
|
|
53
|
+
const prefix = stdout.trim();
|
|
54
|
+
const binPath = process.platform === 'win32'
|
|
55
|
+
? path.join(prefix, binName)
|
|
56
|
+
: path.join(prefix, 'bin', binName);
|
|
63
57
|
await fs.access(binPath);
|
|
58
|
+
return binPath;
|
|
64
59
|
}
|
|
65
|
-
catch {
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
catch { /* fall through to PATH lookup */ }
|
|
61
|
+
// Second try: search PATH (handles nvm-windows, custom prefixes, etc.)
|
|
62
|
+
try {
|
|
63
|
+
const whereCmd = process.platform === 'win32' ? 'where' : 'which';
|
|
64
|
+
const { stdout } = await exec(whereCmd, [binName], { encoding: 'utf8' });
|
|
65
|
+
const found = stdout.trim().split('\n')[0]?.trim();
|
|
66
|
+
if (found) {
|
|
67
|
+
await fs.access(found);
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
68
70
|
}
|
|
69
|
-
|
|
71
|
+
catch { /* fall through */ }
|
|
72
|
+
throw new Error(`walldock-agent is not globally installed.\n` +
|
|
73
|
+
'Run: npm install -g @walldock/agent');
|
|
70
74
|
}
|
|
71
75
|
// ─── macOS ───────────────────────────────────────────────────────────────────
|
|
72
76
|
const LAUNCH_AGENTS_DIR = path.join(os.homedir(), 'Library', 'LaunchAgents');
|
|
@@ -110,13 +114,22 @@ async function unregisterMacOS() {
|
|
|
110
114
|
// ─── Windows ─────────────────────────────────────────────────────────────────
|
|
111
115
|
const REG_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
|
|
112
116
|
const REG_VALUE = 'WalldockAgent';
|
|
117
|
+
// VBScript launcher: runs walldock-agent.cmd silently (windowStyle=0 = hidden).
|
|
118
|
+
// Stored in %APPDATA%\walldock\ so it survives package updates — the .cmd
|
|
119
|
+
// wrapper always resolves to whichever version is currently installed.
|
|
120
|
+
const VBS_PATH = path.join(process.env['APPDATA'] ?? os.homedir(), 'walldock', 'launch-agent.vbs');
|
|
113
121
|
async function registerWindows() {
|
|
114
122
|
const binPath = await resolveGlobalBin();
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
await fs.mkdir(path.dirname(VBS_PATH), { recursive: true });
|
|
124
|
+
// windowStyle=0 = hidden, WaitOnReturn=False
|
|
125
|
+
await fs.writeFile(VBS_PATH, `CreateObject("WScript.Shell").Run """${binPath}"" --tray", 0, False\n`, 'utf8');
|
|
126
|
+
const wscript = path.join(process.env['SystemRoot'] ?? 'C:\\Windows', 'System32', 'wscript.exe');
|
|
127
|
+
const cmd = `"${wscript}" "${VBS_PATH}"`;
|
|
128
|
+
await exec('reg', ['add', REG_KEY, '/v', REG_VALUE, '/t', 'REG_SZ', '/d', cmd, '/f'], { windowsHide: true, encoding: 'utf8' });
|
|
117
129
|
}
|
|
118
130
|
async function unregisterWindows() {
|
|
119
|
-
await exec('reg', ['delete', REG_KEY, '/v', REG_VALUE, '/f']).catch(() => undefined);
|
|
131
|
+
await exec('reg', ['delete', REG_KEY, '/v', REG_VALUE, '/f'], { windowsHide: true, encoding: 'utf8' }).catch(() => undefined);
|
|
132
|
+
await fs.unlink(VBS_PATH).catch(() => undefined);
|
|
120
133
|
}
|
|
121
134
|
// ─── Linux ───────────────────────────────────────────────────────────────────
|
|
122
135
|
const SYSTEMD_USER_DIR = path.join(os.homedir(), '.config', 'systemd', 'user');
|
|
@@ -195,7 +208,7 @@ function startupDescription() {
|
|
|
195
208
|
if (process.platform === 'darwin')
|
|
196
209
|
return `LaunchAgent at ${PLIST_PATH}`;
|
|
197
210
|
if (process.platform === 'win32')
|
|
198
|
-
return `Registry
|
|
211
|
+
return `Registry Run key → wscript launcher at ${VBS_PATH}`;
|
|
199
212
|
return `systemd user service (or ${DESKTOP_PATH})`;
|
|
200
213
|
}
|
|
201
214
|
/** Returns the resolved global bin path, or null if not globally installed. */
|