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