From fcfbcbc7e1e9f0cf92df8b66463bf5ed299503b0 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Fri, 17 Feb 2023 23:29:36 +0100 Subject: [PATCH] test: move desktopCapturer usage from renderer to main in ts-smoke (#37321) --- spec/ts-smoke/electron/main.ts | 13 ++++++++----- spec/ts-smoke/electron/renderer.ts | 16 +++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/ts-smoke/electron/main.ts b/spec/ts-smoke/electron/main.ts index 4e5ee99c5082..09519f83c210 100644 --- a/spec/ts-smoke/electron/main.ts +++ b/spec/ts-smoke/electron/main.ts @@ -4,6 +4,7 @@ import { BrowserWindow, contentTracing, dialog, + desktopCapturer, globalShortcut, ipcMain, Menu, @@ -13,17 +14,14 @@ import { powerSaveBlocker, protocol, Tray, - clipboard, - crashReporter, - nativeImage, screen, - shell, session, systemPreferences, webContents, TouchBar -} from 'electron'; +} from 'electron/main'; +import { clipboard, crashReporter, nativeImage, shell } from 'electron/common'; import * as path from 'path'; // Quick start @@ -508,6 +506,11 @@ dialog.showOpenDialog(win3, { console.log(ret); }); +// desktopCapturer +// https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md + +ipcMain.handle('get-sources', (event, options) => desktopCapturer.getSources(options)); + // global-shortcut // https://github.com/electron/electron/blob/main/docs/api/global-shortcut.md diff --git a/spec/ts-smoke/electron/renderer.ts b/spec/ts-smoke/electron/renderer.ts index 9ba7a0486835..8fc55790d04d 100644 --- a/spec/ts-smoke/electron/renderer.ts +++ b/spec/ts-smoke/electron/renderer.ts @@ -1,12 +1,6 @@ -import { - desktopCapturer, - ipcRenderer, - webFrame, - clipboard, - crashReporter, - shell -} from 'electron'; +import { ipcRenderer, webFrame } from 'electron/renderer'; +import { clipboard, crashReporter, shell } from 'electron/common'; // In renderer process (web page). // https://github.com/electron/electron/blob/main/docs/api/ipc-renderer.md @@ -79,7 +73,7 @@ crashReporter.start({ // desktopCapturer // https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md -desktopCapturer.getSources({ types: ['window', 'screen'] }).then(sources => { +getSources({ types: ['window', 'screen'] }).then(sources => { for (let i = 0; i < sources.length; ++i) { if (sources[i].name === 'Electron') { (navigator as any).webkitGetUserMedia({ @@ -100,6 +94,10 @@ desktopCapturer.getSources({ types: ['window', 'screen'] }).then(sources => { } }); +function getSources (options: Electron.SourcesOptions) { + return ipcRenderer.invoke('get-sources', options) as Promise; +} + function gotStream (stream: any) { (document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream); }