2019-12-06 19:17:34 +01:00
|
|
|
/*
|
2024-09-06 18:56:18 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
Copyright 2018, 2019 , 2021 New Vector Ltd
|
2019-12-06 19:17:34 +01:00
|
|
|
|
2024-09-06 18:56:18 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-12-06 19:17:34 +01:00
|
|
|
*/
|
|
|
|
|
2024-10-30 19:06:03 +01:00
|
|
|
// This file is compiled to CommonJS rather than ESM otherwise the browser chokes on the import statement.
|
|
|
|
|
2022-12-15 12:00:58 +01:00
|
|
|
import { ipcRenderer, contextBridge, IpcRendererEvent } from "electron";
|
2019-12-06 19:17:34 +01:00
|
|
|
|
2021-01-13 16:21:00 +01:00
|
|
|
// Expose only expected IPC wrapper APIs to the renderer process to avoid
|
|
|
|
// handing out generalised messaging access.
|
2020-12-25 15:54:13 +01:00
|
|
|
|
2021-01-13 16:21:00 +01:00
|
|
|
const CHANNELS = [
|
|
|
|
"app_onAction",
|
|
|
|
"before-quit",
|
|
|
|
"check_updates",
|
|
|
|
"install_update",
|
|
|
|
"ipcCall",
|
|
|
|
"ipcReply",
|
|
|
|
"loudNotification",
|
|
|
|
"preferences",
|
|
|
|
"seshat",
|
|
|
|
"seshatReply",
|
|
|
|
"setBadgeCount",
|
|
|
|
"update-downloaded",
|
|
|
|
"userDownloadCompleted",
|
2022-01-10 12:35:23 +01:00
|
|
|
"userDownloadAction",
|
2023-07-14 12:09:12 +02:00
|
|
|
"openDesktopCapturerSourcePicker",
|
2024-07-10 15:41:27 +02:00
|
|
|
"userAccessToken",
|
2024-10-15 13:51:06 +02:00
|
|
|
"homeserverUrl",
|
2024-07-10 15:41:27 +02:00
|
|
|
"serverSupportedVersions",
|
2021-01-13 16:21:00 +01:00
|
|
|
];
|
|
|
|
|
2022-12-15 12:00:58 +01:00
|
|
|
contextBridge.exposeInMainWorld("electron", {
|
|
|
|
on(channel: string, listener: (event: IpcRendererEvent, ...args: any[]) => void): void {
|
|
|
|
if (!CHANNELS.includes(channel)) {
|
|
|
|
console.error(`Unknown IPC channel ${channel} ignored`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ipcRenderer.on(channel, listener);
|
2021-01-13 16:21:00 +01:00
|
|
|
},
|
2022-12-15 12:00:58 +01:00
|
|
|
send(channel: string, ...args: any[]): void {
|
|
|
|
if (!CHANNELS.includes(channel)) {
|
|
|
|
console.error(`Unknown IPC channel ${channel} ignored`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ipcRenderer.send(channel, ...args);
|
|
|
|
},
|
|
|
|
});
|