test: move desktopCapturer usage from renderer to main in ts-smoke (#37321)

This commit is contained in:
Milan Burda 2023-02-17 23:29:36 +01:00 committed by GitHub
parent e34cc6f48c
commit fcfbcbc7e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View file

@ -4,6 +4,7 @@ import {
BrowserWindow, BrowserWindow,
contentTracing, contentTracing,
dialog, dialog,
desktopCapturer,
globalShortcut, globalShortcut,
ipcMain, ipcMain,
Menu, Menu,
@ -13,17 +14,14 @@ import {
powerSaveBlocker, powerSaveBlocker,
protocol, protocol,
Tray, Tray,
clipboard,
crashReporter,
nativeImage,
screen, screen,
shell,
session, session,
systemPreferences, systemPreferences,
webContents, webContents,
TouchBar TouchBar
} from 'electron'; } from 'electron/main';
import { clipboard, crashReporter, nativeImage, shell } from 'electron/common';
import * as path from 'path'; import * as path from 'path';
// Quick start // Quick start
@ -508,6 +506,11 @@ dialog.showOpenDialog(win3, {
console.log(ret); 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 // global-shortcut
// https://github.com/electron/electron/blob/main/docs/api/global-shortcut.md // https://github.com/electron/electron/blob/main/docs/api/global-shortcut.md

View file

@ -1,12 +1,6 @@
import { import { ipcRenderer, webFrame } from 'electron/renderer';
desktopCapturer, import { clipboard, crashReporter, shell } from 'electron/common';
ipcRenderer,
webFrame,
clipboard,
crashReporter,
shell
} from 'electron';
// In renderer process (web page). // In renderer process (web page).
// https://github.com/electron/electron/blob/main/docs/api/ipc-renderer.md // https://github.com/electron/electron/blob/main/docs/api/ipc-renderer.md
@ -79,7 +73,7 @@ crashReporter.start({
// desktopCapturer // desktopCapturer
// https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md // 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) { for (let i = 0; i < sources.length; ++i) {
if (sources[i].name === 'Electron') { if (sources[i].name === 'Electron') {
(navigator as any).webkitGetUserMedia({ (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<Electron.DesktopCapturerSource[]>;
}
function gotStream (stream: any) { function gotStream (stream: any) {
(document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream); (document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream);
} }