Skip to content

Commit

Permalink
CLEAR_FETCH_CACHE fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Sep 4, 2024
1 parent c156973 commit 0dcf4b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/client/initMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import EventEmitter from 'events';
import * as sdk from 'matrix-js-sdk';

import Olm from '@matrix-org/olm';

import { clearFetchPwaCache } from '@src/util/pwa/installer';
import storageManager from '@src/util/libs/Localstorage';
import MxcUrl from '@src/util/libs/MxcUrl';

Expand Down Expand Up @@ -256,6 +258,7 @@ class InitMatrix extends EventEmitter {
}

clearCacheAndReload() {
clearFetchPwaCache();
this.matrixClient.stopClient();
this.matrixClient.store.deleteAllData().then(() => {
if (global.tinyJsonDB && typeof global.tinyJsonDB.clearCacheData === 'function') {
Expand Down
8 changes: 8 additions & 0 deletions src/util/pwa/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ export function isUsingPWA() {
return usingPWA;
}

export function clearFetchPwaCache() {
if ('serviceWorker' in navigator || 'ServiceWorker' in navigator) {
navigator.serviceWorker.controller.postMessage({
type: 'CLEAR_FETCH_CACHE',
});
}
}

export function installPWA() {
if ('serviceWorker' in navigator || 'ServiceWorker' in navigator) {
// Get Items
Expand Down
14 changes: 14 additions & 0 deletions src/util/pwa/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,17 @@ self.addEventListener('fetch', function (event) {

event.respondWith(proxyRequest(caches, request));
});

self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'CLEAR_FETCH_CACHE') {
event.waitUntil(
caches.keys().then(function (cacheNames) {
return Promise.all(
cacheNames.map(function (cacheName) {
return caches.delete(cacheName);
}),
);
}),
);
}
});

0 comments on commit 0dcf4b3

Please sign in to comment.