This commit is contained in:
Erick Zhao 2024-08-12 12:29:26 -07:00
Родитель 1d480ad23d
Коммит a17823663c
Не найден ключ, соответствующий данной подписи
1 изменённых файлов: 10 добавлений и 12 удалений

Просмотреть файл

@ -18,7 +18,7 @@ export async function getSources (args: Electron.SourcesOptions) {
if (!isValid(args)) throw new Error('Invalid options'); if (!isValid(args)) throw new Error('Invalid options');
const resizableValues = new Map(); const resizableValues = new Map();
let winsOwnedByElectronProcess: ElectronInternal.GetSourcesResult[]; let winsOwnedByElectronProcess: Promise<ElectronInternal.GetSourcesResult[]>;
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
// Fix for bug in ScreenCaptureKit that modifies a window's styleMask the first time // Fix for bug in ScreenCaptureKit that modifies a window's styleMask the first time
// it captures a non-resizable window. We record each non-resizable window's styleMask, // it captures a non-resizable window. We record each non-resizable window's styleMask,
@ -52,7 +52,7 @@ export async function getSources (args: Electron.SourcesOptions) {
const getSources = new Promise<ElectronInternal.GetSourcesResult[]>((resolve, reject) => { const getSources = new Promise<ElectronInternal.GetSourcesResult[]>((resolve, reject) => {
let capturer: ElectronInternal.DesktopCapturer | null = createDesktopCapturer(); let capturer: ElectronInternal.DesktopCapturer | null = createDesktopCapturer();
const stopRunning = async () => { const stopRunning = () => {
if (capturer) { if (capturer) {
delete capturer._onerror; delete capturer._onerror;
delete capturer._onfinished; delete capturer._onfinished;
@ -84,25 +84,23 @@ export async function getSources (args: Electron.SourcesOptions) {
appIcon: null appIcon: null
}; };
}); });
winsOwnedByElectronProcess = await Promise.all(fetches); winsOwnedByElectronProcess = Promise.all(fetches);
}; };
} }
// Remove from currentlyRunning once we resolve or reject // Remove from currentlyRunning once we resolve or reject
currentlyRunning = currentlyRunning.filter(running => running.options !== options); currentlyRunning = currentlyRunning.filter(running => running.options !== options);
}; };
capturer._onerror = async (error: string) => { capturer._onerror = (error: string) => {
await stopRunning(); stopRunning();
reject(error); reject(error);
}; };
capturer._onfinished = async (sources: Electron.DesktopCapturerSource[]) => { capturer._onfinished = (sources: Electron.DesktopCapturerSource[]) => {
await stopRunning(); stopRunning();
if (Array.isArray(winsOwnedByElectronProcess)) { winsOwnedByElectronProcess.then((wins) => {
resolve([...sources, ...winsOwnedByElectronProcess]); resolve([...sources, ...wins]);
} else { });
resolve(sources);
}
}; };
capturer.startHandling(captureWindow, captureScreen, thumbnailSize, fetchWindowIcons); capturer.startHandling(captureWindow, captureScreen, thumbnailSize, fetchWindowIcons);