Page MenuHomePhorge

D9970.1768793712.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D9970.1768793712.diff

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<any>) => void,
+ listener: (event: IpcMainEvent, ...args: $ReadOnlyArray<any>) => 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
@@ -225,6 +225,15 @@
return win;
};
+const sendDeviceTokenToWebApp = async () => {
+ if (!mainWindow) {
+ return;
+ }
+
+ const token = await registerForNotifications();
+ mainWindow?.webContents.send('on-device-token-registered', token);
+};
+
const show = (urlPath?: string) => {
const splash = createSplashWindow();
const error = createErrorWindow();
@@ -262,10 +271,7 @@
main.show();
if (app.isPackaged) {
- (async () => {
- const token = await registerForNotifications();
- main.webContents.send('on-device-token-registered', token);
- })();
+ sendDeviceTokenToWebApp();
}
}
});
@@ -291,6 +297,7 @@
} catch (error) {
console.error(error);
}
+
listenForNotifications(threadID => {
if (mainWindow) {
mainWindow.webContents.send('on-notification-clicked', {
@@ -300,6 +307,7 @@
show(`chat/thread/${threadID}/`);
}
});
+ ipcMain.on('fetch-device-token', sendDeviceTokenToWebApp);
}
ipcMain.on('set-badge', (event, value) => {
diff --git a/desktop/src/preload.js b/desktop/src/preload.js
--- a/desktop/src/preload.js
+++ b/desktop/src/preload.js
@@ -40,6 +40,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(

File Metadata

Mime Type
text/plain
Expires
Mon, Jan 19, 3:35 AM (13 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5954150
Default Alt Text
D9970.1768793712.diff (2 KB)

Event Timeline