diff --git a/desktop/flow-typed/npm/electron_v22.0.0.js b/desktop/flow-typed/npm/electron_v22.0.0.js --- a/desktop/flow-typed/npm/electron_v22.0.0.js +++ b/desktop/flow-typed/npm/electron_v22.0.0.js @@ -228,7 +228,7 @@ declare type IpcMain = { on( channel: string, - listener: (event: IpcMainEvent, ...args: $ReadOnlyArray) => void, + listener: (event: IpcMainEvent, ...args: $ReadOnlyArray) => mixed, ): void, removeListener( channel: string, 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,13 @@ 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 @@ -45,6 +45,10 @@ [callSetDeviceToken, dispatchActionPromise], ); + React.useEffect(() => { + electron?.fetchDeviceToken(); + }, []); + const dispatch = useDispatch(); React.useEffect(