Skip to content

Commit 3c61b57

Browse files
committed
test
1 parent ecb0d1d commit 3c61b57

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/sw/notification.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { getMessaging, onBackgroundMessage } from 'firebase/messaging/sw'
33

44
import { wait } from '/@/lib/basic/timer'
55
import type { FirebasePayloadData } from '/@/lib/notification/firebase'
6-
import type { ServiceWorkerNavigateMessage } from '/@/lib/notification/notification'
76
import { createNotificationArgumentsCreator } from '/@/lib/notification/notificationArguments'
87
import { getMeStore } from '/@/sw/store'
98
import type { NotificationClickEvent } from '/@/types/InlineNotificationReplies'
@@ -22,18 +21,22 @@ const postMessage = (channelId: ChannelId, text: string) =>
2221
})
2322

2423
const openChannel = async (event: NotificationClickEvent) => {
24+
// iOSのPWAでincludeUncontrolled: trueを使うと、
25+
// 通知クリック時にNotification.permissionがdefaultに戻る問題がある
26+
// https://stackoverflow.com/questions/76590928/pwa-on-ios-notification-permission-return-default-whatever-we-chose
2527
const clientsArr = await self.clients.matchAll({
26-
type: 'window',
27-
includeUncontrolled: true
28+
type: 'window'
29+
// includeUncontrolled: trueを使わないことで、Service Workerに制御されている
30+
// クライアントのみを対象とし、client.navigate()が正しく動作するようにする
2831
})
2932
if (clientsArr[0]) {
30-
const client = await clientsArr[0].focus()
31-
const message: ServiceWorkerNavigateMessage = {
32-
type: 'navigate',
33-
to: event.notification.data.path
34-
}
35-
return client.postMessage(message)
33+
const client = clientsArr[0]
34+
// navigate()を使うことで新しいウィンドウを開かずに遷移する
35+
// これにはクライアントがService Workerに制御されている必要がある
36+
await client.navigate(event.notification.data.path)
37+
return client.focus()
3638
} else {
39+
// 制御されているクライアントがない場合のみopenWindowを使用
3740
return self.clients.openWindow(event.notification.data.path)
3841
}
3942
}

0 commit comments

Comments
 (0)