Switch to IPC channel for getDesktopCapturerSources (#320)

This commit is contained in:
Šimon Brandner 2022-02-11 11:38:19 +01:00 committed by GitHub
parent a80bc76e22
commit 634c5c66a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 22 deletions

View file

@ -19,7 +19,17 @@ limitations under the License.
// Squirrel on windows starts the app with various flags as hooks to tell us when we've been installed/uninstalled etc.
import "./squirrelhooks";
import { app, ipcMain, powerSaveBlocker, BrowserWindow, Menu, autoUpdater, protocol, dialog } from "electron";
import {
app,
ipcMain,
powerSaveBlocker,
BrowserWindow,
Menu,
autoUpdater,
protocol,
dialog,
desktopCapturer,
} from "electron";
import AutoLaunch from "auto-launch";
import path from "path";
import windowStateKeeper from 'electron-window-state';
@ -502,6 +512,13 @@ ipcMain.on('ipcCall', async function(ev, payload) {
await keytar.deletePassword("riot.im", `${args[0]}|${args[1]}`);
} catch (e) {}
break;
case 'getDesktopCapturerSources':
ret = (await desktopCapturer.getSources(args[0])).map((source) => ({
id: source.id,
name: source.name,
thumbnailURL: source.thumbnail.toDataURL(),
}));
break;
default:
mainWindow.webContents.send('ipcReply', {

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { ipcRenderer, desktopCapturer, contextBridge, IpcRendererEvent, SourcesOptions } from 'electron';
import { ipcRenderer, contextBridge, IpcRendererEvent } from 'electron';
// Expose only expected IPC wrapper APIs to the renderer process to avoid
// handing out generalised messaging access.
@ -36,12 +36,6 @@ const CHANNELS = [
"userDownloadAction",
];
interface ISource {
id: string;
name: string;
thumbnailURL: string;
}
contextBridge.exposeInMainWorld(
"electron",
{
@ -59,19 +53,5 @@ contextBridge.exposeInMainWorld(
}
ipcRenderer.send(channel, ...args);
},
async getDesktopCapturerSources(options: SourcesOptions): Promise<ISource[]> {
const sources = await desktopCapturer.getSources(options);
const desktopCapturerSources: ISource[] = [];
for (const source of sources) {
desktopCapturerSources.push({
id: source.id,
name: source.name,
thumbnailURL: source.thumbnail.toDataURL(),
});
}
return desktopCapturerSources;
},
},
);