limit open dialogs
This commit is contained in:
@@ -10,6 +10,7 @@ import createRCDClient, {
|
|||||||
type OpenApiRequiredKeysOf,
|
type OpenApiRequiredKeysOf,
|
||||||
type RCDClient,
|
type RCDClient,
|
||||||
} from 'rclone-sdk'
|
} from 'rclone-sdk'
|
||||||
|
import { claimReconnectDialog } from '../../store/memory'
|
||||||
import { selectCurrentHost, usePersistedStore } from '../../store/persisted'
|
import { selectCurrentHost, usePersistedStore } from '../../store/persisted'
|
||||||
import { UserCancelledError } from '../errors'
|
import { UserCancelledError } from '../errors'
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ async function handleReconnectIfNeeded(errorMessage: string) {
|
|||||||
const match = errorMessage.match(RE_RECONNECT)
|
const match = errorMessage.match(RE_RECONNECT)
|
||||||
if (!match) return false
|
if (!match) return false
|
||||||
const remoteName = match[1]
|
const remoteName = match[1]
|
||||||
|
if (!claimReconnectDialog(remoteName)) return true
|
||||||
const confirmed = await ask(
|
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?`,
|
`Remote "${remoteName}" needs to be reconnected. This usually means the authentication token has expired.\n\nWould you like to reconnect now?`,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ interface State {
|
|||||||
dryRunJobIds: number[]
|
dryRunJobIds: number[]
|
||||||
|
|
||||||
watchedJobs: Record<number, WatchedJob>
|
watchedJobs: Record<number, WatchedJob>
|
||||||
|
|
||||||
|
reconnectDialogsShown: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useStore = create<State>()(
|
export const useStore = create<State>()(
|
||||||
@@ -53,7 +55,21 @@ export const useStore = create<State>()(
|
|||||||
dryRunJobIds: [],
|
dryRunJobIds: [],
|
||||||
|
|
||||||
watchedJobs: {},
|
watchedJobs: {},
|
||||||
|
|
||||||
|
reconnectDialogsShown: [],
|
||||||
}),
|
}),
|
||||||
{ name: 'shared-store' }
|
{ 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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user