Simplify the desktopCapturer code
This commit is contained in:
parent
f6c9000f5f
commit
836a8b1794
7 changed files with 38 additions and 66 deletions
|
@ -1,11 +1,20 @@
|
|||
{ipcRenderer, NativeImage} = require 'electron'
|
||||
{ipcRenderer, nativeImage} = require 'electron'
|
||||
|
||||
nextId = 0
|
||||
getNextId = -> ++nextId
|
||||
|
||||
# |options.type| can not be empty and has to include 'window' or 'screen'.
|
||||
isValid = (options) ->
|
||||
return options?.types? and Array.isArray options.types
|
||||
|
||||
exports.getSources = (options, callback) ->
|
||||
return callback new Error('Invalid options') unless isValid options
|
||||
|
||||
captureWindow = 'window' in options.types
|
||||
captureScreen = 'screen' in options.types
|
||||
options.thumbnailSize ?= width: 150, height: 150
|
||||
|
||||
id = getNextId()
|
||||
ipcRenderer.send 'ATOM_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', options, id
|
||||
ipcRenderer.once "ATOM_RENDERER_DESKTOP_CAPTURER_RESULT_#{id}", (error_message, sources) ->
|
||||
error = if error_message then Error error_message else null
|
||||
callback error, ({id: source.id, name: source.name, thumbnail: NativeImage.createFromDataUrl source.thumbnail} for source in sources)
|
||||
ipcRenderer.send 'ATOM_BROWSER_DESKTOP_CAPTURER_GET_SOURCES', captureWindow, captureScreen, options.thumbnailSize, id
|
||||
ipcRenderer.once "ATOM_RENDERER_DESKTOP_CAPTURER_RESULT_#{id}", (event, sources) ->
|
||||
callback null, ({id: source.id, name: source.name, thumbnail: nativeImage.createFromDataURL source.thumbnail} for source in sources)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue