|
@@ -17,6 +17,16 @@ function isValid (options) {
|
|
|
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 = function (options, callback) {
|
|
|
if (!isValid(options)) return callback(new Error('Invalid options'))
|
|
|
const captureWindow = includes.call(options.types, 'window')
|
|
@@ -35,18 +45,10 @@ exports.getSources = function (options, callback) {
|
|
|
const id = incrementId()
|
|
|
ipcRenderer.send('ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, options.thumbnailSize, options.fetchWindowIcons, id)
|
|
|
return ipcRenderer.once(`ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_${id}`, (event, sources) => {
|
|
|
- callback(null, (() => {
|
|
|
- const results = []
|
|
|
- sources.forEach(source => {
|
|
|
- results.push({
|
|
|
- id: source.id,
|
|
|
- name: source.name,
|
|
|
- thumbnail: nativeImage.createFromDataURL(source.thumbnail),
|
|
|
- display_id: source.display_id,
|
|
|
- appIcon: source.appIcon ? nativeImage.createFromDataURL(source.appIcon) : null
|
|
|
- })
|
|
|
- })
|
|
|
- return results
|
|
|
- })())
|
|
|
+ try {
|
|
|
+ callback(null, mapSources(sources))
|
|
|
+ } catch (error) {
|
|
|
+ callback(error)
|
|
|
+ }
|
|
|
})
|
|
|
}
|