Skip to content

Commit 9f5da48

Browse files
committed
Improve server-list sync: periodic resync + tab-focus trigger
- Re-sync encrypted server list every 5 minutes (if wrapping key available) - Trigger sync when tab becomes visible (catches changes from other devices) - Both fire only when e2e wrapping key is in memory (password-based login)
1 parent 564bae8 commit 9f5da48

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

public/js/modules/app-platform.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,35 @@ async _initE2E() {
481481
if (syncKey && this.serverManager) {
482482
await this.serverManager.syncWithServer(this.token, syncKey);
483483
this._renderServerBar();
484+
485+
// Re-sync periodically (every 5 min) so cross-device changes propagate
486+
// without requiring a full page reload or re-login
487+
if (!this._serverSyncInterval) {
488+
this._serverSyncInterval = setInterval(async () => {
489+
const key = this._e2eWrappingKey || sessionStorage.getItem('haven_e2e_wrap') || null;
490+
if (key && this.serverManager && this.token) {
491+
try {
492+
await this.serverManager.syncWithServer(this.token, key);
493+
this._renderServerBar();
494+
} catch { /* silent — best-effort background sync */ }
495+
}
496+
}, 5 * 60 * 1000);
497+
}
498+
499+
// Also sync when the tab becomes visible (user switching back from another server)
500+
if (!this._serverSyncVisibility) {
501+
this._serverSyncVisibility = true;
502+
document.addEventListener('visibilitychange', async () => {
503+
if (document.visibilityState !== 'visible') return;
504+
const key = this._e2eWrappingKey || sessionStorage.getItem('haven_e2e_wrap') || null;
505+
if (key && this.serverManager && this.token) {
506+
try {
507+
await this.serverManager.syncWithServer(this.token, key);
508+
this._renderServerBar();
509+
} catch { /* silent */ }
510+
}
511+
});
512+
}
484513
}
485514
} catch (err) {
486515
console.warn('[ServerSync] Post-login sync failed:', err.message);

0 commit comments

Comments
 (0)