test: move desktopCapturer usage from renderer to main in ts-smoke (#37321)
This commit is contained in:
parent
e34cc6f48c
commit
fcfbcbc7e1
2 changed files with 15 additions and 14 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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<Electron.DesktopCapturerSource[]>;
|
||||
}
|
||||
|
||||
function gotStream (stream: any) {
|
||||
(document.querySelector('video') as HTMLVideoElement).src = URL.createObjectURL(stream);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue