diff --git a/src/App.vue b/src/App.vue index 785a686d..915445d4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -71,6 +71,7 @@ import { emit, subscribe } from '@nextcloud/event-bus'; import * as utils from './services/Utils'; import * as nativex from './native'; +import staticConfig from './services/static-config'; import UserConfig from './mixins/UserConfig'; import Timeline from './components/Timeline.vue'; import Settings from './components/Settings.vue'; @@ -280,6 +281,9 @@ export default defineComponent({ async beforeMount() { if ('serviceWorker' in navigator) { + // Get the config before loading + const previousVersion = staticConfig.getSync('version'); + // Use the window load event to keep the page load performant window.addEventListener('load', async () => { try { @@ -288,6 +292,12 @@ export default defineComponent({ scope: generateUrl('/apps/memories'), }); console.log('SW registered: ', registration); + + // Check for updates + const currentVersion = await staticConfig.get('version'); + if (previousVersion !== currentVersion) { + registration.update(); + } } catch (error) { console.error('SW registration failed: ', error); } diff --git a/src/services/static-config.ts b/src/services/static-config.ts index d6c6c495..98e74503 100644 --- a/src/services/static-config.ts +++ b/src/services/static-config.ts @@ -36,19 +36,15 @@ class StaticConfig { const old = this.getDefault(); if (old.version !== this.config.version) { if (old.version) { - showInfo(t('memories', 'Memories has been updated. Please reload to get the new version.')); + showInfo( + t('memories', 'Memories has been updated to {version}. Reload to get the new version.', { + version: this.config.version, + }) + ); } // Clear page cache, keep other caches window.caches?.delete('pages'); - - // Update service worker if present - navigator.serviceWorker - ?.getRegistration() - .then((reg) => { - reg?.update(); - }) - .catch(() => {}); } // Assign to existing default