2015-12-08 05:49:26 +00:00
|
|
|
{ipcRenderer, nativeImage} = require 'electron'
|
2015-10-04 01:35:00 +00:00
|
|
|
|
2015-10-19 10:07:35 +00:00
|
|
|
nextId = 0
|
|
|
|
getNextId = -> ++nextId
|
|
|
|
|
2015-12-08 05:49:26 +00:00
|
|
|
# |options.type| can not be empty and has to include 'window' or 'screen'.
|
|
|
|
isValid = (options) ->
|
|
|
|
return options?.types? and Array.isArray options.types
|
|
|
|
|
2015-12-08 04:58:39 +00:00
|
|
|
exports.getSources = (options, callback) ->
|
2015-12-08 05:49:26 +00:00
|
|
|
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
|
|
|
|
|
2015-10-19 10:07:35 +00:00
|
|
|
id = getNextId()
|
2015-12-08 05:49:26 +00:00
|
|
|
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)
|