@walldock/agent 0.2.5 → 0.2.7

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 CHANGED
@@ -102,11 +102,6 @@ async function main() {
102
102
  }
103
103
  // --register-startup: (re-)register the startup entry without going through pairing
104
104
  if (args.includes('--register-startup')) {
105
- const globalBin = await (0, startup_1.getGlobalBin)();
106
- if (!globalBin) {
107
- console.error('walldock-agent is not globally installed. Run: npm install -g @walldock/agent');
108
- process.exit(1);
109
- }
110
105
  try {
111
106
  await (0, startup_1.registerStartup)();
112
107
  console.log(`✓ Registered for startup (${(0, startup_1.startupDescription)()})`);
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
- const binPath = process.platform === 'win32'
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
- throw new Error(`walldock-agent is not globally installed at ${binPath}.\n` +
67
- 'Run: npm install -g @walldock/agent');
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
- return binPath;
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');
@@ -108,24 +112,18 @@ async function unregisterMacOS() {
108
112
  await fs.unlink(PLIST_PATH).catch(() => undefined);
109
113
  }
110
114
  // ─── Windows ─────────────────────────────────────────────────────────────────
111
- const REG_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
112
- const REG_VALUE = 'WalldockAgent';
113
- // VBScript launcher: runs walldock-agent.cmd silently (windowStyle=0 = hidden).
114
- // Stored in %APPDATA%\walldock\ so it survives package updates — the .cmd
115
- // wrapper always resolves to whichever version is currently installed.
116
- const VBS_PATH = path.join(process.env['APPDATA'] ?? os.homedir(), 'walldock', 'launch-agent.vbs');
115
+ // Use the per-user Startup folder — always writable, no registry or admin needed.
116
+ const WIN_STARTUP_DIR = path.join(process.env['APPDATA'] ?? os.homedir(), 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup');
117
+ const WIN_VBS_PATH = path.join(WIN_STARTUP_DIR, 'walldock-agent.vbs');
117
118
  async function registerWindows() {
118
119
  const binPath = await resolveGlobalBin();
119
- await fs.mkdir(path.dirname(VBS_PATH), { recursive: true });
120
- // windowStyle=0 = hidden, WaitOnReturn=False
121
- await fs.writeFile(VBS_PATH, `CreateObject("WScript.Shell").Run """${binPath}"" --tray", 0, False\n`, 'utf8');
122
- const wscript = path.join(process.env['SystemRoot'] ?? 'C:\\Windows', 'System32', 'wscript.exe');
123
- const cmd = `"${wscript}" "${VBS_PATH}"`;
124
- await exec('reg', ['add', REG_KEY, '/v', REG_VALUE, '/t', 'REG_SZ', '/d', cmd, '/f'], { windowsHide: true, encoding: 'utf8' });
120
+ // windowStyle=0 = hidden, WaitOnReturn=False no console window at login
121
+ await fs.writeFile(WIN_VBS_PATH, `CreateObject("WScript.Shell").Run """${binPath}"" --tray", 0, False\n`, 'utf8');
125
122
  }
126
123
  async function unregisterWindows() {
127
- await exec('reg', ['delete', REG_KEY, '/v', REG_VALUE, '/f'], { windowsHide: true, encoding: 'utf8' }).catch(() => undefined);
128
- await fs.unlink(VBS_PATH).catch(() => undefined);
124
+ await fs.unlink(WIN_VBS_PATH).catch(() => undefined);
125
+ // Clean up old registry entry left by earlier versions
126
+ await exec('reg', ['delete', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', 'WalldockAgent', '/f'], { windowsHide: true, encoding: 'utf8' }).catch(() => undefined);
129
127
  }
130
128
  // ─── Linux ───────────────────────────────────────────────────────────────────
131
129
  const SYSTEMD_USER_DIR = path.join(os.homedir(), '.config', 'systemd', 'user');
@@ -204,7 +202,7 @@ function startupDescription() {
204
202
  if (process.platform === 'darwin')
205
203
  return `LaunchAgent at ${PLIST_PATH}`;
206
204
  if (process.platform === 'win32')
207
- return `Registry Run key → wscript launcher at ${VBS_PATH}`;
205
+ return `Startup folder: ${WIN_VBS_PATH}`;
208
206
  return `systemd user service (or ${DESKTOP_PATH})`;
209
207
  }
210
208
  /** Returns the resolved global bin path, or null if not globally installed. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@walldock/agent",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Walldock desktop agent — sync wallpapers across all your screens",
5
5
  "license": "MIT",
6
6
  "main": "dist/main.js",