mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-30 13:52:44 -08:00
fix(sync): reconnect immediately on mobile app resume
This commit is contained in:
1 parent
a040f7390a
commit
bce679b6af
3 files changed
+36
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
@@ -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]);
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user