electron/atom/renderer/api/lib/desktop-capturer.coffee

21 lines
858 B
CoffeeScript
Raw Normal View History

2015-12-08 05:49:26 +00:00
{ipcRenderer, nativeImage} = require 'electron'
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
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)