@walldock/agent 0.2.0 → 0.2.1

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
@@ -47,6 +47,7 @@ const pid_1 = require("./pid");
47
47
  const tray_1 = require("./tray");
48
48
  // ─── Logging ─────────────────────────────────────────────────────────────────
49
49
  const isDaemon = process.argv.includes('--daemon');
50
+ const isTray = process.argv.includes('--tray');
50
51
  function logDir() {
51
52
  if (process.platform === 'darwin')
52
53
  return path.join(os.homedir(), 'Library', 'Logs');
@@ -62,7 +63,7 @@ async function openLog() {
62
63
  }
63
64
  function log(msg) {
64
65
  const line = `[${new Date().toISOString()}] ${msg}\n`;
65
- if (isDaemon && logStream) {
66
+ if ((isDaemon || isTray) && logStream) {
66
67
  logStream.write(line).catch(() => undefined);
67
68
  }
68
69
  else {
@@ -96,7 +97,7 @@ async function main() {
96
97
  }
97
98
  return;
98
99
  }
99
- if (isDaemon)
100
+ if (isDaemon || isTray)
100
101
  await openLog();
101
102
  // Single-instance guard
102
103
  try {
@@ -125,8 +126,8 @@ async function main() {
125
126
  log('Device token is no longer valid. Clearing credentials…');
126
127
  await storage.deleteDeviceToken();
127
128
  await storage.clearDeviceIdentity();
128
- if (isDaemon) {
129
- log('Run "walldock-agent" (without --daemon) to re-pair this device.');
129
+ if (isDaemon || isTray) {
130
+ log('Run "walldock-agent" to re-pair this device.');
130
131
  await shutdown();
131
132
  return;
132
133
  }
@@ -163,15 +164,28 @@ async function main() {
163
164
  }
164
165
  process.on('SIGINT', () => { void shutdown(); });
165
166
  process.on('SIGTERM', () => { void shutdown(); });
166
- function maybeStartTray() {
167
- if (isDaemon || trayHandle)
168
- return;
169
- try {
170
- trayHandle = (0, tray_1.startTray)(() => { void sync.syncNow(); }, () => { void shutdown(); });
171
- }
172
- catch {
173
- // tray unavailable (headless/no display) — continue without it
167
+ async function maybeStartTray() {
168
+ if (isDaemon)
169
+ return false;
170
+ if (isTray) {
171
+ // Already a detached background process start the tray in-place
172
+ try {
173
+ trayHandle = (0, tray_1.startTray)(() => { void sync.syncNow(); }, () => { void shutdown(); });
174
+ }
175
+ catch { /* no display — run headlessly */ }
176
+ return false;
174
177
  }
178
+ // Console-attached interactive session: re-spawn detached so closing the
179
+ // terminal doesn't kill the agent.
180
+ await (0, pid_1.releaseLock)();
181
+ const { spawn } = await Promise.resolve().then(() => __importStar(require('node:child_process')));
182
+ const child = spawn(process.execPath, [process.argv[1], '--tray'], {
183
+ detached: true,
184
+ stdio: 'ignore',
185
+ windowsHide: true,
186
+ });
187
+ child.unref();
188
+ return true;
175
189
  }
176
190
  // Try to resume from stored token
177
191
  log('Walldock Agent starting…');
@@ -179,11 +193,12 @@ async function main() {
179
193
  if (existing) {
180
194
  await storage.setDeviceIdentity({ deviceId: existing.deviceId, deviceName: existing.deviceName });
181
195
  log(`Linked as "${existing.deviceName}". Starting sync…`);
182
- maybeStartTray();
183
- sync.start({ token: existing.token, deviceId: existing.deviceId });
184
- if (trayHandle)
196
+ if (await maybeStartTray()) {
185
197
  console.log('Walldock Agent is running in the system tray.');
186
- return; // sync loop keeps process alive
198
+ process.exit(0);
199
+ }
200
+ sync.start({ token: existing.token, deviceId: existing.deviceId });
201
+ return; // sync loop keeps process alive (isTray path)
187
202
  }
188
203
  // No valid token — need to pair
189
204
  if (isDaemon) {
@@ -220,16 +235,13 @@ async function main() {
220
235
  }
221
236
  catch (err) {
222
237
  console.warn(` Could not register for startup: ${err}`);
223
- console.warn(' You can run "walldock-agent --daemon" manually to start syncing.');
238
+ console.warn(' You can run "walldock-agent" manually to start syncing.');
224
239
  }
225
240
  }
226
241
  }
227
- maybeStartTray();
228
- if (trayHandle) {
229
- console.log('\nWalldock Agent is running in the system tray. You can close this terminal.\n');
230
- }
231
- else {
232
- console.log('\nStarting sync. Press Ctrl+C to stop.\n');
242
+ if (await maybeStartTray()) {
243
+ console.log('\nWalldock Agent is running in the system tray.\n');
244
+ process.exit(0);
233
245
  }
234
246
  sync.start({ token: result.token, deviceId: result.deviceId });
235
247
  }
package/dist/startup.js CHANGED
@@ -83,7 +83,7 @@ function plistContent(binPath) {
83
83
  <key>ProgramArguments</key>
84
84
  <array>
85
85
  <string>${binPath}</string>
86
- <string>--daemon</string>
86
+ <string>--tray</string>
87
87
  </array>
88
88
  <key>RunAtLoad</key>
89
89
  <true/>
@@ -112,7 +112,7 @@ const REG_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
112
112
  const REG_VALUE = 'WalldockAgent';
113
113
  async function registerWindows() {
114
114
  const binPath = await resolveGlobalBin();
115
- const cmd = `"${binPath}" --daemon`;
115
+ const cmd = `"${binPath}" --tray`;
116
116
  await exec('reg', ['add', REG_KEY, '/v', REG_VALUE, '/t', 'REG_SZ', '/d', cmd, '/f']);
117
117
  }
118
118
  async function unregisterWindows() {
@@ -130,7 +130,7 @@ After=network-online.target
130
130
  Wants=network-online.target
131
131
 
132
132
  [Service]
133
- ExecStart=${binPath} --daemon
133
+ ExecStart=${binPath} --tray
134
134
  Restart=on-failure
135
135
  RestartSec=10s
136
136
 
@@ -142,7 +142,7 @@ function desktopContent(binPath) {
142
142
  return `[Desktop Entry]
143
143
  Type=Application
144
144
  Name=Walldock Agent
145
- Exec=${binPath} --daemon
145
+ Exec=${binPath} --tray
146
146
  Hidden=false
147
147
  NoDisplay=false
148
148
  X-GNOME-Autostart-enabled=true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@walldock/agent",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Walldock desktop agent — sync wallpapers across all your screens",
5
5
  "license": "MIT",
6
6
  "main": "dist/main.js",