sw: await update call

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/953/head
Varun Patil 2023-11-25 11:02:50 -08:00
parent eaba80a73b
commit 14702f7669
2 changed files with 10 additions and 6 deletions

View File

@ -273,9 +273,6 @@ export default defineComponent({
// Disable on dev instances
console.warn('Service Worker is not enabled on localhost.');
} else 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 {
@ -286,9 +283,8 @@ export default defineComponent({
console.info('SW registered: ', registration);
// Check for updates
const currentVersion = await staticConfig.get('version');
if (previousVersion !== currentVersion) {
registration.update();
if (await staticConfig.versionChanged()) {
await registration.update();
}
} catch (error) {
console.error('SW registration failed: ', error);

View File

@ -14,6 +14,7 @@ class StaticConfig {
private initPromises: Array<() => void> = [];
private default: IConfig | null = null;
private storage: Storage;
private verchange: boolean = false;
public constructor() {
this.storage = getBuilder('memories').clearOnLogout().persist().build();
@ -36,6 +37,8 @@ class StaticConfig {
// Check if version changed
const old = this.getDefault();
if (old.version !== this.config.version) {
this.verchange = true;
if (old.version) {
showInfo(
t('memories', 'Memories has been updated to {version}. Reload to get the new version.', {
@ -164,6 +167,11 @@ class StaticConfig {
return config;
}
public async versionChanged(): Promise<boolean> {
await this.getAll();
return this.verchange;
}
}
export default new StaticConfig();