limit open dialogs

This commit is contained in:
FTCHD
2026-07-15 21:24:53 +03:00
parent eae1024858
commit c8e1103bf4
2 changed files with 18 additions and 0 deletions
+2
View File
@@ -10,6 +10,7 @@ import createRCDClient, {
type OpenApiRequiredKeysOf,
type RCDClient,
} from 'rclone-sdk'
import { claimReconnectDialog } from '../../store/memory'
import { selectCurrentHost, usePersistedStore } from '../../store/persisted'
import { UserCancelledError } from '../errors'
@@ -21,6 +22,7 @@ async function handleReconnectIfNeeded(errorMessage: string) {
const match = errorMessage.match(RE_RECONNECT)
if (!match) return false
const remoteName = match[1]
if (!claimReconnectDialog(remoteName)) return true
const confirmed = await ask(
`Remote "${remoteName}" needs to be reconnected. This usually means the authentication token has expired.\n\nWould you like to reconnect now?`,
{
+16
View File
@@ -37,6 +37,8 @@ interface State {
dryRunJobIds: number[]
watchedJobs: Record<number, WatchedJob>
reconnectDialogsShown: string[]
}
export const useStore = create<State>()(
@@ -53,7 +55,21 @@ export const useStore = create<State>()(
dryRunJobIds: [],
watchedJobs: {},
reconnectDialogsShown: [],
}),
{ name: 'shared-store' }
)
)
export function claimReconnectDialog(remoteName: string): boolean {
let claimed = false
useStore.setState((state) => {
if (state.reconnectDialogsShown.includes(remoteName)) return state
claimed = true
return { reconnectDialogsShown: [...state.reconnectDialogsShown, remoteName] }
})
return claimed
}