知了 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: keep the notes window from activating the app and pulling other windows forward
wquguruf5efa3070c48
diff --git a/AGENTS.md b/AGENTS.mdindex 2faebcd..dac6621 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -13,7 +13,7 @@ Live Subs is a macOS menu bar app that turns whatever the Mac is playing (stream- AI (Ling, ant-ling.com, OpenAI-compatible): one user key for the whole app, for now in a 0600 file `ling-api-key` in the app's Application Support folder, excluded from backups (`AIKey`; never in UserDefaults, logs or exports; ad-hoc signing makes the Keychain ask for the password after every rebuild or update, so it moves back to the Keychain once builds have a Developer ID; a key in the old Keychain item, service = bundle id + `.ai`, is moved over once), checked with a one-token `Ling-3.0-tiny` call. `LingClient` is the single gate for every call: request *starts* ≥ 0.6 s apart (the account allows ~2 requests/s across all models), waiting requests ordered speak-back > translation > notes; notes retry 429 with 1/2/4/8 s backoff, translation and speak-back fail fast to the next translator; 401 marks the key invalid. Every call sends `thinking: disabled`, puts the content in the **system** message and a fixed instruction in the user message (otherwise question-like text gets a search-grounded essay instead), and drops replies with no `finish_reason` or starting 根据现有检索证据.- Live notes (`NotesEngine`, UI-free): about every 45 s with new lines, one JSON call sends the current notes + new lines (`[L12 02:03 对方] …`) and gets the whole notes back (summary, ≤ 8 topics with points and an optional fishbone, conclusions/to-dos with evidence line ids → support counts, terms with misrecognised forms); a bad reply never replaces good notes. A final pass over the whole transcript runs when the meeting ends ("完整版"). Notes are written in Chinese when Chinese is among the system languages. Stored as `notes` in `session.json`; finished meetings without notes can generate them from the main window. Speak-back voices (`Voices.swift`, settings UI `VoicePicker.swift` on the 同声传译 page): one choice per room language (`speakVoices`, "en" → `ming:US_Emma` / `system:<AVSpeechSynthesisVoice id>` / `clone`). Offered: hand-picked Ming voices (English Emma/George/Charlotte; Chinese 小雅/小棠/小锋/卓然; ja/ko/de/fr/es via Emma/George with `language_id`) and the Mac's best female and male voice; default is Ming's first with a key, else the Mac's. `clone` is the user's own voice: a 8–30 s recording read from a passage in their language (16 kHz WAV + its on-device transcript in `voice/` under Application Support, 0600, out of backups), sent to Ming as `references` with every sentence (~600 KB, first audio ~3 s, ~8 s on a cold call; a foreign language keeps the speaker's accent). Ming's voices fall back to the Mac's voice without a usable key or when the stream fails; previews play on the default output, not the room.0-tts-0.5B`, SSE PCM 24 kHz) through the same key, falling back to the system voice.- Live notes window (`NotesWindow`): a floating `NSPanel`, `sharingType = .none` (invisible to screen sharing and screenshots), on all Spaces, frame autosaved; < 360 px a card that offers what the notes added since it was collapsed ("收起后新增 …", only when there is something), tabs 纪要 / 文字记录 in between, both side by side from 760 px; banners for no key (inline key entry) / invalid key / rate limited. While writing: sound bars before anyone speaks, a spinner with "已听到 N 句" and shimmering placeholders for the first version, an "正在更新" pill and a warm shimmer under the current topic for later updates (`TimelineView`, since the window redraws every second). Transcript: oldest first, follows the newest line plus the sentence still being spoken; scrolling up pauses following and gathers new lines into a "↓ N 句新内容" button; search highlights in place (query plus the notes' misheard forms of a name). Notes carry times: points and conclusions get the time of their first evidence line (`pointTimes`, `NoteItem.t`; carried over when the model echoes a point without evidence), topics show ranges.-- App menu (`AppMenu`): the app is a regular app (name and menus top left, Dock, ⌘Tab) while any of its windows is visible, the notes window included, and an accessory otherwise (`AppDelegate.updateActivationPolicy`; never activates on its own, so the notes window appearing doesn't take focus). Menus: app, 纪要, 显示 (display mode, ⌘1–⌘3 sizes, 始终置顶), 编辑 (standard responder-chain actions, so ⌘V works in fields; ⌘F search), 窗口, 帮助.+- App menu (`AppMenu`): the app is a regular app (name and menus top left, Dock, ⌘Tab) while the main, settings or onboarding window is visible, and an accessory otherwise (`AppDelegate.updateActivationPolicy`). The notes window doesn't count: it is a non-activating panel, so clicking it never takes focus from the meeting app or brings our other windows forward; it becomes key only for its text fields. The Dock icon brings back whichever windows are open (the main window only when none is); quitting while a meeting with lines is being recorded asks first; exports are a sheet on the window they were asked from. The settings window remembers its frame and last tab (`settingsSection`). Menus: app, 纪要, 显示 (display mode, ⌘1–⌘3 sizes, 始终置顶), 编辑 (standard responder-chain actions, so ⌘V works in fields; ⌘F search), 窗口, 帮助.- Meeting records: one folder per meeting, `session.json` + `system.m4a` (+ `mic.m4a`); empty meetings are dropped; export to Markdown, Word (`.docx` via `NSAttributedString`, both starting with the notes) and SRT. Speaker labels are only "对方" (system audio) and "你" (microphone): no diarization yet.- Shortcuts (`Shortcuts.swift`): talk and subtitle-bar toggle are recorded in settings (`ShortcutField`). A combination must include ⌃ or ⌘ (⌥/⇧ alone types characters; bare F keys are brightness/volume), must not be a system shortcut (`CopySymbolicHotKeys`) or held by another app (Carbon refuses to register it).- Nothing the user does needs the Terminal. When a feature request fits none of the above, push back before adding UI.@@ -66,6 +66,6 @@ TODO: unit tests for the pure parts (language-code mapping, detection scoring, S- Keep files small and single-purpose; match the existing naming and comment density (comments say why).- UI and engine state are `@MainActor`; audio callbacks never touch app state directly (they hand buffers to `AudioRouter`'s queue).- No third-party dependencies; system frameworks only.-- User data: `~/Library/Application Support/LiveSubs/Sessions` and `UserDefaults` (`sourceMode`, `target`, `speakEnabled`, `speakFrom`, `speakTo`, `speakOutput`, `recordAudio`, `overlayAuto`, `overlayHideAfter`, `overlay.<screen>`, `lastDetected`, `onboarded`, `talkKey`, `toggleKey` as `keyCode:carbonModifiers`, `displayMode`, `aiModel`, `speakVoices`, `notesOnTop`, `diagnostics`) and the Ling key file (`ling-api-key`).+- User data: `~/Library/Application Support/LiveSubs/Sessions` and `UserDefaults` (`sourceMode`, `target`, `speakEnabled`, `speakFrom`, `speakTo`, `speakOutput`, `recordAudio`, `overlayAuto`, `overlayHideAfter`, `overlay.<screen>`, `lastDetected`, `onboarded`, `talkKey`, `toggleKey` as `keyCode:carbonModifiers`, `displayMode`, `aiModel`, `speakVoices`, `notesOnTop`, `diagnostics`, `settingsSection`) and the Ling key file (`ling-api-key`).- Add a line to `CHANGELOG.md` with every user-visible change. Keep `README.md` and `README.zh-CN.md` in step.- Commit in coherent batches with a short imperative subject.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a900756..bda45a7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -31,6 +31,7 @@ the release workflow publishes it as the release notes.- New: Settings › AI 服务 takes your own Ling (ant-ling.com) API key. It is kept in the macOS Keychain, checked with a one-token request, and shown masked; without a key everything works as before.- New: both shortcuts (talk, hide/show the subtitle bar) can be changed in settings: click and press new keys. Combinations without ⌃ or ⌘, system shortcuts and ones another app already uses are refused with a reason.+- Fixed: clicking the live notes window no longer brings the main or settings window forward or takes focus from the meeting app, and the notes window alone no longer puts the app in the Dock. The Dock icon reopens whichever window is open instead of always the main window; exporting from the main window opens the save dialog on it; quitting while a meeting is being recorded asks first; settings remember their position and last tab; the 窗口 menu lists the open windows.## 2.0.0 — 2026-11-01- New: spoken-language auto-detection across the installed on-device models; translation target follows the system language or a manual choice.diff --git a/Sources/LiveSubs/AppMenu.swift b/Sources/LiveSubs/AppMenu.swiftindex 790dba8..5eda094 100644--- a/Sources/LiveSubs/AppMenu.swift+++ b/Sources/LiveSubs/AppMenu.swift@@ -1,7 +1,8 @@import AppKit-/// The menus in the top-left of the screen. They show while any Live Subs window is in front-/// (the app is a regular app then); the Edit menu also makes ⌘C / ⌘V / ⌘A work in text fields.+/// The menus in the top-left of the screen. They show while the main, settings or onboarding+/// window is in front (the app is a regular app then; the notes window never activates it).+/// The Edit menu also makes ⌘C / ⌘V / ⌘A work in text fields.@MainActorfinal class AppMenu: NSObject, NSMenuItemValidation {private weak var model: AppModel?@@ -85,6 +86,7 @@ final class AppMenu: NSObject, NSMenuItemValidation {add(help, to: main)NSApp.mainMenu = main+ NSApp.windowsMenu = windowNSApp.helpMenu = help}@@ -168,7 +170,6 @@ final class AppMenu: NSObject, NSMenuItemValidation {@objc private func exportNotes(_ sender: NSMenuItem) {guard let model, let s = model.store.session(model.store.liveID ?? model.notes.shownID) else { return }- NSApp.activate()model.export(s, kind: ["md", "word", "srt"][sender.tag])}diff --git a/Sources/LiveSubs/AppModel.swift b/Sources/LiveSubs/AppModel.swiftindex 90b328a..629be53 100644--- a/Sources/LiveSubs/AppModel.swift+++ b/Sources/LiveSubs/AppModel.swift@@ -23,7 +23,10 @@ final class AppModel: ObservableObject {@Published var candidates: [Lang] = []@Published var outputs: [OutputDevice] = []@Published var speakPhase: SpeakEngine.Phase = .idle- @Published var settingsSection: SettingsSection = .speak+ @Published var settingsSection: SettingsSection =+ SettingsSection(rawValue: UserDefaults.standard.string(forKey: "settingsSection") ?? "") ?? .speak {+ didSet { UserDefaults.standard.set(settingsSection.rawValue, forKey: "settingsSection") }+ }@Published var systemAudioOK = false@Published var micStatus: AVAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .audio)@Published var liveSource = ""@@ -518,6 +521,15 @@ final class AppModel: ObservableObject {let ext = kind == "word" ? "docx" : kind == "srt" ? "srt" : "md"panel.nameFieldStringValue = "\(session.title).\(ext)"panel.canCreateDirectories = true+ if let w = NSApp.keyWindow, !(w is NSPanel), w.isVisible {+ panel.beginSheetModal(for: w) { [weak self] r in+ guard r == .OK, let url = panel.url else { return }+ MainActor.assumeIsolated { _ = self?.writeExport(session, kind: kind, to: url) }+ }+ return+ }+ NSApp.activate()+ panel.level = .modalPanelguard panel.runModal() == .OK, let url = panel.url else { return }writeExport(session, kind: kind, to: url)}@@ -676,7 +688,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {menu.showMainWindow = { [weak self] in self?.showMainWindow() }menu.showOnboarding = { [weak self] in self?.showOnboarding() }menu.install()- model.notesWindow.onVisibilityChange = { [weak self] in self?.updateActivationPolicy() }setupStatusItem()model.openMainWindow = { [weak self] in self?.showMainWindow() }model.openSettingsWindow = { [weak self] in self?.showSettingsWindow() }@@ -705,8 +716,21 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {}func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {- showMainWindow()- return true+ let open = [mainWindow, settingsWindow, onboardingWindow].compactMap { $0 }.filter { $0.isVisible || $0.isMiniaturized }+ if open.isEmpty { showMainWindow() } else { open.forEach { $0.deminiaturize(nil) }; NSApp.activate() }+ return false+ }++ /// Quitting ends the meeting being recorded: ask first.+ func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {+ guard model.running, let id = model.store.liveID, !(model.store.session(id)?.lines.isEmpty ?? true) else { return .terminateNow }+ NSApp.activate()+ let alert = NSAlert()+ alert.messageText = "正在记录会议"+ alert.informativeText = "退出会结束这场记录,已记下的内容会保存。"+ alert.addButton(withTitle: "退出")+ alert.addButton(withTitle: "取消")+ return alert.runModal() == .alertFirstButtonReturn ? .terminateNow : .terminateCancel}// MARK: Menu bar@@ -783,6 +807,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {w.contentView = NSHostingView(rootView: SettingsView(model: model, settings: model.settings, installer: model.installer))w.center()settingsWindow = w+ w.setFrameAutosaveName("LiveSubsSettings")}model.refreshOutputs()NSApp.setActivationPolicy(.regular)@@ -829,7 +854,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {/// notes window appearing must not take focus from the meeting app.func updateActivationPolicy(closing: NSWindow? = nil) {let open = [mainWindow, onboardingWindow, settingsWindow].contains { $0 != nil && $0 != closing && $0!.isVisible }- || model.notesWindow.isVisiblelet policy: NSApplication.ActivationPolicy = open ? .regular : .accessoryguard NSApp.activationPolicy() != policy else { return }NSApp.setActivationPolicy(policy)diff --git a/Sources/LiveSubs/NotesWindow.swift b/Sources/LiveSubs/NotesWindow.swiftindex 7ee20c6..1fcfb15 100644--- a/Sources/LiveSubs/NotesWindow.swift+++ b/Sources/LiveSubs/NotesWindow.swift@@ -14,8 +14,6 @@ final class NotesWindowController: NSObject, NSWindowDelegate {private var panel: NSPanel?private weak var model: AppModel?let commands = PassthroughSubject<Command, Never>()- /// Shown or hidden: the app is a regular app (menus, Dock) while any of its windows is open.- var onVisibilityChange: () -> Void = {}init(model: AppModel) {self.model = model@@ -44,14 +42,10 @@ final class NotesWindowController: NSObject, NSWindowDelegate {commands.send(command)}- func windowWillClose(_ notification: Notification) {- DispatchQueue.main.async { [weak self] in self?.onVisibilityChange() }- }-func show() {guard let model else { return }if panel == nil {- let p = NSPanel(contentRect: defaultFrame(), styleMask: [.titled, .closable, .resizable, .fullSizeContentView],+ let p = NSPanel(contentRect: defaultFrame(), styleMask: [.titled, .closable, .resizable, .fullSizeContentView, .nonactivatingPanel],backing: .buffered, defer: false)p.titleVisibility = .hiddenp.titlebarAppearsTransparent = true@@ -59,6 +53,8 @@ final class NotesWindowController: NSObject, NSWindowDelegate {p.isFloatingPanel = onTopp.level = onTop ? .floating : .normalp.delegate = self+ // Clicking it leaves the meeting app active and our other windows where they are;+ // it only takes the keyboard for its text fields.p.hidesOnDeactivate = falsep.becomesKeyOnlyIfNeeded = truep.isReleasedWhenClosed = false@@ -76,12 +72,10 @@ final class NotesWindowController: NSObject, NSWindowDelegate {panel = p}panel?.orderFrontRegardless()- onVisibilityChange()}func hide() {panel?.orderOut(nil)- onVisibilityChange()}var frame: NSRect? { panel?.frame }diff --git a/site/changelog.json b/site/changelog.jsonindex 8a32cee..4d2fb69 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -80,6 +80,11 @@"kind": "fixed","title": "要点全被标成“新”。","text": "会议结束后不再这样,“新”只标最近一分钟加的内容。"+ },+ {+ "kind": "fixed",+ "title": "点纪要窗口会带出主窗口。",+ "text": "现在点它不会把主窗口或设置顶上来,也不抢会议软件的焦点;只开着纪要窗口时,Dock 里不再多一个图标。点 Dock 图标会回到已打开的窗口;正在记录时退出会先问一句;设置记住位置和上次的页面;「窗口」菜单列出已打开的窗口。"}]},