From 875a0f8bfde260e542c988128c10f0ea3f3d0a19 Mon Sep 17 00:00:00 2001 From: Claudio Costa Date: Mon, 29 Nov 2021 10:18:49 +0100 Subject: [PATCH] Expose native API call to get desktop screen sources (#1881) * Expose native API call to get screen sources * Move eslint line to the bottom --- src/main/preload/mattermost.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/preload/mattermost.js b/src/main/preload/mattermost.js index 8c0f4bda..cbb18728 100644 --- a/src/main/preload/mattermost.js +++ b/src/main/preload/mattermost.js @@ -6,7 +6,7 @@ /* eslint-disable no-magic-numbers */ -import {contextBridge, ipcRenderer, webFrame} from 'electron'; +import {contextBridge, ipcRenderer, webFrame, desktopCapturer} from 'electron'; // I've filed an issue in electron-log https://github.com/megahertz/electron-log/issues/267 // we'll be able to use it again if there is a workaround for the 'os' import @@ -262,4 +262,18 @@ window.addEventListener('storage', (e) => { } }); +contextBridge.exposeInMainWorld('desktopCapturer', { + getSources: async (options) => { + const sources = await desktopCapturer.getSources(options); + return sources.map((source) => { + return { + id: source.id, + name: source.name, + thumbnailURL: source.thumbnail.toDataURL(), + }; + }); + }, +}); + /* eslint-enable no-magic-numbers */ +