Skip to content

Commit c46c82d

Browse files
committed
feat: increment cache version and add notification click handler to focus or open app window
1 parent b0dc9aa commit c46c82d

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

sw.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const CACHE_NAME = 'pomodoro-v8';
1+
const CACHE_NAME = 'pomodoro-v9';
22
const ASSETS = [
33
'./',
44
'./index.html',
@@ -32,6 +32,18 @@ self.addEventListener('message', e => {
3232
}
3333
});
3434

35+
self.addEventListener('notificationclick', e => {
36+
e.notification.close();
37+
e.waitUntil(
38+
self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then(clients => {
39+
if (clients.length) {
40+
return clients[0].focus();
41+
}
42+
return self.clients.openWindow('./');
43+
})
44+
);
45+
});
46+
3547
self.addEventListener('fetch', e => {
3648
if (e.request.method !== 'GET') return;
3749
if (!e.request.url.startsWith(self.location.origin)) return;

0 commit comments

Comments
 (0)