diff options
author | 2022-04-29 13:38:19 +0200 | |
---|---|---|
committer | 2022-04-29 07:57:25 -0500 | |
commit | f6d086bc3da5312c7eeb9fa6834312ede795d1dc (patch) | |
tree | 8553f94693750b39d28d648cc0f2e9ffcb954c8f | |
parent | Update submodules, browserslist data updates and linter fixes [skip ci] (diff) | |
download | ferdium-app-f6d086bc3da5312c7eeb9fa6834312ede795d1dc.tar.gz ferdium-app-f6d086bc3da5312c7eeb9fa6834312ede795d1dc.tar.zst ferdium-app-f6d086bc3da5312c7eeb9fa6834312ede795d1dc.zip |
fix: desktopCapturer in electron 17+ (fixes #59)
Since electron 17, desktopCapturer is only available in the main
process:
https://www.electronjs.org/blog/electron-17-0#desktopcapturergetsources-in-the-renderer
This patch adds a new IPC message from the service renderer to the main
process so it can still invoke desktopCapturer.getSources
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
-rw-r--r-- | src/index.ts | 6 | ||||
-rw-r--r-- | src/webview/screenshare.ts | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/index.ts b/src/index.ts index ef9d5bd72..59a90a3cb 100644 --- a/src/index.ts +++ b/src/index.ts | |||
@@ -7,6 +7,7 @@ import { | |||
7 | ipcMain, | 7 | ipcMain, |
8 | session, | 8 | session, |
9 | dialog, | 9 | dialog, |
10 | desktopCapturer, | ||
10 | } from 'electron'; | 11 | } from 'electron'; |
11 | 12 | ||
12 | import { emptyDirSync, ensureFileSync } from 'fs-extra'; | 13 | import { emptyDirSync, ensureFileSync } from 'fs-extra'; |
@@ -632,6 +633,11 @@ ipcMain.on('set-spellchecker-locales', (_e, { locale, serviceId }) => { | |||
632 | serviceSession.setSpellCheckerLanguages(locales); | 633 | serviceSession.setSpellCheckerLanguages(locales); |
633 | }); | 634 | }); |
634 | 635 | ||
636 | |||
637 | ipcMain.handle('get-desktop-capturer-sources', () => desktopCapturer.getSources({ | ||
638 | types: ['screen', 'window'], | ||
639 | })); | ||
640 | |||
635 | ipcMain.on('window.toolbar-double-clicked', () => { | 641 | ipcMain.on('window.toolbar-double-clicked', () => { |
636 | mainWindow?.isMaximized() ? mainWindow.unmaximize() : mainWindow?.maximize(); | 642 | mainWindow?.isMaximized() ? mainWindow.unmaximize() : mainWindow?.maximize(); |
637 | }); | 643 | }); |
diff --git a/src/webview/screenshare.ts b/src/webview/screenshare.ts index dbc23d62c..e631ce52f 100644 --- a/src/webview/screenshare.ts +++ b/src/webview/screenshare.ts | |||
@@ -1,11 +1,9 @@ | |||
1 | import { desktopCapturer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | 2 | ||
3 | const CANCEL_ID = 'desktop-capturer-selection__cancel'; | 3 | const CANCEL_ID = 'desktop-capturer-selection__cancel'; |
4 | 4 | ||
5 | export async function getDisplayMediaSelector() { | 5 | export async function getDisplayMediaSelector() { |
6 | const sources = await desktopCapturer.getSources({ | 6 | const sources = await ipcRenderer.invoke('get-desktop-capturer-sources'); |
7 | types: ['screen', 'window'], | ||
8 | }); | ||
9 | return `<div class="desktop-capturer-selection__scroller"> | 7 | return `<div class="desktop-capturer-selection__scroller"> |
10 | <ul class="desktop-capturer-selection__list"> | 8 | <ul class="desktop-capturer-selection__list"> |
11 | ${sources | 9 | ${sources |