fix(sync): reconnect immediately on mobile app resume

This commit is contained in:
Erwan Leboucher authored and Andrew Attali committed 2026-07-19 01:06:27 +02:00
1 parent a040f7390a
commit bce679b6af
3 files changed
+36

No files matched your search

+5
View File
@@ -318,6 +318,11 @@ 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
@@ -0,0 +1,29 @@
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]);
};
+2
View File
@@ -4,6 +4,7 @@ import { useCallback, 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';
type StateData = {
@@ -33,6 +34,7 @@ export function SyncStatus({ mx }: SyncStatusProps) {
previous: undefined,
showConnecting: false,
});
useResumeSyncRetry(mx);
useSyncState(
mx,