Files
ThreadNet-Web/src/preload.cts
T

74 lines
2.3 KiB
TypeScript
Raw Normal View History

/*
2024-09-06 17:56:18 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2018, 2019 , 2021 New Vector Ltd
2025-01-17 11:44:49 +00:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-06 17:56:18 +01:00
Please see LICENSE files in the repository root for full details.
*/
2024-10-30 18:06:03 +00:00
// This file is compiled to CommonJS rather than ESM otherwise the browser chokes on the import statement.
2022-12-15 11:00:58 +00:00
import { ipcRenderer, contextBridge, IpcRendererEvent } from "electron";
// 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
const CHANNELS = [
"app_onAction",
"before-quit",
"check_updates",
"install_update",
"ipcCall",
"ipcReply",
"loudNotification",
"preferences",
"seshat",
"seshatReply",
"setBadgeCount",
"update-downloaded",
"userDownloadCompleted",
"userDownloadAction",
"openDesktopCapturerSourcePicker",
"userAccessToken",
2024-10-15 17:21:06 +05:30
"homeserverUrl",
"serverSupportedVersions",
];
2022-12-15 11:00:58 +00: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);
},
2022-12-15 11:00:58 +00:00
send(channel: string, ...args: any[]): void {
if (!CHANNELS.includes(channel)) {
console.error(`Unknown IPC channel ${channel} ignored`);
return;
}
ipcRenderer.send(channel, ...args);
},
async initialise(): Promise<{
protocol: string;
sessionId: string;
config: IConfigOptions;
supportedSettings: Record<string, boolean>;
}> {
const [{ protocol, sessionId }, config, supportedSettings] = await Promise.all([
ipcRenderer.invoke("getProtocol"),
ipcRenderer.invoke("getConfig"),
ipcRenderer.invoke("getSupportedSettings"),
]);
return { protocol, sessionId, config, supportedSettings };
},
async setSettingValue(settingName: string, value: any): Promise<void> {
return ipcRenderer.invoke("setSettingValue", settingName, value);
},
async getSettingValue(settingName: string): Promise<any> {
return ipcRenderer.invoke("getSettingValue", settingName);
},
2022-12-15 11:00:58 +00:00
});