Skip to content

Commit

Permalink
feat: add configurable reloading delay for page refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
a1mersnow committed Jan 20, 2025
1 parent 3f8620f commit 5757b11
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/providers/baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const provider: Provider = {
shouldShowEntry,
getContainer,
getApiDelay: () => 0,
getReloadingDelay: () => 4000,
renameOne,
setRequestHeader,
ButtonComponent,
Expand Down
6 changes: 4 additions & 2 deletions src/stores/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ export const useMainStore = defineStore('main', () => {
running.value = false

if (!import.meta.env.DEV) {
warning.value = '即将刷新页面...'
const delay = provider.getReloadingDelay()
const seconds = Math.floor(delay / 1000)
warning.value = `即将刷新页面(${seconds}s后)...`
setTimeout(() => {
location.reload()
}, 2500)
}, delay)
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface Provider {
setRequestHeader: (key: string, value: string) => void
/** where to put the button into and how to style the wrapper */
getContainer: () => ContainerInfo
/** how long we wait for reloading */
getReloadingDelay?: () => number
/** the button component */
ButtonComponent: Component
}
5 changes: 5 additions & 0 deletions src/utils/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export function getApiMaxConcurrent() {
return resolveProvider().MAX_CONCURRENT ?? 3
}

export function getReloadingDelay() {
const p = resolveProvider()
return p.getReloadingDelay ? p.getReloadingDelay() : 1000
}

export function getFetchMode(): FetchMode {
return resolveProvider().FETCH_MODE || 'listen-url'
}
Expand Down

0 comments on commit 5757b11

Please sign in to comment.