@walldock/agent 0.2.2 → 0.2.4
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/auth.js +9 -2
- package/dist/main.js +12 -6
- package/package.json +1 -1
package/dist/auth.js
CHANGED
|
@@ -134,8 +134,15 @@ async function validateStoredToken(api) {
|
|
|
134
134
|
}
|
|
135
135
|
return { token, deviceId: v.deviceId, deviceName: v.deviceName };
|
|
136
136
|
}
|
|
137
|
-
catch {
|
|
138
|
-
//
|
|
137
|
+
catch (err) {
|
|
138
|
+
// Auth errors mean the token is genuinely invalid — clear it and re-pair
|
|
139
|
+
const msg = err instanceof Error ? err.message.toLowerCase() : '';
|
|
140
|
+
if (msg.includes('invalid device token') || msg.includes('http 401') || msg.includes('http 403')) {
|
|
141
|
+
await storage.deleteDeviceToken();
|
|
142
|
+
await storage.clearDeviceIdentity();
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
// Genuine network error (offline, timeout) — start offline with cached identity
|
|
139
146
|
const cached = await storage.getDeviceIdentity();
|
|
140
147
|
if (cached)
|
|
141
148
|
return { token, ...cached };
|
package/dist/main.js
CHANGED
|
@@ -73,9 +73,11 @@ function log(msg) {
|
|
|
73
73
|
// ─── Main ─────────────────────────────────────────────────────────────────────
|
|
74
74
|
async function main() {
|
|
75
75
|
const args = process.argv.slice(2);
|
|
76
|
-
// --unlink: remove stored credentials and startup entry
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
// --unlink / --relink: remove stored credentials and startup entry
|
|
77
|
+
// --relink also falls through to the pairing flow below
|
|
78
|
+
if (args.includes('--unlink') || args.includes('--relink')) {
|
|
79
|
+
const isRelink = args.includes('--relink');
|
|
80
|
+
// Kill any running background instance first
|
|
79
81
|
const bgPid = await (0, pid_1.runningPid)();
|
|
80
82
|
if (bgPid) {
|
|
81
83
|
try {
|
|
@@ -92,8 +94,11 @@ async function main() {
|
|
|
92
94
|
await storage.deleteDeviceToken();
|
|
93
95
|
await storage.clearDeviceIdentity();
|
|
94
96
|
await (0, startup_1.unregisterStartup)().catch(() => undefined);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
if (!isRelink) {
|
|
98
|
+
console.log('Device unlinked and startup entry removed.');
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
console.log('Device unlinked. Starting pairing…\n');
|
|
97
102
|
}
|
|
98
103
|
// --status: print current link status
|
|
99
104
|
if (args.includes('--status')) {
|
|
@@ -204,7 +209,8 @@ async function main() {
|
|
|
204
209
|
await storage.setDeviceIdentity({ deviceId: existing.deviceId, deviceName: existing.deviceName });
|
|
205
210
|
log(`Linked as "${existing.deviceName}". Starting sync…`);
|
|
206
211
|
if (await maybeStartTray()) {
|
|
207
|
-
console.log(
|
|
212
|
+
console.log(`Walldock Agent is running in the system tray (linked as "${existing.deviceName}").`);
|
|
213
|
+
console.log('To re-link this device: walldock-agent --unlink');
|
|
208
214
|
process.exit(0);
|
|
209
215
|
}
|
|
210
216
|
sync.start({ token: existing.token, deviceId: existing.deviceId });
|