feat: add support for DesktopCapturerSource.appIcon
Useful to get the icon of the application owning the source. Only available for sources of type window, i.e. not for screen. https://github.com/electron/electron/issues/14845
This commit is contained in:
parent
77f73830e8
commit
1f55f1635f
7 changed files with 48 additions and 15 deletions
|
@ -11,19 +11,20 @@ let requestsQueue = []
|
|||
const electronSources = 'ELECTRON_BROWSER_DESKTOP_CAPTURER_GET_SOURCES'
|
||||
const capturerResult = (id) => `ELECTRON_RENDERER_DESKTOP_CAPTURER_RESULT_${id}`
|
||||
|
||||
ipcMain.on(electronSources, (event, captureWindow, captureScreen, thumbnailSize, id) => {
|
||||
ipcMain.on(electronSources, (event, captureWindow, captureScreen, thumbnailSize, fetchWindowIcons, id) => {
|
||||
const request = {
|
||||
id,
|
||||
options: {
|
||||
captureWindow,
|
||||
captureScreen,
|
||||
thumbnailSize
|
||||
thumbnailSize,
|
||||
fetchWindowIcons
|
||||
},
|
||||
webContents: event.sender
|
||||
}
|
||||
requestsQueue.push(request)
|
||||
if (requestsQueue.length === 1) {
|
||||
desktopCapturer.startHandling(captureWindow, captureScreen, thumbnailSize)
|
||||
desktopCapturer.startHandling(captureWindow, captureScreen, thumbnailSize, fetchWindowIcons)
|
||||
}
|
||||
|
||||
// If the WebContents is destroyed before receiving result, just remove the
|
||||
|
@ -33,7 +34,7 @@ ipcMain.on(electronSources, (event, captureWindow, captureScreen, thumbnailSize,
|
|||
})
|
||||
})
|
||||
|
||||
desktopCapturer.emit = (event, name, sources) => {
|
||||
desktopCapturer.emit = (event, name, sources, fetchWindowIcons) => {
|
||||
// Receiving sources result from main process, now send them back to renderer.
|
||||
const handledRequest = requestsQueue.shift()
|
||||
const handledWebContents = handledRequest.webContents
|
||||
|
@ -44,7 +45,8 @@ desktopCapturer.emit = (event, name, sources) => {
|
|||
id: source.id,
|
||||
name: source.name,
|
||||
thumbnail: source.thumbnail.toDataURL(),
|
||||
display_id: source.display_id
|
||||
display_id: source.display_id,
|
||||
appIcon: (fetchWindowIcons && source.appIcon) ? source.appIcon.toDataURL() : null
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -67,7 +69,7 @@ desktopCapturer.emit = (event, name, sources) => {
|
|||
|
||||
// If the requestsQueue is not empty, start a new request handling.
|
||||
if (requestsQueue.length > 0) {
|
||||
const { captureWindow, captureScreen, thumbnailSize } = requestsQueue[0].options
|
||||
return desktopCapturer.startHandling(captureWindow, captureScreen, thumbnailSize)
|
||||
const { captureWindow, captureScreen, thumbnailSize, fetchWindowIcons } = requestsQueue[0].options
|
||||
return desktopCapturer.startHandling(captureWindow, captureScreen, thumbnailSize, fetchWindowIcons)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue