refactor(sw): self => globalThis
This commit is contained in:
parent
0f546b47d1
commit
36170a11f5
3 changed files with 13 additions and 13 deletions
|
@ -23,7 +23,7 @@ export async function createNotification<K extends keyof pushNotificationDataMap
|
||||||
const n = await composeNotification(data);
|
const n = await composeNotification(data);
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
return self.registration.showNotification(...n);
|
return globalThis.registration.showNotification(...n);
|
||||||
} else {
|
} else {
|
||||||
console.error('Could not compose notification', data);
|
console.error('Could not compose notification', data);
|
||||||
return createEmptyNotification();
|
return createEmptyNotification();
|
||||||
|
@ -239,7 +239,7 @@ export async function createEmptyNotification() {
|
||||||
const i18n = await swLang.i18n as I18n<any>;
|
const i18n = await swLang.i18n as I18n<any>;
|
||||||
const { t } = i18n;
|
const { t } = i18n;
|
||||||
|
|
||||||
await self.registration.showNotification(
|
await globalThis.registration.showNotification(
|
||||||
t('_notification.emptyPushNotificationMessage'),
|
t('_notification.emptyPushNotificationMessage'),
|
||||||
{
|
{
|
||||||
silent: true,
|
silent: true,
|
||||||
|
@ -253,8 +253,8 @@ export async function createEmptyNotification() {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
for (const n of
|
for (const n of
|
||||||
[
|
[
|
||||||
...(await self.registration.getNotifications({ tag: 'user_visible_auto_notification' })),
|
...(await globalThis.registration.getNotifications({ tag: 'user_visible_auto_notification' })),
|
||||||
...(await self.registration.getNotifications({ tag: 'read_notification' })),
|
...(await globalThis.registration.getNotifications({ tag: 'read_notification' })),
|
||||||
]
|
]
|
||||||
) {
|
) {
|
||||||
n.close();
|
n.close();
|
||||||
|
|
|
@ -51,11 +51,11 @@ export async function openClient(order: swMessageOrderType, url: string, loginId
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.clients.openWindow(getUrlWithLoginId(url, loginId));
|
return globalThis.clients.openWindow(getUrlWithLoginId(url, loginId));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findClient() {
|
export async function findClient() {
|
||||||
const clients = await self.clients.matchAll({
|
const clients = await globalThis.clients.matchAll({
|
||||||
type: 'window',
|
type: 'window',
|
||||||
});
|
});
|
||||||
for (const c of clients) {
|
for (const c of clients) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import * as swos from '@/scripts/operations';
|
||||||
import { acct as getAcct } from '@/filters/user';
|
import { acct as getAcct } from '@/filters/user';
|
||||||
|
|
||||||
globalThis.addEventListener('install', ev => {
|
globalThis.addEventListener('install', ev => {
|
||||||
//ev.waitUntil(self.skipWaiting());
|
//ev.waitUntil(globalThis.skipWaiting());
|
||||||
});
|
});
|
||||||
|
|
||||||
globalThis.addEventListener('activate', ev => {
|
globalThis.addEventListener('activate', ev => {
|
||||||
|
@ -17,7 +17,7 @@ globalThis.addEventListener('activate', ev => {
|
||||||
.filter((v) => v !== swLang.cacheName)
|
.filter((v) => v !== swLang.cacheName)
|
||||||
.map(name => caches.delete(name)),
|
.map(name => caches.delete(name)),
|
||||||
))
|
))
|
||||||
.then(() => self.clients.claim()),
|
.then(() => globalThis.clients.claim()),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ globalThis.addEventListener('fetch', ev => {
|
||||||
|
|
||||||
globalThis.addEventListener('push', ev => {
|
globalThis.addEventListener('push', ev => {
|
||||||
// クライアント取得
|
// クライアント取得
|
||||||
ev.waitUntil(self.clients.matchAll({
|
ev.waitUntil(globalThis.clients.matchAll({
|
||||||
includeUncontrolled: true,
|
includeUncontrolled: true,
|
||||||
type: 'window',
|
type: 'window',
|
||||||
}).then(async (clients: readonly WindowClient[]) => {
|
}).then(async (clients: readonly WindowClient[]) => {
|
||||||
|
@ -58,24 +58,24 @@ globalThis.addEventListener('push', ev => {
|
||||||
|
|
||||||
return createNotification(data);
|
return createNotification(data);
|
||||||
case 'readAllNotifications':
|
case 'readAllNotifications':
|
||||||
for (const n of await self.registration.getNotifications()) {
|
for (const n of await globalThis.registration.getNotifications()) {
|
||||||
if (n?.data?.type === 'notification') n.close();
|
if (n?.data?.type === 'notification') n.close();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'readAllAntennas':
|
case 'readAllAntennas':
|
||||||
for (const n of await self.registration.getNotifications()) {
|
for (const n of await globalThis.registration.getNotifications()) {
|
||||||
if (n?.data?.type === 'unreadAntennaNote') n.close();
|
if (n?.data?.type === 'unreadAntennaNote') n.close();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'readNotifications':
|
case 'readNotifications':
|
||||||
for (const n of await self.registration.getNotifications()) {
|
for (const n of await globalThis.registration.getNotifications()) {
|
||||||
if (data.body.notificationIds.includes(n.data.body.id)) {
|
if (data.body.notificationIds.includes(n.data.body.id)) {
|
||||||
n.close();
|
n.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'readAntenna':
|
case 'readAntenna':
|
||||||
for (const n of await self.registration.getNotifications()) {
|
for (const n of await globalThis.registration.getNotifications()) {
|
||||||
if (n?.data?.type === 'unreadAntennaNote' && data.body.antennaId === n.data.body.antenna.id) {
|
if (n?.data?.type === 'unreadAntennaNote' && data.body.antennaId === n.data.body.antenna.id) {
|
||||||
n.close();
|
n.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue