fix: free screen and window capturers immediately after we're finished with them (#20156)
fix #17937, #19908
This commit is contained in:
parent
42999f42f2
commit
d2a94e6b13
2 changed files with 9 additions and 7 deletions
|
@ -19,7 +19,13 @@ export const getSources = (event: Electron.IpcMainEvent, options: ElectronIntern
|
|||
}
|
||||
|
||||
const getSources = new Promise<ElectronInternal.GetSourcesResult[]>((resolve, reject) => {
|
||||
let capturer: ElectronInternal.DesktopCapturer | null = createDesktopCapturer()
|
||||
|
||||
const stopRunning = () => {
|
||||
if (capturer) {
|
||||
capturer.emit = null
|
||||
capturer = null
|
||||
}
|
||||
// Remove from currentlyRunning once we resolve or reject
|
||||
currentlyRunning = currentlyRunning.filter(running => running.options !== options)
|
||||
}
|
||||
|
@ -42,19 +48,13 @@ export const getSources = (event: Electron.IpcMainEvent, options: ElectronIntern
|
|||
})))
|
||||
})
|
||||
|
||||
let capturer: ElectronInternal.DesktopCapturer | null = createDesktopCapturer()
|
||||
|
||||
capturer.emit = emitter.emit.bind(emitter)
|
||||
capturer.startHandling(options.captureWindow, options.captureScreen, options.thumbnailSize, options.fetchWindowIcons)
|
||||
|
||||
// If the WebContents is destroyed before receiving result, just remove the
|
||||
// reference to emit and the capturer itself so that it never dispatches
|
||||
// back to the renderer
|
||||
event.sender.once('destroyed', () => {
|
||||
capturer!.emit = null
|
||||
capturer = null
|
||||
stopRunning()
|
||||
})
|
||||
event.sender.once('destroyed', () => stopRunning())
|
||||
})
|
||||
|
||||
currentlyRunning.push({
|
||||
|
|
|
@ -144,6 +144,7 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
|
|||
}
|
||||
std::move(window_sources.begin(), window_sources.end(),
|
||||
std::back_inserter(captured_sources_));
|
||||
window_capturer_.reset();
|
||||
}
|
||||
|
||||
if (capture_screen_ &&
|
||||
|
@ -194,6 +195,7 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) {
|
|||
// individual screen support is added.
|
||||
std::move(screen_sources.begin(), screen_sources.end(),
|
||||
std::back_inserter(captured_sources_));
|
||||
screen_capturer_.reset();
|
||||
}
|
||||
|
||||
if (!capture_window_ && !capture_screen_)
|
||||
|
|
Loading…
Add table
Reference in a new issue