diff --git a/apps/pwa/src/updater.tsx b/apps/pwa/src/updater.tsx index 92e73c85..37f13db5 100644 --- a/apps/pwa/src/updater.tsx +++ b/apps/pwa/src/updater.tsx @@ -28,67 +28,63 @@ const VersionUpdater = styled.div` `; if ('serviceWorker' in navigator) { if (definition.WITH_SW) { - window.requestIdleCallback(() => - import('workbox-window').then(({ Workbox }) => { - const wb = new Workbox('/service_worker.js'); - wb.register(); + import('workbox-window').then(({ Workbox }) => { + const wb = new Workbox('/service_worker.js'); + wb.register(); + + /** + * 生产模式下询问是否升级 + * 开发模式下默认升级 + * @author mebtte + */ + if (process.env.NODE_ENV === 'production') { + let updateNoticeId: string = ''; + wb.addEventListener('waiting', () => { + updateNoticeId = notice.info( + +
{t('pwa_update_question')}
+
+ { + wb.messageSkipWaiting(); + return Promise.race([ + new Promise((resolve) => + wb.addEventListener('controlling', resolve), + ), + sleep(5000), + ]).then(() => window.location.reload()); + }} + > + + + notice.close(updateNoticeId)} + > + + +
+
, + { duration: 0, closable: false }, + ); + }); /** - * 生产模式下询问是否升级 - * 开发模式下默认升级 + * 定时检查更新 * @author mebtte */ - if (process.env.NODE_ENV === 'production') { - let updateNoticeId: string = ''; - wb.addEventListener('waiting', () => { - updateNoticeId = notice.info( - -
{t('pwa_update_question')}
-
- { - wb.messageSkipWaiting(); - return Promise.race([ - new Promise((resolve) => - wb.addEventListener('controlling', resolve), - ), - sleep(5000), - ]).then(() => window.location.reload()); - }} - > - - - notice.close(updateNoticeId)} - > - - -
-
, - { duration: 0, closable: false }, - ); - }); - - /** - * 定时检查更新 - * @author mebtte - */ - window.setInterval(() => { - notice.close(updateNoticeId); - return wb.update(); - }, 1000 * 60 * 60); - } - }), - ); - } else { - window.requestIdleCallback(() => { - window.navigator.serviceWorker - .getRegistrations() - .then((registrations) => - registrations.forEach((registration) => registration.unregister()), - ); + window.setInterval(() => { + notice.close(updateNoticeId); + return wb.update(); + }, 1000 * 60 * 60); + } }); + } else { + window.navigator.serviceWorker + .getRegistrations() + .then((registrations) => + registrations.forEach((registration) => registration.unregister()), + ); } }