@walldock/agent 0.1.2 → 0.1.3
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 +26 -0
- package/dist/sync.d.ts +2 -0
- package/dist/sync.js +20 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -114,6 +114,32 @@ async function main() {
|
|
|
114
114
|
log(`[sync] ok at ${lastSyncAt}`);
|
|
115
115
|
},
|
|
116
116
|
onLog: log,
|
|
117
|
+
onInvalidToken() {
|
|
118
|
+
void (async () => {
|
|
119
|
+
log('Device token is no longer valid. Clearing credentials…');
|
|
120
|
+
await storage.deleteDeviceToken();
|
|
121
|
+
await storage.clearDeviceIdentity();
|
|
122
|
+
if (isDaemon) {
|
|
123
|
+
log('Run "walldock-agent" (without --daemon) to re-pair this device.');
|
|
124
|
+
await shutdown();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
console.log('\nDevice token is no longer valid. Please re-pair this device.\n');
|
|
128
|
+
let result;
|
|
129
|
+
try {
|
|
130
|
+
result = await (0, auth_1.runPairingFlow)(api);
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
console.error(`\nRe-pairing failed: ${err}`);
|
|
134
|
+
await shutdown();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
await storage.setDeviceToken(result.token);
|
|
138
|
+
await storage.setDeviceIdentity({ deviceId: result.deviceId, deviceName: result.deviceName });
|
|
139
|
+
console.log(`\n✓ Re-linked as "${result.deviceName}"\n`);
|
|
140
|
+
sync.start({ token: result.token, deviceId: result.deviceId });
|
|
141
|
+
})();
|
|
142
|
+
},
|
|
117
143
|
});
|
|
118
144
|
// Graceful shutdown
|
|
119
145
|
let stopping = false;
|
package/dist/sync.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type ConnectionStatus = 'idle' | 'online' | 'error';
|
|
|
7
7
|
export interface SyncCallbacks {
|
|
8
8
|
onTick(status: ConnectionStatus, lastSyncAt?: string): void;
|
|
9
9
|
onLog(msg: string): void;
|
|
10
|
+
onInvalidToken(): void;
|
|
10
11
|
}
|
|
11
12
|
export declare class SyncService {
|
|
12
13
|
private readonly api;
|
|
@@ -25,6 +26,7 @@ export declare class SyncService {
|
|
|
25
26
|
private scheduleNext;
|
|
26
27
|
private runTick;
|
|
27
28
|
private doTick;
|
|
29
|
+
private notifyInvalidToken;
|
|
28
30
|
private handlePush;
|
|
29
31
|
private reportScreensIfChanged;
|
|
30
32
|
private fetchCommands;
|
package/dist/sync.js
CHANGED
|
@@ -6,6 +6,9 @@ const index_2 = require("./wallpaper/index");
|
|
|
6
6
|
const cache_1 = require("./cache");
|
|
7
7
|
const sse_1 = require("./sse");
|
|
8
8
|
const POLL_INTERVAL_MS = 15_000;
|
|
9
|
+
function isInvalidToken(err) {
|
|
10
|
+
return err instanceof Error && err.message.toLowerCase().includes('invalid device token');
|
|
11
|
+
}
|
|
9
12
|
class SyncService {
|
|
10
13
|
api;
|
|
11
14
|
callbacks;
|
|
@@ -72,6 +75,10 @@ class SyncService {
|
|
|
72
75
|
this.tickInFlight = null;
|
|
73
76
|
}
|
|
74
77
|
}
|
|
78
|
+
notifyInvalidToken() {
|
|
79
|
+
this.stop();
|
|
80
|
+
this.callbacks.onInvalidToken();
|
|
81
|
+
}
|
|
75
82
|
async handlePush() {
|
|
76
83
|
if (this.tickInFlight || !this.context)
|
|
77
84
|
return;
|
|
@@ -95,6 +102,10 @@ class SyncService {
|
|
|
95
102
|
this.lastScreensFingerprint = fp;
|
|
96
103
|
}
|
|
97
104
|
catch (err) {
|
|
105
|
+
if (isInvalidToken(err)) {
|
|
106
|
+
this.notifyInvalidToken();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
98
109
|
this.callbacks.onLog(`[sync] reportScreens failed: ${err}`);
|
|
99
110
|
}
|
|
100
111
|
}
|
|
@@ -106,7 +117,11 @@ class SyncService {
|
|
|
106
117
|
}
|
|
107
118
|
this.callbacks.onTick('online', new Date().toISOString());
|
|
108
119
|
}
|
|
109
|
-
catch {
|
|
120
|
+
catch (err) {
|
|
121
|
+
if (isInvalidToken(err)) {
|
|
122
|
+
this.notifyInvalidToken();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
110
125
|
this.callbacks.onTick('error');
|
|
111
126
|
}
|
|
112
127
|
}
|
|
@@ -116,6 +131,10 @@ class SyncService {
|
|
|
116
131
|
assignments = await this.api.getDeviceScreenAssignments(ctx.token, ctx.deviceId);
|
|
117
132
|
}
|
|
118
133
|
catch (err) {
|
|
134
|
+
if (isInvalidToken(err)) {
|
|
135
|
+
this.notifyInvalidToken();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
119
138
|
this.callbacks.onLog(`[sync] getAssignments failed: ${err}`);
|
|
120
139
|
return;
|
|
121
140
|
}
|