feat(connection): notify sidebar when keepalive loses connection

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-09-30 19:49:52 +08:00
1 parent 3ffff92c8f
commit dc503877f9
13 files changed
+864 -27

No files matched your search

+39
View File
@@ -371,6 +371,9 @@ let updateCheckTimer: ReturnType<typeof setInterval> | undefined;
const needsAuth = ref(!isDesktop && (startupProps.startupAuthentication?.required ?? true));
const authenticated = ref(isDesktop || (startupProps.startupAuthentication?.authenticated ?? false));
const setupRequired = ref(!isDesktop && (startupProps.startupAuthentication?.setup_required ?? false));
// Mirrors the template gate above the app shell. The backend liveness stream is registered
// against it so the web runtime only opens an authenticated subscription.
const appReady = computed(() => !setupRequired.value && (!needsAuth.value || authenticated.value));
const showConnectionDialog = ref(false);
const connectionDialogPrefill = ref<ConnectionDeepLinkDraft | null>(null);
@@ -4078,6 +4081,40 @@ function runUpdateNotificationChecks() {
void componentUpdates.refresh();
}
// Backend-confirmed connection liveness losses (#4339). Registered through the forwarded
// `api` layer rather than the Tauri-only `listen` helpers so both runtimes subscribe, and
// keyed off `appReady` so the web runtime never opens the SSE stream before it is
// authenticated (the whole /api surface sits behind the auth middleware).
let connectionLivenessUnlisten: (() => void) | null = null;
let connectionLivenessSubscribing = false;
async function syncConnectionLivenessSubscription(active: boolean): Promise<void> {
if (!active) {
connectionLivenessUnlisten?.();
connectionLivenessUnlisten = null;
return;
}
if (connectionLivenessUnlisten || connectionLivenessSubscribing) return;
connectionLivenessSubscribing = true;
try {
const unlisten = await api.subscribeConnectionLiveness((message) => {
void connectionStore.handleConnectionLivenessMessage(message);
});
if (!appReady.value) {
// Auth flipped off while the subscription was being established.
unlisten();
return;
}
connectionLivenessUnlisten = unlisten;
} catch (error) {
console.error("[DBX] subscribeConnectionLiveness error:", error);
} finally {
connectionLivenessSubscribing = false;
}
}
watch(appReady, (ready) => void syncConnectionLivenessSubscription(ready), { immediate: true });
onMounted(async () => {
clearStartupPreloadRetry();
markStartupPhase("app-mounted");
@@ -4182,6 +4219,8 @@ onMounted(async () => {
onUnmounted(() => {
disposeUpdater();
updatePreparation?.dispose();
connectionLivenessUnlisten?.();
connectionLivenessUnlisten = null;
detachedEventUnlisteners.forEach((unlisten) => unlisten());
detachedEventUnlisteners = [];
cleanupTauriListeners();