Skip to content

Commit c7f1b37

Browse files
committed
force update all clients
1 parent d1b539a commit c7f1b37

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

public/sw.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const VERSION = '1.1.3';
1+
const VERSION = '1.1.4';
22
const CACHE_NAME = `flag-trainer-v${VERSION}`;
33
const BASE_PATH = '/';
44

@@ -106,8 +106,27 @@ self.addEventListener('activate', (event) => {
106106
})
107107
);
108108
}),
109-
// Claim clients but don't force reload
110-
self.clients.claim()
109+
// Force claim all clients
110+
self.clients.claim().then(() => {
111+
// Notify all clients about the update
112+
self.clients.matchAll().then(clients => {
113+
clients.forEach(client => {
114+
client.postMessage({
115+
type: 'APP_UPDATED',
116+
version: VERSION
117+
});
118+
});
119+
});
120+
})
111121
])
112122
);
123+
});
124+
125+
self.addEventListener('message', (event) => {
126+
if (event.data && event.data.type === 'CHECK_VERSION') {
127+
event.ports[0].postMessage({
128+
type: 'VERSION_INFO',
129+
version: VERSION
130+
});
131+
}
113132
});

0 commit comments

Comments
 (0)