Skip to content

Commit

Permalink
fix service worker reload prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
rwv committed Nov 19, 2023
1 parent 8ca026b commit f12f196
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
29 changes: 22 additions & 7 deletions src/components/Misc/ServiceWorkerReloadPrompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const { offlineReady, needRefresh } = useRegisterSW()
const { offlineReady, needRefresh, updateServiceWorker } = useRegisterSW()
const message = useMessage()
Expand All @@ -22,12 +22,27 @@ watch(offlineReady, (ready) => {
watch(needRefresh, (refresh) => {
if (refresh) {
console.log('Service Worker need to refresh')
message.info(t('base.serviceWorker.needRefresh'), {
icon: () => h(NIcon, null, { default: () => h(Refresh) }),
closable: true,
keepAliveOnHover: true,
duration: 5000
})
message.info(
() =>
h(
'span',
{
onClick: () => {
message.destroyAll()
console.log('updateServiceWorker')
updateServiceWorker(true)
},
style: 'cursor: pointer'
},
t('base.serviceWorker.needRefresh')
),
{
icon: () => h(NIcon, null, { default: () => h(Refresh) }),
closable: true,
keepAliveOnHover: true,
duration: 5000
}
)
}
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/locale/en/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const base = {
scanTitle: 'Scan',
serviceWorker: {
offlineReady: 'App ready to work offline',
needRefresh: 'New content available, reload to update.'
needRefresh: 'New version available, click to refresh.'
}
}
2 changes: 1 addition & 1 deletion src/locale/zh-CN/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export const base = {
scanTitle: '扫描',
serviceWorker: {
offlineReady: '离线缓存已准备就绪',
needRefresh: '网站代码已更新,刷新界面可享受新版本。不刷新也可继续使用'
needRefresh: '网站代码已更新,点此可享受新版本。'
}
}

0 comments on commit f12f196

Please sign in to comment.