知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
fix: Cicada no longer quits now and then when the menu bar panel opens
wquguru9d3286eba8ba
diff --git a/Sources/Cicada/Shortcuts.swift b/Sources/Cicada/Shortcuts.swiftindex e1d430e..317d115 100644--- a/Sources/Cicada/Shortcuts.swift+++ b/Sources/Cicada/Shortcuts.swift@@ -62,10 +62,25 @@ struct Shortcut: Equatable {kVK_Home: "↖", kVK_End: "↘", kVK_PageUp: "⇞", kVK_PageDown: "⇟", kVK_RightOption: L("右 ⌥"),]+ /// Names worked out on the main thread. SwiftUI sometimes builds the panel off it, and the+ /// input-source calls assert the main queue there (a crash since 1.4.0): off it, the last name.+ private static let nameLock = NSLock()+ nonisolated(unsafe) private static var names: [Int: String] = [:]+/// The character the key types on the current layout (US letters on non-Latin layouts).static func keyName(_ code: Int) -> String {if let f = functionKeys[code] { return f }if let n = named[code] { return n }+ guard Thread.isMainThread else {+ nameLock.lock(); defer { nameLock.unlock() }+ return names[code] ?? "#\(code)"+ }+ let name = layoutName(code)+ nameLock.lock(); names[code] = name; nameLock.unlock()+ return name+ }++ private static func layoutName(_ code: Int) -> String {guard let source = TISCopyCurrentASCIICapableKeyboardLayoutInputSource()?.takeRetainedValue(),let ptr = TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData) else { return "#\(code)" }let data = Unmanaged<CFData>.fromOpaque(ptr).takeUnretainedValue() as Data