Create polished demo videos without editing skills. Mac/Windows/Linux
Match the selected macOS microphone despite Chromium's label suffix
sourabhxyze029d11663d4
diff --git a/electron/native/ScreenCaptureKitRecorder.swift b/electron/native/ScreenCaptureKitRecorder.swiftindex 707813a0..c2c2d075 100644--- a/electron/native/ScreenCaptureKitRecorder.swift+++ b/electron/native/ScreenCaptureKitRecorder.swift@@ -858,8 +858,10 @@ final class ScreenCaptureRecorder: NSObject, SCStreamOutput, SCStreamDelegate {let audioDevices = AVCaptureDevice.devices(for: .audio)if let microphoneLabel = config.microphoneLabel?.trimmingCharacters(in: .whitespacesAndNewlines), !microphoneLabel.isEmpty {- if let matchedDevice = audioDevices.first(where: { $0.localizedName == microphoneLabel }) {- return matchedDevice.uniqueID+ for candidateName in microphoneNameCandidates(forLabel: microphoneLabel) {+ if let matchedDevice = audioDevices.first(where: { $0.localizedName == candidateName }) {+ return matchedDevice.uniqueID+ }}}@@ -872,6 +874,22 @@ final class ScreenCaptureRecorder: NSObject, SCStreamOutput, SCStreamDelegate {return nil}+ /// The label comes from Chromium's `enumerateDevices()`, which appends a+ /// transport suffix to the CoreAudio name — "Shure MV7 (14ed:1012)",+ /// "MacBook Pro Microphone (Built-in)", "BlackHole 16ch (Virtual)" — so it+ /// rarely equals `localizedName` as-is. Without the undecorated candidate the+ /// selection is silently ignored and the system default input is recorded.+ private static func microphoneNameCandidates(forLabel label: String) -> [String] {+ var candidates = [label]+ if label.hasSuffix(")"), let suffixStart = label.range(of: " (", options: .backwards) {+ let undecoratedName = label[..<suffixStart.lowerBound].trimmingCharacters(in: .whitespaces)+ if !undecoratedName.isEmpty {+ candidates.append(undecoratedName)+ }+ }+ return candidates+ }+private func supportsNativeMicrophoneCapture(streamConfig: SCStreamConfiguration) -> Bool {let supportsConfigSelector = streamConfig.responds(to: Selector(("setCaptureMicrophone:")))let supportsDeviceSelector = streamConfig.responds(to: Selector(("setMicrophoneCaptureDeviceID:")))diff --git a/electron/native/ScreenCaptureKitRecorder.test.ts b/electron/native/ScreenCaptureKitRecorder.test.tsindex edaba7ee..e96a96a7 100644--- a/electron/native/ScreenCaptureKitRecorder.test.ts+++ b/electron/native/ScreenCaptureKitRecorder.test.ts@@ -117,3 +117,23 @@ describe("ScreenCaptureKitRecorder first frame timing", () => {expect(audioGuard).toBeLessThan(callback.indexOf("if outputType == .audio"));});});++describe("ScreenCaptureKitRecorder microphone selection", () => {+ const resolver = recorderSource.slice(+ recorderSource.indexOf("private static func resolveMicrophoneCaptureDeviceID"),+ recorderSource.indexOf("private func supportsNativeMicrophoneCapture"),+ );++ it("matches the selected microphone by its undecorated Chromium label", () => {+ // Chromium reports "Shure MV7 (14ed:1012)"; CoreAudio names it "Shure MV7".+ expect(resolver).toContain(+ "for candidateName in microphoneNameCandidates(forLabel: microphoneLabel)",+ );+ expect(resolver).toContain("$0.localizedName == candidateName");+ expect(resolver).toContain('label.range(of: " (", options: .backwards)');+ });++ it("prefers the raw label so device names ending in parentheses still match", () => {+ expect(resolver).toContain("var candidates = [label]");+ });+});