d87b3ead76
* chore: remove promisification deprecation callbacks * update docs * fix smoke test * fix executejs issue * cleanup leftovers * fix webContents.executeJavaScript tests * cleanup WebContents.prototype.takeHeapSnapshot * fix "sets arbitrary webContents as devtools" test * fix executeJavaScriptInFrame related tests
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
const { nativeImage, deprecate } = require('electron')
|
|
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils')
|
|
|
|
// |options.types| can't be empty and must be an array
|
|
function isValid (options) {
|
|
const types = options ? options.types : undefined
|
|
return Array.isArray(types)
|
|
}
|
|
|
|
function mapSources (sources) {
|
|
return sources.map(source => ({
|
|
id: source.id,
|
|
name: source.name,
|
|
thumbnail: nativeImage.createFromDataURL(source.thumbnail),
|
|
display_id: source.display_id,
|
|
appIcon: source.appIcon ? nativeImage.createFromDataURL(source.appIcon) : null
|
|
}))
|
|
}
|
|
|
|
exports.getSources = (options) => {
|
|
return new Promise((resolve, reject) => {
|
|
if (!isValid(options)) throw new Error('Invalid options')
|
|
|
|
const captureWindow = options.types.includes('window')
|
|
const captureScreen = options.types.includes('screen')
|
|
|
|
if (options.thumbnailSize == null) {
|
|
options.thumbnailSize = {
|
|
width: 150,
|
|
height: 150
|
|
}
|
|
}
|
|
if (options.fetchWindowIcons == null) {
|
|
options.fetchWindowIcons = false
|
|
}
|
|
|
|
ipcRendererUtils.invoke('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, options.thumbnailSize, options.fetchWindowIcons)
|
|
.then(sources => resolve(mapSources(sources)), reject)
|
|
})
|
|
}
|