fix(sync): debounce connection-lost banner instead of ineffective resume retry

This commit is contained in:
Erwan Leboucher authored and Andrew Attali committed 2026-07-19 01:06:27 +02:00
1 parent dab35f9c44
commit 47b3ea2512
3 files changed
+18 -39

No files matched your search

-5
View File
@@ -320,11 +320,6 @@ pub fn run() {
};
app.run(|app, event| {
if matches!(event, tauri::RunEvent::Resumed) {
use tauri::Emitter;
let _ = app.emit("app-resumed", ());
}
#[cfg(desktop)]
desktop::tray::handle_run_event(app, event);
-29
View File
@@ -1,29 +0,0 @@
import { useEffect } from 'react';
import { isTauri } from '@tauri-apps/api/core';
import { listen } from '@tauri-apps/api/event';
import type { MatrixClient } from '$types/matrix-sdk';
import { SyncState } from '$types/matrix-sdk';
export const useResumeSyncRetry = (mx: MatrixClient | undefined): void => {
useEffect(() => {
if (!mx || !isTauri()) return undefined;
let disposed = false;
let unlisten: (() => void) | undefined;
listen('app-resumed', () => {
const state = mx.getSyncState();
if (state === SyncState.Error || state === SyncState.Reconnecting) {
mx.retryImmediately();
}
}).then((fn) => {
if (disposed) fn();
else unlisten = fn;
});
return () => {
disposed = true;
unlisten?.();
};
}, [mx]);
};
+18 -5
View File
@@ -1,12 +1,13 @@
import type { MatrixClient } from '$types/matrix-sdk';
import { SyncState } from '$types/matrix-sdk';
import { useCallback, useRef, useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import { Box, config, Line, Text } from 'folds';
import * as Sentry from '@sentry/react';
import { useSyncState } from '$hooks/useSyncState';
import { useResumeSyncRetry } from '$hooks/useResumeSyncRetry';
import { ContainerColor } from '$styles/ContainerColor.css';
const DISCONNECTED_GRACE_MS = 2000;
type StateData = {
current: SyncState | null;
previous: SyncState | null | undefined;
@@ -34,7 +35,19 @@ export function SyncStatus({ mx }: SyncStatusProps) {
previous: undefined,
showConnecting: false,
});
useResumeSyncRetry(mx);
const [showDisconnected, setShowDisconnected] = useState(false);
const isDisconnected =
stateData.current === SyncState.Reconnecting || stateData.current === SyncState.Error;
useEffect(() => {
if (!isDisconnected) {
setShowDisconnected(false);
return undefined;
}
const timeoutId = setTimeout(() => setShowDisconnected(true), DISCONNECTED_GRACE_MS);
return () => clearTimeout(timeoutId);
}, [isDisconnected]);
useSyncState(
mx,
@@ -83,7 +96,7 @@ export function SyncStatus({ mx }: SyncStatusProps) {
);
}
if (stateData.current === SyncState.Reconnecting) {
if (showDisconnected && stateData.current === SyncState.Reconnecting) {
return (
<Box direction="Column" shrink="No">
<Box
@@ -99,7 +112,7 @@ export function SyncStatus({ mx }: SyncStatusProps) {
);
}
if (stateData.current === SyncState.Error) {
if (showDisconnected && stateData.current === SyncState.Error) {
return (
<Box direction="Column" shrink="No">
<Box