11import { PUBLIC_PROVISIONER_URL } from "$env/static/public" ;
2+ import { addNotification } from "$lib/stores/notifications" ;
23import {
34 isPermissionGranted ,
45 registerForPushNotifications ,
56 requestPermission ,
67 sendNotification ,
78} from "@choochmeque/tauri-plugin-notifications-api" ;
89import { invoke } from "@tauri-apps/api/core" ;
9- import { addNotification } from "$lib/stores/notifications" ;
1010
1111export interface DeviceRegistration {
1212 eName : string ;
@@ -119,12 +119,19 @@ class NotificationService {
119119 */
120120 async sendLocalNotification ( payload : NotificationPayload ) : Promise < void > {
121121 try {
122- // Store notification for the notification panel
123- const data = payload . data as Record < string , string > | undefined ;
122+ // Store notification for the notification panel — coerce to string values only
123+ const data = payload . data
124+ ? Object . fromEntries (
125+ Object . entries ( payload . data ) . filter (
126+ ( entry ) : entry is [ string , string ] =>
127+ typeof entry [ 1 ] === "string" ,
128+ ) ,
129+ )
130+ : undefined ;
124131 addNotification ( {
125132 title : payload . title ,
126133 body : payload . body ,
127- data,
134+ data : Object . keys ( data ?? { } ) . length > 0 ? data : undefined ,
128135 } ) ;
129136
130137 // Check permissions first
@@ -202,6 +209,8 @@ class NotificationService {
202209 async checkAndShowNotifications ( ) : Promise < {
203210 globalMessageId ?: string ;
204211 globalChatId ?: string ;
212+ title ?: string ;
213+ body ?: string ;
205214 } | null > {
206215 try {
207216 console . log ( "🔍 Checking for notifications from provisioner..." ) ;
@@ -273,7 +282,8 @@ class NotificationService {
273282 `Found ${ data . notifications . length } notification(s)` ,
274283 ) ;
275284
276- // Show each notification locally
285+ // Show each notification locally — intentionally keep only the
286+ // most recent new_message so the caller navigates to it.
277287 let lastMessageNotif : {
278288 globalMessageId ?: string ;
279289 globalChatId ?: string ;
@@ -293,17 +303,15 @@ class NotificationService {
293303 }
294304 }
295305 return lastMessageNotif ;
296- } else {
297- console . log ( "No new notifications" ) ;
298- return null ;
299306 }
300- } else {
301- console . log (
302- "No notifications endpoint available or error:" ,
303- response . status ,
304- ) ;
307+ console . log ( "No new notifications" ) ;
305308 return null ;
306309 }
310+ console . log (
311+ "No notifications endpoint available or error:" ,
312+ response . status ,
313+ ) ;
314+ return null ;
307315 } catch ( error ) {
308316 console . error ( "Error checking notifications:" , error ) ;
309317 return null ;
@@ -318,7 +326,7 @@ class NotificationService {
318326 await this . sendLocalNotification ( {
319327 title : "Test Notification" ,
320328 body : "This is a test notification from eid-wallet!" ,
321- data : { test : true , timestamp : new Date ( ) . toISOString ( ) } ,
329+ data : { test : " true" , timestamp : new Date ( ) . toISOString ( ) } ,
322330 } ) ;
323331 }
324332
0 commit comments