add shenyan-app RN project + PWA push/noise updates
This commit is contained in:
26
PWA/public/sw-push.js
Normal file
26
PWA/public/sw-push.js
Normal file
@@ -0,0 +1,26 @@
|
||||
self.addEventListener('push', function (event) {
|
||||
var data = {};
|
||||
try { data = event.data.json(); } catch (e) { data = { title: '沈晏', body: event.data ? event.data.text() : '' }; }
|
||||
event.waitUntil(
|
||||
self.registration.showNotification(data.title || '沈晏', {
|
||||
body: data.body || '',
|
||||
icon: '/icon-192.png',
|
||||
badge: '/icon-192.png',
|
||||
vibrate: [200, 100, 200],
|
||||
tag: 'shenyan-push',
|
||||
renotify: true,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', function (event) {
|
||||
event.notification.close();
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function (list) {
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (list[i].url && 'focus' in list[i]) return list[i].focus();
|
||||
}
|
||||
if (clients.openWindow) return clients.openWindow('/');
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user