fix(capture): stabilize platform source handling

This commit is contained in:
wiiiii123
2026-05-26 23:12:01 +07:00
parent 73bd4f11f5
commit 31d1022fef
6 changed files with 167 additions and 19 deletions
+11
View File
@@ -4,6 +4,7 @@ import {
createProcessedMicrophoneConstraints,
normalizeBrowserMicrophoneProfile,
resolveBrowserCaptureCursorPolicy,
shouldUseNativeWindowsCaptureForSource,
} from "./useScreenRecorder";
type RecordingState = "inactive" | "recording" | "paused";
@@ -129,6 +130,16 @@ describe("resolveBrowserCaptureCursorPolicy", () => {
});
});
describe("shouldUseNativeWindowsCaptureForSource", () => {
it("keeps native Windows capture on screen sources", () => {
expect(shouldUseNativeWindowsCaptureForSource({ id: "screen:101:0" })).toBe(true);
});
it("routes window sources through browser capture", () => {
expect(shouldUseNativeWindowsCaptureForSource({ id: "window:123456:0" })).toBe(false);
});
});
function stopRecording(
recorder: ReturnType<typeof createMockMediaRecorder>,
isNativeRecording: boolean,
+7 -2
View File
@@ -211,6 +211,12 @@ export function resolveBrowserCaptureCursorPolicy({
};
}
export function shouldUseNativeWindowsCaptureForSource(
source: Pick<ProcessedDesktopSource, "id"> | null | undefined,
): boolean {
return source?.id?.startsWith("screen:") === true;
}
export function createProcessedMicrophoneConstraints(
microphoneDeviceId?: string,
profile: BrowserMicrophoneProfile = DEFAULT_BROWSER_MICROPHONE_PROFILE,
@@ -1362,8 +1368,7 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
let nativeWindowsCaptureStartFailed = false;
if (
platform === "win32" &&
(selectedSource.id?.startsWith("screen:") ||
selectedSource.id?.startsWith("window:")) &&
shouldUseNativeWindowsCaptureForSource(selectedSource) &&
typeof window.electronAPI.isNativeWindowsCaptureAvailable === "function"
) {
try {