parent
eaba80a73b
commit
14702f7669
|
@ -273,9 +273,6 @@ export default defineComponent({
|
||||||
// Disable on dev instances
|
// Disable on dev instances
|
||||||
console.warn('Service Worker is not enabled on localhost.');
|
console.warn('Service Worker is not enabled on localhost.');
|
||||||
} else if ('serviceWorker' in navigator) {
|
} 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
|
// Use the window load event to keep the page load performant
|
||||||
window.addEventListener('load', async () => {
|
window.addEventListener('load', async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -286,9 +283,8 @@ export default defineComponent({
|
||||||
console.info('SW registered: ', registration);
|
console.info('SW registered: ', registration);
|
||||||
|
|
||||||
// Check for updates
|
// Check for updates
|
||||||
const currentVersion = await staticConfig.get('version');
|
if (await staticConfig.versionChanged()) {
|
||||||
if (previousVersion !== currentVersion) {
|
await registration.update();
|
||||||
registration.update();
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('SW registration failed: ', error);
|
console.error('SW registration failed: ', error);
|
||||||
|
|
|
@ -14,6 +14,7 @@ class StaticConfig {
|
||||||
private initPromises: Array<() => void> = [];
|
private initPromises: Array<() => void> = [];
|
||||||
private default: IConfig | null = null;
|
private default: IConfig | null = null;
|
||||||
private storage: Storage;
|
private storage: Storage;
|
||||||
|
private verchange: boolean = false;
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
this.storage = getBuilder('memories').clearOnLogout().persist().build();
|
this.storage = getBuilder('memories').clearOnLogout().persist().build();
|
||||||
|
@ -36,6 +37,8 @@ class StaticConfig {
|
||||||
// Check if version changed
|
// Check if version changed
|
||||||
const old = this.getDefault();
|
const old = this.getDefault();
|
||||||
if (old.version !== this.config.version) {
|
if (old.version !== this.config.version) {
|
||||||
|
this.verchange = true;
|
||||||
|
|
||||||
if (old.version) {
|
if (old.version) {
|
||||||
showInfo(
|
showInfo(
|
||||||
t('memories', 'Memories has been updated to {version}. Reload to get the new version.', {
|
t('memories', 'Memories has been updated to {version}. Reload to get the new version.', {
|
||||||
|
@ -164,6 +167,11 @@ class StaticConfig {
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async versionChanged(): Promise<boolean> {
|
||||||
|
await this.getAll();
|
||||||
|
return this.verchange;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new StaticConfig();
|
export default new StaticConfig();
|
||||||
|
|
Loading…
Reference in New Issue