2019-12-06 19:17:34 +01:00
|
|
|
/*
|
2021-01-13 16:21:00 +01:00
|
|
|
Copyright 2018, 2019, 2021 New Vector Ltd
|
2019-12-06 19:17:34 +01:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-07-01 10:11:42 +02:00
|
|
|
import { ipcRenderer, desktopCapturer, contextBridge, IpcRendererEvent, SourcesOptions } 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",
|
|
|
|
"userDownloadOpen",
|
|
|
|
];
|
|
|
|
|
|
|
|
contextBridge.exposeInMainWorld(
|
|
|
|
"electron",
|
|
|
|
{
|
2021-07-01 10:11:42 +02:00
|
|
|
on(channel: string, listener: (event: IpcRendererEvent, ...args: any[]) => void) {
|
2021-01-13 16:21:00 +01:00
|
|
|
if (!CHANNELS.includes(channel)) {
|
|
|
|
console.error(`Unknown IPC channel ${channel} ignored`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ipcRenderer.on(channel, listener);
|
|
|
|
},
|
2021-07-01 10:11:42 +02:00
|
|
|
send(channel: string, ...args: any[]) {
|
2021-01-13 16:21:00 +01:00
|
|
|
if (!CHANNELS.includes(channel)) {
|
|
|
|
console.error(`Unknown IPC channel ${channel} ignored`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ipcRenderer.send(channel, ...args);
|
|
|
|
},
|
2021-07-01 10:11:42 +02:00
|
|
|
async getDesktopCapturerSources(options: SourcesOptions) {
|
2021-01-14 08:31:52 +01:00
|
|
|
const sources = await desktopCapturer.getSources(options);
|
|
|
|
const desktopCapturerSources = [];
|
|
|
|
|
|
|
|
for (const source of sources) {
|
|
|
|
desktopCapturerSources.push({
|
|
|
|
id: source.id,
|
|
|
|
name: source.name,
|
|
|
|
thumbnailURL: source.thumbnail.toDataURL(),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return desktopCapturerSources;
|
|
|
|
},
|
2021-01-13 16:21:00 +01:00
|
|
|
},
|
|
|
|
);
|