知了 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
feat: add the live notes window as the default display, with a display mode switch
wquguru2c21f0b0560e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 26ff99e..08d864a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ the release workflow publishes it as the release notes.- New: a sound test for the virtual microphone: the app plays a sentence into it, listens back and shows what the room will hear.- New: a settings window with a sidebar (听 / 我说话也翻译 / 字幕条 / 会议记录) replaces the settings sheet; the virtual microphone is set up from a three-step checklist there and in the first-run guide.- Changed: hold the right ⌥ key on its own to talk, instead of ⌥ Space (which other apps' launchers often use, and which types a space). Pressing another key while holding it cancels, so ⌥ + letter still types. It needs the "输入监控" permission; the app asks for it.+- New: a live notes window, now the default display while listening: notes, the transcript and a caption line in one floating window that can be moved and resized anywhere (a small card under 360 px with "我刚走神了,错过什么?", tabs in between, notes beside the transcript from 760 px), never shows up in screen sharing, and remembers its frame. The menu bar panel and settings choose 实时纪要 / 字幕条 / 不显示; ⌃⌥S now cycles through them.- New: live meeting notes. With a key, Ling updates the notes about every 45 s while the meeting runs (summary, topics with key points, a fishbone diagram where causes are discussed, conclusions and to-dos with how many lines back them, names and terms with their misrecognised forms) and rewrites them once over the whole transcript when it ends. Notes are saved with the meeting.- New: with a key, finished sentences and speak-back are translated by Ling (names kept consistent through the notes' glossary); if Ling is busy or fails, that sentence falls back to Google, then to Apple's on-device translation. Partial text while someone is still talking stays on Google.- 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.diff --git a/Sources/LiveSubs/AppModel.swift b/Sources/LiveSubs/AppModel.swiftindex f84f84e..d5324c4 100644--- a/Sources/LiveSubs/AppModel.swift+++ b/Sources/LiveSubs/AppModel.swift@@ -38,6 +38,7 @@ final class AppModel: ObservableObject {let ling = LingClient()lazy var translator = TranslationService(ling: ling)lazy var notes = NotesEngine(ling: ling, store: store)+ lazy var notesWindow = NotesWindowController(model: self)let sample = SamplePlayer()var openOnboarding: (() -> Void)?@@ -52,6 +53,7 @@ final class AppModel: ObservableObject {listen.onSubtitle = { [weak self] src, dst inself?.liveSource = srcself?.liveTranslation = dst+ guard self?.settings.displayMode == "bar" else { return }self?.overlay.clearStatus()self?.overlay.setSubtitle(source: src, translation: dst)}@@ -90,6 +92,14 @@ final class AppModel: ObservableObject {speak.onLive = { [weak self] phase, src, dst inguard let self else { return }self.speakPhase = phase+ guard self.settings.displayMode == "bar" else {+ // The notes window's caption line shows what you are saying.+ if phase != .idle || !src.isEmpty {+ self.liveSource = src.isEmpty ? "你正在说…" : "你:\(src)"+ self.liveTranslation = dst+ }+ return+ }if !self.overlay.isShown { self.overlay.show() }if phase == .idle && src.isEmpty {self.overlay.setSpeaking(nil)@@ -122,7 +132,7 @@ final class AppModel: ObservableObject {(self?.settings.overlayAuto ?? true, self?.settings.overlayHideAfter ?? 4)}toggleKey.onDown = { [weak self] in- DispatchQueue.main.async { MainActor.assumeIsolated { self?.overlay.toggleManual() } }+ DispatchQueue.main.async { MainActor.assumeIsolated { self?.cycleDisplay() } }}applyToggleKey()refreshOutputs()@@ -220,7 +230,7 @@ final class AppModel: ObservableObject {listen.start()notes.begin(session.id)if listen.isRunning {- overlay.show()+ showDisplay()} else {store.end()}@@ -239,6 +249,40 @@ final class AppModel: ObservableObject {func setRunning(_ on: Bool) { on ? start() : stop() }+ // MARK: Display (live notes / subtitle bar / nothing)++ func setDisplayMode(_ mode: String) {+ settings.displayMode = mode+ objectWillChange.send()+ showDisplay()+ }++ /// ⌃⌥S: notes → subtitle bar → nothing → notes.+ func cycleDisplay() {+ let order = ["notes", "bar", "none"]+ let i = order.firstIndex(of: settings.displayMode) ?? 0+ setDisplayMode(order[(i + 1) % order.count])+ }++ private func showDisplay() {+ switch settings.displayMode {+ case "bar":+ notesWindow.hide()+ if listen.isRunning { overlay.show() }+ case "none":+ notesWindow.hide()+ overlay.hide()+ default:+ overlay.hide()+ if listen.isRunning { notesWindow.show() }+ }+ }++ func openNotesWindow() {+ if settings.displayMode != "notes" { setDisplayMode("notes") }+ notesWindow.show()+ }+// MARK: Settings actionsvar sourceSelection: String {@@ -458,7 +502,25 @@ final class AppModel: ObservableObject {if let k = try? String(contentsOfFile: arg, encoding: .utf8) { Task { await ling.setKey(k) } }case "aiCheck": Task { await ling.check() }case "notesNow": notes.updateNow()+ case "display": setDisplayMode(arg)+ case "notesWindow":+ let v = arg.split(separator: ",").compactMap { Double($0) }+ openNotesWindow()+ if v.count == 4 { notesWindow.place(NSRect(x: v[0], y: v[1], width: v[2], height: v[3])) }+ case "notesFrame": debugLog("notes window frame=\(String(describing: notesWindow.frame)) visible=\(notesWindow.isVisible)")case "notesReplay": Task { await notes.replay(arg) }+ case "notesShow": notes.show(arg)+ case "notesCapturable": notesWindow.setCapturable(arg != "off")+ case "notesRender":+ // The whole notes column as a PNG, for checking what is below the fold.+ let view = NotesContentView(notes: notes.notes, fresh: notes.fresh, live: store.liveID != nil)+ .padding(24).frame(width: 460).background(Color.white)+ let r = ImageRenderer(content: view)+ r.scale = 2+ if let img = r.nsImage, let tiff = img.tiffRepresentation, let rep = NSBitmapImageRep(data: tiff),+ let png = rep.representation(using: .png, properties: [:]) {+ try? png.write(to: URL(fileURLWithPath: arg))+ }case "notesState": debugLog("notes state=\(notes.state) topics=\(notes.notes.topics.count) covered=\(notes.notes.covered) glossary=\(notes.glossary.count)")case "lingSimulate":ling.simulate = ["429": .rateLimited, "hijack": .hijacked, "timeout": .timeout][arg]diff --git a/Sources/LiveSubs/Notes.swift b/Sources/LiveSubs/Notes.swiftindex 9dd4cad..17003d3 100644--- a/Sources/LiveSubs/Notes.swift+++ b/Sources/LiveSubs/Notes.swift@@ -37,7 +37,7 @@ struct FishboneBranch: Codable, Equatable, Identifiable {var label: Stringvar detail: Stringvar t: Double?- /// How many transcript lines back this branch; 0–1 is shown as weak.+ /// How many transcript lines back this branch; 0 is shown as weak.var support: Intvar id: String { label + detail }}@@ -133,6 +133,13 @@ final class NotesEngine: ObservableObject {Task { await update(id, final: false) }}+ /// Show a stored meeting's notes (the window shows the live meeting when there is one).+ func show(_ id: String) {+ shownID = id+ notes = store.session(id)?.notes ?? MeetingNotes()+ fresh = []+ }+/// Notes for a finished meeting that has none (e.g. recorded before a key was set).func generate(for id: String) {Task { await update(id, final: true) }@@ -152,6 +159,9 @@ final class NotesEngine: ObservableObject {}private func tick() {+ // A key was added or replaced since the last failure.+ if (state == .noKey || state == .invalidKey), ling.usable, ling.keyState != .checking { state = .idle }+ if state == .idle, !ling.hasKey { state = .noKey }guard let id = sessionID, !inFlight else { return }guard let s = store.session(id), s.lines.count > notes.covered else { return }// First notes as soon as there is something to say, then every 45 s.@@ -212,7 +222,7 @@ final class NotesEngine: ObservableObject {// MARK: Prompt- static func clock(_ t: Double) -> String { String(format: "%02d:%02d", Int(t) / 60, Int(t) % 60) }+ static func clock(_ t: Double) -> String { TranscriptExport.clock(t) }static func prompt(notes: MeetingNotes, lines: [TranscriptLine], from: Int, language: String, final: Bool) -> String {func line(_ i: Int) -> String {diff --git a/Sources/LiveSubs/NotesViews.swift b/Sources/LiveSubs/NotesViews.swiftnew file mode 100644index 0000000..1530b1c--- /dev/null+++ b/Sources/LiveSubs/NotesViews.swift@@ -0,0 +1,349 @@+import AppKit+import SwiftUI++// Notes and transcript views shared by the live notes window and the main window (meeting+// records). The look follows the canvas: white ground, grey blocks for what matters most,+// framed lists with hairlines, orange only for what is happening now.++// MARK: - Notes++struct NotesContentView: View {+ let notes: MeetingNotes+ var fresh: Set<String> = []+ /// The meeting is still going: the last topic is "正在讲".+ var live = false+ var updating = false+ var summaryJustChanged = false+ var onJump: (Double) -> Void = { _ in }++ var body: some View {+ VStack(alignment: .leading, spacing: 18) {+ if !notes.summary.isEmpty {+ VStack(alignment: .leading, spacing: 8) {+ HStack(spacing: 8) {+ Text("总结").font(.system(size: 15, weight: .bold))+ if summaryJustChanged { Tag("刚更新", live: true) }+ Spacer()+ if notes.final { Tag("完整版") } else if live { Tag("速记版") }+ }+ Text(notes.summary).font(.system(size: 14)).lineSpacing(4).textSelection(.enabled)+ }+ .padding(.horizontal, 18).padding(.vertical, 16)+ .frame(maxWidth: .infinity, alignment: .leading)+ .background(RoundedRectangle(cornerRadius: 18).fill(Palette.raised))+ }++ if !notes.topics.isEmpty {+ VStack(alignment: .leading, spacing: 14) {+ SectionTitle("议题")+ ForEach(Array(notes.topics.enumerated()), id: \.element.id) { i, topic in+ TopicView(topic: topic, current: live && i == notes.topics.count - 1,+ updating: updating && i == notes.topics.count - 1, fresh: fresh, onJump: onJump)+ }+ }+ }++ if !notes.conclusions.isEmpty || !notes.todos.isEmpty {+ VStack(alignment: .leading, spacing: 10) {+ SectionTitle(notes.todos.isEmpty ? "结论" : "结论和待办")+ FramedList {+ ForEach(Array((notes.conclusions + notes.todos).enumerated()), id: \.offset) { i, item in+ let todo = i >= notes.conclusions.count+ HStack(alignment: .firstTextBaseline, spacing: 10) {+ if todo {+ Image(systemName: "circle").font(.system(size: 11)).foregroundStyle(Palette.tertiary)+ }+ Text(item.text + (item.owner.map { "(\($0))" } ?? ""))+ .font(.system(size: 14)).lineSpacing(2)+ .foregroundStyle(item.support == 0 ? Palette.tertiary : Palette.ink)+ .frame(maxWidth: .infinity, alignment: .leading)+ Tag(item.support == 0 ? "依据少" : "依据 \(item.support) 句")+ }+ .padding(.horizontal, 16).padding(.vertical, 11)+ if i < notes.conclusions.count + notes.todos.count - 1 { Divider() }+ }+ }+ }+ }++ if !notes.terms.isEmpty {+ VStack(alignment: .leading, spacing: 10) {+ SectionTitle("人名和术语")+ FlowLayout(spacing: 6) {+ ForEach(notes.terms) { t in+ (Text(t.name).bold() + Text(t.note.isEmpty ? "" : " \(t.note)")+ + Text(t.heard.isEmpty ? "" : " · 原识别 \(t.heard.prefix(2).joined(separator: "、"))")+ .foregroundColor(Palette.tertiary))+ .font(.system(size: 12))+ .padding(.horizontal, 9).padding(.vertical, 5)+ .background(RoundedRectangle(cornerRadius: 7).fill(Palette.fill))+ }+ }+ }+ }+ }+ }+}++private struct TopicView: View {+ let topic: NoteTopic+ let current: Bool+ let updating: Bool+ let fresh: Set<String>+ let onJump: (Double) -> Void++ var body: some View {+ VStack(alignment: .leading, spacing: 8) {+ HStack(alignment: .firstTextBaseline, spacing: 10) {+ Button { onJump(topic.start) } label: {+ Text(NotesEngine.clock(topic.start))+ .font(.system(size: 12).monospacedDigit())+ .foregroundStyle(current ? Palette.accentInk : Palette.tertiary)+ .frame(width: topic.start >= 3600 ? 56 : 40, alignment: .leading)+ }+ .buttonStyle(.plain).help("看原话")+ Text(topic.title).font(.system(size: 15, weight: .bold))+ if current { Tag("正在讲", live: true) }+ if fresh.contains(topic.title) && !current { Tag("新", live: true) }+ }+ VStack(alignment: .leading, spacing: 6) {+ if !topic.summary.isEmpty {+ Text(topic.summary).font(.system(size: 13)).foregroundStyle(Palette.secondary).lineSpacing(2)+ .fixedSize(horizontal: false, vertical: true)+ }+ ForEach(topic.points, id: \.self) { p in+ HStack(alignment: .firstTextBaseline, spacing: 8) {+ Circle().fill(fresh.contains(p) ? Palette.accent : Palette.ink.opacity(0.55)).frame(width: 4, height: 4)+ .alignmentGuide(.firstTextBaseline) { $0[.bottom] + 4 }+ Text(p).font(.system(size: 14)).lineSpacing(2).textSelection(.enabled)+ .fixedSize(horizontal: false, vertical: true)+ if fresh.contains(p) { Tag("新", live: true) }+ }+ }+ if let fish = topic.fishbone { FishboneView(fishbone: fish, onJump: onJump).padding(.top, 4) }+ if updating {+ VStack(alignment: .leading, spacing: 6) {+ RoundedRectangle(cornerRadius: 4).fill(Palette.fill).frame(height: 9).frame(maxWidth: 260)+ RoundedRectangle(cornerRadius: 4).fill(Palette.fill).frame(width: 160, height: 9)+ Text("正在整理这一段…").font(.system(size: 12)).foregroundStyle(Palette.tertiary)+ }+ .padding(.top, 4)+ }+ }+ .padding(.leading, topic.start >= 3600 ? 66 : 50)+ }+ .padding(.vertical, current ? 10 : 0).padding(.horizontal, current ? 10 : 0)+ .background(RoundedRectangle(cornerRadius: 14).fill(current ? Palette.accentWash : .clear))+ }+}++/// A fishbone drawn upright for a narrow window: the question on top, branches alternating on+/// either side of a spine. A branch no transcript line backs is dashed.+struct FishboneView: View {+ let fishbone: Fishbone+ var onJump: (Double) -> Void = { _ in }++ var body: some View {+ VStack(alignment: .leading, spacing: 10) {+ HStack(spacing: 6) {+ Image(systemName: "point.3.connected.trianglepath.dotted").font(.system(size: 12)).foregroundStyle(Palette.secondary)+ Text(fishbone.question.isEmpty ? "为什么" : fishbone.question).font(.system(size: 13, weight: .bold))+ Spacer()+ Text("鱼骨图").font(.system(size: 11)).foregroundStyle(Palette.tertiary)+ }+ VStack(spacing: 6) {+ ForEach(Array(stride(from: 0, to: fishbone.branches.count, by: 2)), id: \.self) { i in+ HStack(alignment: .center, spacing: 0) {+ branch(fishbone.branches[i])+ spine+ if i + 1 < fishbone.branches.count {+ branch(fishbone.branches[i + 1])+ } else {+ Color.clear.frame(maxWidth: .infinity)+ }+ }+ .fixedSize(horizontal: false, vertical: true)+ }+ }+ Text("点分支回到原话").font(.system(size: 11)).foregroundStyle(Palette.tertiary)+ }+ .padding(12)+ .background(RoundedRectangle(cornerRadius: 16).stroke(Palette.line, lineWidth: 1))+ }++ private var spine: some View {+ VStack(spacing: 0) {+ Rectangle().fill(Color(white: 0.84)).frame(width: 2)+ Circle().fill(Palette.ink).frame(width: 7, height: 7)+ Rectangle().fill(Color(white: 0.84)).frame(width: 2)+ }+ .frame(width: 18)+ }++ private func branch(_ b: FishboneBranch) -> some View {+ let weak = b.support == 0+ return Button { if let t = b.t { onJump(t) } } label: {+ VStack(alignment: .leading, spacing: 3) {+ Text(b.label).font(.system(size: 12, weight: .bold)).foregroundStyle(weak ? Palette.tertiary : Palette.ink)+ if !b.detail.isEmpty {+ Text(b.detail).font(.system(size: 12)).foregroundStyle(Palette.secondary).lineLimit(3)+ .fixedSize(horizontal: false, vertical: true)+ }+ }+ .padding(.horizontal, 10).padding(.vertical, 8)+ .frame(maxWidth: .infinity, alignment: .leading)+ .background(RoundedRectangle(cornerRadius: 10).fill(weak ? Color.clear : Palette.raised))+ .overlay(RoundedRectangle(cornerRadius: 10)+ .stroke(weak ? Color(white: 0.8) : .clear, style: StrokeStyle(lineWidth: 1, dash: [4, 3])))+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ .help(weak ? "依据少,仅供参考" : "看原话")+ }+}++// MARK: - Transcript++/// The transcript grouped under the notes' topics, newest at the bottom.+struct TranscriptListView: View {+ let lines: [TranscriptLine]+ let topics: [NoteTopic]+ var query = ""+ var bilingual = true+ var live = false+ var jumpTo: Double?++ private var groups: [(title: String, start: Double, lines: [TranscriptLine])] {+ let shown = query.isEmpty ? lines : lines.filter {+ $0.src.localizedCaseInsensitiveContains(query) || ($0.dst ?? "").localizedCaseInsensitiveContains(query)+ }+ guard !topics.isEmpty else { return [("", 0, shown)] }+ var out: [(String, Double, [TranscriptLine])] = []+ for (i, t) in topics.enumerated() {+ let end = i + 1 < topics.count ? topics[i + 1].start : .infinity+ let first = i == 0 ? -Double.infinity : t.start+ let ls = shown.filter { $0.t >= first && $0.t < end }+ if !ls.isEmpty { out.append((t.title, t.start, ls)) }+ }+ return out+ }++ var body: some View {+ ScrollViewReader { proxy in+ ScrollView {+ LazyVStack(alignment: .leading, spacing: 10) {+ ForEach(groups, id: \.start) { g in+ if !g.title.isEmpty { SectionTitle(g.title).padding(.top, 6) }+ FramedList {+ ForEach(Array(g.lines.enumerated()), id: \.element.id) { i, l in+ row(l, current: live && l.id == lines.last?.id).id(l.id)+ if i < g.lines.count - 1 { Divider() }+ }+ }+ }+ if lines.isEmpty {+ Text("说话的内容会出现在这里").font(.system(size: 13)).foregroundStyle(Palette.tertiary)+ .frame(maxWidth: .infinity).padding(.top, 40)+ }+ }+ .padding(.bottom, 12)+ }+ .onChange(of: lines.count) { _, _ in+ if live, query.isEmpty, let last = lines.last { withAnimation { proxy.scrollTo(last.id, anchor: .bottom) } }+ }+ .onChange(of: jumpTo) { _, t in+ guard let t, let target = lines.first(where: { $0.t >= t - 1 }) ?? lines.last else { return }+ withAnimation { proxy.scrollTo(target.id, anchor: .top) }+ }+ .onAppear {+ if let t = jumpTo, let target = lines.first(where: { $0.t >= t - 1 }) {+ proxy.scrollTo(target.id, anchor: .top)+ } else if live, let last = lines.last {+ proxy.scrollTo(last.id, anchor: .bottom)+ }+ }+ }+ }++ private func row(_ l: TranscriptLine, current: Bool) -> some View {+ HStack(alignment: .top, spacing: 12) {+ Text(NotesEngine.clock(l.t)).font(.system(size: 12).monospacedDigit())+ .foregroundStyle(current ? Palette.accentInk : Palette.tertiary)+ .frame(width: l.t >= 3600 ? 56 : 40, alignment: .leading).padding(.top, 2)+ VStack(alignment: .leading, spacing: 4) {+ if l.speaker == "me" { Text("你").font(.system(size: 11, weight: .semibold)).foregroundStyle(Palette.accentInk) }+ Text(l.src).font(.system(size: 14)).lineSpacing(2).textSelection(.enabled)+ if bilingual, let d = l.dst, d != l.src {+ Text(d).font(.system(size: 13)).foregroundStyle(Palette.secondary).lineSpacing(2).textSelection(.enabled)+ }+ }+ Spacer(minLength: 0)+ }+ .padding(.horizontal, 14).padding(.vertical, 11)+ .background(current ? Palette.accentWash : Color.clear)+ }+}++// MARK: - Small parts++struct SectionTitle: View {+ let text: String+ init(_ text: String) { self.text = text }+ var body: some View {+ Text(text).font(.system(size: 15, weight: .bold)).foregroundStyle(Palette.secondary)+ }+}++struct Tag: View {+ let text: String+ var live = false+ init(_ text: String, live: Bool = false) {+ self.text = text+ self.live = live+ }+ var body: some View {+ Text(text).font(.system(size: 11, weight: .semibold))+ .foregroundStyle(live ? Palette.accentInk : Palette.secondary)+ .padding(.horizontal, 7).padding(.vertical, 2)+ .background(RoundedRectangle(cornerRadius: 6).fill(live ? Palette.accentPale : Palette.fill))+ .fixedSize()+ }+}++struct FramedList<Content: View>: View {+ @ViewBuilder var content: Content+ var body: some View {+ VStack(alignment: .leading, spacing: 0) { content }+ .frame(maxWidth: .infinity, alignment: .leading)+ .clipShape(RoundedRectangle(cornerRadius: 16))+ .overlay(RoundedRectangle(cornerRadius: 16).stroke(Palette.line, lineWidth: 1))+ }+}++/// Wraps chips onto as many lines as needed.+struct FlowLayout: Layout {+ var spacing: CGFloat = 6++ func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {+ let width = proposal.width ?? 400+ var x: CGFloat = 0, y: CGFloat = 0, row: CGFloat = 0+ for v in subviews {+ let s = v.sizeThatFits(.unspecified)+ if x + s.width > width, x > 0 { x = 0; y += row + spacing; row = 0 }+ x += s.width + spacing+ row = max(row, s.height)+ }+ return CGSize(width: width, height: y + row)+ }++ func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {+ var x = bounds.minX, y = bounds.minY, row: CGFloat = 0+ for v in subviews {+ let s = v.sizeThatFits(.unspecified)+ if x + s.width > bounds.maxX, x > bounds.minX { x = bounds.minX; y += row + spacing; row = 0 }+ v.place(at: CGPoint(x: x, y: y), proposal: ProposedViewSize(s))+ x += s.width + spacing+ row = max(row, s.height)+ }+ }+}diff --git a/Sources/LiveSubs/NotesWindow.swift b/Sources/LiveSubs/NotesWindow.swiftnew file mode 100644index 0000000..b0b7470--- /dev/null+++ b/Sources/LiveSubs/NotesWindow.swift@@ -0,0 +1,371 @@+import AppKit+import SwiftUI++/// The live notes window: floats over the meeting app, can be dragged and resized anywhere,+/// stays out of screen sharing, and remembers its frame. Three layouts by width: a small card+/// (< 360), a sidebar with 纪要 / 文字记录 tabs, and notes beside the transcript (≥ 760).+@MainActor+final class NotesWindowController {+ private var panel: NSPanel?+ private weak var model: AppModel?++ init(model: AppModel) { self.model = model }++ var isVisible: Bool { panel?.isVisible ?? false }++ func show() {+ guard let model else { return }+ if panel == nil {+ let p = NSPanel(contentRect: defaultFrame(), styleMask: [.titled, .closable, .resizable, .fullSizeContentView],+ backing: .buffered, defer: false)+ p.titleVisibility = .hidden+ p.titlebarAppearsTransparent = true+ p.isMovableByWindowBackground = true+ p.isFloatingPanel = true+ p.level = .floating+ p.hidesOnDeactivate = false+ p.becomesKeyOnlyIfNeeded = true+ p.isReleasedWhenClosed = false+ // Others never see it when you share your screen.+ p.sharingType = .none+ p.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]+ p.minSize = NSSize(width: 300, height: 180)+ p.backgroundColor = .white+ p.contentView = NSHostingView(rootView: NotesWindowView(+ model: model, engine: model.notes, store: model.store, settings: model.settings,+ setWidth: { [weak self] w, h in self?.resize(width: w, height: h) }))+ p.setFrameAutosaveName("LiveSubsNotes")+ if !p.setFrameUsingName("LiveSubsNotes") { p.setFrame(defaultFrame(), display: false) }+ panel = p+ }+ panel?.orderFrontRegardless()+ }++ func hide() { panel?.orderOut(nil) }++ var frame: NSRect? { panel?.frame }++ /// Card ⇄ sidebar ⇄ wide, keeping the window's top-right corner where it is.+ func resize(width: CGFloat, height: CGFloat? = nil) {+ guard let p = panel, let screen = p.screen ?? NSScreen.main else { return }+ var f = p.frame+ let top = f.maxY, right = f.maxX+ f.size.width = width+ if let height { f.size.height = min(height, screen.visibleFrame.height - 24) }+ f.origin.x = min(max(screen.visibleFrame.minX, right - width), screen.visibleFrame.maxX - width)+ f.origin.y = top - f.size.height+ p.setFrame(f, display: true, animate: true)+ }++ func place(_ r: NSRect) { panel?.setFrame(r, display: true) }++ /// Debug control only: let screenshots capture the window.+ func setCapturable(_ on: Bool) { panel?.sharingType = on ? .readOnly : .none }++ /// The sidebar: docked to the right edge, nearly full height.+ private func defaultFrame() -> NSRect {+ let v = (NSScreen.main ?? NSScreen.screens[0]).visibleFrame+ return NSRect(x: v.maxX - 460 - 16, y: v.minY + 16, width: 460, height: v.height - 32)+ }+}++// MARK: - Views++struct NotesWindowView: View {+ @ObservedObject var model: AppModel+ @ObservedObject var engine: NotesEngine+ @ObservedObject var store: SessionStore+ @ObservedObject var settings: AppSettings+ let setWidth: (CGFloat, CGFloat?) -> Void++ @State private var tab = "notes"+ @State private var query = ""+ @State private var jumpTo: Double?+ @State private var keyDraft = ""+ /// Session time when the window was collapsed to the card: "what did I miss" starts there.+ @State private var collapsedAt: Double = 0+ @State private var catchUp = false+ @State private var now = Date()++ private var session: Session? { store.session(store.liveID ?? engine.shownID) }+ private var live: Bool { store.liveID != nil }+ private let tick = Timer.publish(every: 1, on: .main, in: .common).autoconnect()++ var body: some View {+ GeometryReader { geo in+ Group {+ if geo.size.width < 360 {+ card+ } else {+ VStack(alignment: .leading, spacing: 0) {+ header(wide: geo.size.width >= 760)+ banner.padding(.horizontal, 24).padding(.bottom, 4)+ if geo.size.width >= 760 {+ HStack(alignment: .top, spacing: 0) {+ notesScroll.frame(maxWidth: .infinity)+ Divider()+ transcript.padding(.horizontal, 20).padding(.top, 12).frame(maxWidth: .infinity)+ }+ } else if tab == "notes" {+ notesScroll+ } else {+ transcript.padding(.horizontal, 24).padding(.top, 12)+ }+ caption+ }+ }+ }+ .frame(width: geo.size.width, height: geo.size.height)+ }+ .background(Color.white)+ .foregroundStyle(Palette.ink)+ .onReceive(tick) { now = $0 }+ }++ // MARK: Header++ private func header(wide: Bool) -> some View {+ VStack(alignment: .leading, spacing: 16) {+ HStack(alignment: .top, spacing: 4) {+ VStack(alignment: .leading, spacing: 6) {+ Text("实时纪要").font(.system(size: 24, weight: .bold))+ HStack(spacing: 6) {+ if live { Circle().fill(Palette.accent).frame(width: 7, height: 7) }+ Text(statusLine).font(.system(size: 12)).foregroundStyle(Palette.tertiary).lineLimit(1)+ }+ }+ Spacer()+ iconButton(wide ? "rectangle.split.2x1.fill" : "rectangle.split.2x1", help: wide ? "收窄" : "纪要和原话并排") {+ setWidth(wide ? 460 : 820, nil)+ }+ iconButton("minus", help: "收成小卡") {+ collapsedAt = elapsed+ catchUp = false+ setWidth(320, 230)+ }+ }+ if !wide {+ HStack(spacing: 0) {+ segment("纪要", "notes")+ segment("文字记录", "transcript")+ }+ .padding(4)+ .background(RoundedRectangle(cornerRadius: 12).fill(Palette.fill))+ }+ if wide || tab == "transcript" {+ HStack(spacing: 8) {+ Image(systemName: "magnifyingglass").font(.system(size: 13)).foregroundStyle(Palette.tertiary)+ TextField("搜索文字记录", text: $query).textFieldStyle(.plain).font(.system(size: 13))+ }+ .padding(.horizontal, 12).frame(height: 34)+ .background(RoundedRectangle(cornerRadius: 10).fill(Palette.fill))+ }+ }+ .padding(.horizontal, 24).padding(.top, 34).padding(.bottom, 12)+ }++ private func segment(_ title: String, _ id: String) -> some View {+ Button { tab = id } label: {+ Text(title).font(.system(size: 13, weight: tab == id ? .semibold : .regular))+ .foregroundStyle(tab == id ? Palette.ink : Palette.secondary)+ .frame(maxWidth: .infinity).frame(height: 30)+ .background(RoundedRectangle(cornerRadius: 9).fill(tab == id ? Color.white : .clear)+ .shadow(color: .black.opacity(tab == id ? 0.08 : 0), radius: 1.5, y: 1))+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ }++ private func iconButton(_ name: String, help: String, action: @escaping () -> Void) -> some View {+ Button(action: action) {+ Image(systemName: name).font(.system(size: 13)).foregroundStyle(Palette.secondary)+ .frame(width: 30, height: 30).contentShape(Rectangle())+ }+ .buttonStyle(.plain).help(help).accessibilityLabel(help)+ }++ private var elapsed: Double { store.liveStart.map { now.timeIntervalSince($0) } ?? 0 }++ private var statusLine: String {+ let clock = live ? "正在记录 · \(NotesEngine.clock(elapsed))" : (session.map { TranscriptExport.header($0) } ?? "没有进行中的会议")+ guard let at = engine.notes.updatedAt else { return clock }+ let ago = Int(now.timeIntervalSince(at))+ if engine.state == .updating { return clock + " · 正在更新" }+ return clock + " · " + (ago < 10 ? "刚刚更新" : ago < 60 ? "\(ago) 秒前更新" : "\(ago / 60) 分钟前更新")+ }++ // MARK: Banners (key and service states)++ @ViewBuilder+ private var banner: some View {+ switch engine.state {+ case .noKey where session?.lines.isEmpty == false || live:+ keyEntry+ case .invalidKey:+ notice("key 失效了(令牌被删除,或免费额度用完),纪要停在 \(NotesEngine.clock(lastCovered))。", tint: Palette.errorPale) {+ SoftButton("换一个 key", dark: true) { model.openSettings(.ai) }+ }+ case .rateLimited:+ notice("请求太多,Ling 让等一下,过一会儿自动再试。纪要停在 \(NotesEngine.clock(lastCovered))。", tint: Palette.fill) { EmptyView() }+ case .failed:+ notice("这次没整理好,下一轮会再试。", tint: Palette.fill) { EmptyView() }+ default:+ EmptyView()+ }+ }++ private var lastCovered: Double {+ guard let s = session, engine.notes.covered > 0, engine.notes.covered <= s.lines.count else { return 0 }+ return s.lines[engine.notes.covered - 1].t+ }++ private func notice<Trailing: View>(_ text: String, tint: Color, @ViewBuilder trailing: () -> Trailing) -> some View {+ HStack(spacing: 10) {+ Text(text).font(.system(size: 12)).lineSpacing(2).frame(maxWidth: .infinity, alignment: .leading)+ trailing()+ }+ .padding(12)+ .background(RoundedRectangle(cornerRadius: 12).fill(tint))+ }++ private var keyEntry: some View {+ VStack(alignment: .leading, spacing: 10) {+ Text("纪要需要一个 API key").font(.system(size: 15, weight: .bold))+ Text("文字记录照常在记。填上 Ling 的 key 后,从这场会已经说过的内容开始整理。")+ .font(.system(size: 12)).foregroundStyle(Palette.secondary).lineSpacing(2)+ HStack(spacing: 8) {+ SecureField("sk-…", text: $keyDraft)+ .textFieldStyle(.plain).font(.system(size: 13, design: .monospaced))+ .padding(.horizontal, 10).frame(height: 34)+ .background(RoundedRectangle(cornerRadius: 9).fill(Color.white))+ .overlay(RoundedRectangle(cornerRadius: 9).stroke(Palette.line, lineWidth: 1))+ .onSubmit(saveKey)+ SoftButton("保存并开始", dark: true, action: saveKey)+ }+ Button("去 Ling 拿 key ↗") {+ if let url = URL(string: "https://chat.ant-ling.com/open") { NSWorkspace.shared.open(url) }+ }+ .buttonStyle(.plain).font(.system(size: 12)).foregroundStyle(Palette.secondary)+ }+ .padding(16)+ .background(RoundedRectangle(cornerRadius: 16).fill(Palette.raised))+ }++ private func saveKey() {+ let k = keyDraft+ keyDraft = ""+ Task {+ await model.ling.setKey(k)+ if model.ling.usable { model.notes.updateNow() }+ }+ }++ // MARK: Content++ private var notesScroll: some View {+ ScrollView {+ VStack(alignment: .leading, spacing: 0) {+ if engine.notes.isEmpty {+ emptyNotes+ } else {+ NotesContentView(notes: engine.notes, fresh: engine.fresh, live: live,+ updating: engine.state == .updating,+ summaryJustChanged: engine.summaryChangedAt.map { now.timeIntervalSince($0) < 20 } ?? false,+ onJump: { t in jumpTo = t; tab = "transcript" })+ }+ }+ .padding(.horizontal, 24).padding(.vertical, 12)+ }+ }++ @ViewBuilder+ private var emptyNotes: some View {+ if engine.state == .noKey { EmptyView() } else {+ VStack(alignment: .leading, spacing: 8) {+ Text(engine.state == .updating ? "正在整理第一版纪要…" : "开始说话后,大约半分钟出第一版纪要")+ .font(.system(size: 14, weight: .semibold))+ Text("之后每 45 秒更新一次;会议结束时再整理一遍完整版。")+ .font(.system(size: 12)).foregroundStyle(Palette.tertiary)+ }+ .padding(18).frame(maxWidth: .infinity, alignment: .leading)+ .background(RoundedRectangle(cornerRadius: 18).fill(Palette.raised))+ }+ }++ private var transcript: some View {+ TranscriptListView(lines: session?.lines ?? [], topics: engine.notes.topics, query: query,+ live: live, jumpTo: jumpTo)+ }++ @ViewBuilder+ private var caption: some View {+ if live, !model.liveSource.isEmpty || !model.liveTranslation.isEmpty {+ VStack(alignment: .leading, spacing: 3) {+ if !model.liveSource.isEmpty {+ Text(model.liveSource).font(.system(size: 12)).foregroundStyle(Color(white: 0.74)).lineLimit(2)+ }+ if !model.liveTranslation.isEmpty {+ Text(model.liveTranslation).font(.system(size: 14, weight: .semibold)).foregroundStyle(.white).lineLimit(3)+ }+ }+ .frame(maxWidth: .infinity, alignment: .leading)+ .padding(.horizontal, 16).padding(.vertical, 12)+ .background(RoundedRectangle(cornerRadius: 14).fill(Palette.ink))+ .padding(.horizontal, 16).padding(.bottom, 16).padding(.top, 8)+ }+ }++ // MARK: Card++ private var card: some View {+ VStack(alignment: .leading, spacing: 10) {+ HStack(spacing: 6) {+ if live { Circle().fill(Palette.accent).frame(width: 7, height: 7) }+ Text(currentTopic.map { (live ? "正在讲 · " : "最后一个议题 · ") + "\(NotesEngine.clock($0.start)) 起" } ?? (live ? "正在记录" : "实时纪要"))+ .font(.system(size: 12)).foregroundStyle(Palette.tertiary)+ Spacer()+ iconButton("arrow.up.left.and.arrow.down.right", help: "展开纪要") { setWidth(460, 760) }+ }+ if catchUp {+ Text("你错过的 \(missedSpan)").font(.system(size: 15, weight: .bold))+ ScrollView {+ VStack(alignment: .leading, spacing: 6) {+ ForEach(missed, id: \.self) { p in+ HStack(alignment: .firstTextBaseline, spacing: 6) {+ Circle().fill(Palette.ink.opacity(0.55)).frame(width: 4, height: 4)+ Text(p).font(.system(size: 13)).lineSpacing(2)+ }+ }+ }+ }+ HStack(spacing: 8) {+ SoftButton("展开完整纪要", dark: true) { setWidth(460, 760) }+ SoftButton("知道了") { catchUp = false; collapsedAt = elapsed }+ }+ } else {+ Text(currentTopic?.title ?? "还没有纪要").font(.system(size: 17, weight: .bold)).lineLimit(2)+ if let last = currentTopic?.points.last {+ Text(last).font(.system(size: 13)).foregroundStyle(Palette.secondary).lineLimit(2)+ }+ Spacer(minLength: 0)+ SoftButton("我刚走神了,错过什么?", dark: true) { catchUp = true }+ }+ }+ .padding(.horizontal, 18).padding(.top, 30).padding(.bottom, 16)+ }++ private var currentTopic: NoteTopic? { engine.notes.topics.last }++ private var missed: [String] {+ let topics = engine.notes.topics+ let since = topics.filter { $0.start >= collapsedAt - 5 }+ let pool = since.isEmpty ? Array(topics.suffix(1)) : since+ let items = pool.flatMap { t in ["\(t.title):\(t.summary.isEmpty ? t.points.first ?? "" : t.summary)"] + t.points.prefix(2) }+ return items.isEmpty ? ["这段时间还没有新的纪要"] : items+ }++ private var missedSpan: String {+ let s = max(0, Int(elapsed - collapsedAt))+ return s < 60 ? "\(s) 秒" : "\(s / 60) 分 \(s % 60) 秒"+ }+}diff --git a/Sources/LiveSubs/Settings.swift b/Sources/LiveSubs/Settings.swiftindex c785307..a621c13 100644--- a/Sources/LiveSubs/Settings.swift+++ b/Sources/LiveSubs/Settings.swift@@ -53,6 +53,10 @@ final class AppSettings: ObservableObject {didSet { save() }}+ /// What shows while listening: "notes" (live notes window, default), "bar" (subtitle bar), "none".+ @Published var displayMode: String {+ didSet { save() }+ }/// Ling model for notes and translation.@Published var aiModel: String {didSet { save() }@@ -79,6 +83,7 @@ final class AppSettings: ObservableObject {talkKey = Shortcut(stored: defaults.string(forKey: "talkKey")) ?? .defaultTalktoggleKey = Shortcut(stored: defaults.string(forKey: "toggleKey")) ?? .defaultToggleaiModel = defaults.string(forKey: "aiModel") ?? "Ling-3.1-flash"+ displayMode = defaults.string(forKey: "displayMode") ?? "notes"}private func save() {@@ -97,6 +102,7 @@ final class AppSettings: ObservableObject {defaults.set(talkKey.stored, forKey: "talkKey")defaults.set(toggleKey.stored, forKey: "toggleKey")defaults.set(aiModel, forKey: "aiModel")+ defaults.set(displayMode, forKey: "displayMode")}/// Target language. "Follow system" uses the first system language thatdiff --git a/Sources/LiveSubs/SettingsWindow.swift b/Sources/LiveSubs/SettingsWindow.swiftindex 89675bd..2177c92 100644--- a/Sources/LiveSubs/SettingsWindow.swift+++ b/Sources/LiveSubs/SettingsWindow.swift@@ -9,7 +9,7 @@ enum SettingsSection: String, CaseIterable, Identifiable {switch self {case .listen: "听"case .speak: "我说话也翻译"- case .overlay: "字幕条"+ case .overlay: "显示"case .records: "会议记录"case .ai: "AI 服务"}@@ -462,7 +462,21 @@ struct SettingsView: View {private var overlay: some View {VStack(alignment: .leading, spacing: 14) {SettingsCard {- SettingsRow(title: "显示") {+ SettingsRow(title: "听的时候显示", detail: "选哪个都会照样记录、照样出纪要") {+ Picker("显示方式", selection: Binding(get: { settings.displayMode }, set: { model.setDisplayMode($0) })) {+ Text("实时纪要").tag("notes")+ Text("字幕条").tag("bar")+ Text("不显示").tag("none")+ }+ .pickerStyle(.segmented).labelsHidden().frame(width: 210)+ }+ SettingsRow(title: "切换显示方式", detail: model.toggleKeyTaken ? "被其他应用占用了,点右边换一个" : "实时纪要 → 字幕条 → 不显示", divider: false) {+ ShortcutField(model: model, role: .toggle)+ }+ }+ Text("字幕条").font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.secondary).padding(.top, 4)+ SettingsCard {+ SettingsRow(title: "字幕条出现") {Picker("显示", selection: Binding(get: { settings.overlayAuto }, set: { model.setOverlayAuto($0) })) {Text("说话时").tag(true)Text("一直").tag(false)@@ -479,9 +493,6 @@ struct SettingsView: View {.pickerStyle(.segmented).labelsHidden().frame(width: 140)}}- SettingsRow(title: "随时显示 / 隐藏", detail: model.toggleKeyTaken ? "被其他应用占用了,点右边换一个" : nil) {- ShortcutField(model: model, role: .toggle)- }SettingsRow(title: "位置和大小", detail: "鼠标停住不动可拖动,拖右下角缩放", divider: false) {SoftButton("恢复默认") { model.overlay.resetPosition() }}diff --git a/Sources/LiveSubs/Views.swift b/Sources/LiveSubs/Views.swiftindex 5d4f12e..d93d985 100644--- a/Sources/LiveSubs/Views.swift+++ b/Sources/LiveSubs/Views.swift@@ -160,15 +160,35 @@ struct MenuPanelView: View {VStack(spacing: 10) {HStack {- Text("字幕条").font(.system(size: 14, weight: .semibold)).foregroundStyle(Palette.ink)+ Text("显示").font(.system(size: 14, weight: .semibold)).foregroundStyle(Palette.ink)Spacer()- Picker("字幕条", selection: Binding(get: { settings.overlayAuto }, set: { model.setOverlayAuto($0) })) {- Text("说话时显示").tag(true)- Text("一直显示").tag(false)+ Picker("显示", selection: Binding(get: { settings.displayMode }, set: { model.setDisplayMode($0) })) {+ Text("实时纪要").tag("notes")+ Text("字幕条").tag("bar")+ Text("不显示").tag("none")+ }+ .pickerStyle(.segmented).labelsHidden().frame(width: 210)+ }+ if settings.displayMode == "notes" {+ HStack {+ Text(model.ling.hasKey ? "纪要、文字记录和字幕都在一个窗口里" : "填上 API key 才有纪要;文字记录照常")+ .font(.system(size: 12)).foregroundStyle(Palette.secondary)+ Spacer()+ SoftButton("打开") { model.openNotesWindow() }+ }+ }+ if settings.displayMode == "bar" {+ HStack {+ Text("字幕条").font(.system(size: 12)).foregroundStyle(Palette.secondary)+ Spacer()+ Picker("字幕条", selection: Binding(get: { settings.overlayAuto }, set: { model.setOverlayAuto($0) })) {+ Text("说话时显示").tag(true)+ Text("一直显示").tag(false)+ }+ .pickerStyle(.segmented).labelsHidden().frame(width: 170)}- .pickerStyle(.segmented).labelsHidden().frame(width: 170)}- if settings.overlayAuto {+ if settings.displayMode == "bar" && settings.overlayAuto {HStack {Text("安静多久后收起").font(.system(size: 12)).foregroundStyle(Palette.secondary)Spacer()@@ -181,7 +201,7 @@ struct MenuPanelView: View {}}HStack(spacing: 5) {- Text("随时显示 / 隐藏").foregroundStyle(Palette.secondary)+ Text("切换显示方式").foregroundStyle(Palette.secondary)Spacer()KeyCap(settings.toggleKey.display)}