diff --git a/desktop/src/main.js b/desktop/src/main.js --- a/desktop/src/main.js +++ b/desktop/src/main.js @@ -253,10 +253,16 @@ main.show(); if (app.isPackaged) { - (async () => { + const sendDeviceTokenToWebApp = async () => { const token = await registerForNotifications(); main.webContents.send('on-device-token-registered', token); - })(); + }; + + sendDeviceTokenToWebApp(); + + ipcMain.on('fetch-device-token', () => { + sendDeviceTokenToWebApp(); + }); } } }); diff --git a/desktop/src/preload.js b/desktop/src/preload.js --- a/desktop/src/preload.js +++ b/desktop/src/preload.js @@ -35,6 +35,7 @@ return () => ipcRenderer.removeListener('on-notification-clicked', withEvent); }, + fetchDeviceToken: () => ipcRenderer.send('fetch-device-token'), }; contextBridge.exposeInMainWorld('electronContextBridge', bridge); diff --git a/lib/types/electron-types.js b/lib/types/electron-types.js --- a/lib/types/electron-types.js +++ b/lib/types/electron-types.js @@ -24,4 +24,5 @@ +platform?: 'windows' | 'macos', +onDeviceTokenRegistered?: OnDeviceTokenRegisteredListener => () => void, +onNotificationClicked?: OnNotificationClickedListener => () => void, + +fetchDeviceToken: () => void, }; diff --git a/web/push-notif/push-notifs-handler.js b/web/push-notif/push-notifs-handler.js --- a/web/push-notif/push-notifs-handler.js +++ b/web/push-notif/push-notifs-handler.js @@ -44,6 +44,10 @@ [callSetDeviceToken, dispatchActionPromise], ); + React.useEffect(() => { + electron?.fetchDeviceToken(); + }, []); + const dispatch = useDispatch(); React.useEffect(