知了 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: the live notes window no longer covers the welcome guide's buttons on small screens
wquguru4acfab7e5c86
diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swiftindex 2f9c3fe..2679cde 100644--- a/Sources/Cicada/AppModel.swift+++ b/Sources/Cicada/AppModel.swift@@ -802,7 +802,7 @@ final class AppModel: ObservableObject {/// Asked for by name (菜单栏面板 打开, 窗口 › 实时纪要): shown even before anyone speaks, and/// without touching 显示方式, so 不显示 or 字幕条 is back at the next meeting.- func openNotesWindow() { notesWindow.show() }+ func openNotesWindow() { notesWindow.show(asked: true) }/// The listening pill: bring back what shows this meeting, the subtitle bar in 字幕条 mode,/// else the notes window (in 不显示 just this once).@@ -2167,12 +2167,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, UNUs}NSApp.setActivationPolicy(.regular)onboardingWindow?.makeKeyAndOrderFront(nil)+ // After it's on screen: a notes window already showing has to make way.+ model.notesWindow.avoid(onboardingWindow)NSApp.activate()}func windowWillClose(_ notification: Notification) {let w = notification.object as? NSWindowupdateActivationPolicy(closing: w)+ if w == onboardingWindow { model.notesWindow.avoid(nil) }if w == onboardingWindow, !model.relaunching {model.sample.stop()UserDefaults.standard.set(true, forKey: "onboarded")diff --git a/Sources/Cicada/NotesWindow.swift b/Sources/Cicada/NotesWindow.swiftindex 53c712d..6a7fe67 100644--- a/Sources/Cicada/NotesWindow.swift+++ b/Sources/Cicada/NotesWindow.swift@@ -21,6 +21,9 @@ final class NotesWindowController: NSObject, NSWindowDelegate {}var isVisible: Bool { panel?.isVisible ?? false }+ /// Not read back from the panel: its hosting view lowers `minSize` to the content's.+ static let minWidth: CGFloat = 300+ private static let autosave = "LiveSubsNotes"var layout: Layout {let w = panel?.frame.width ?? 460@@ -42,7 +45,8 @@ final class NotesWindowController: NSObject, NSWindowDelegate {commands.send(command)}- func show() {+ /// `asked`: opened by name, so shown even where it can't keep clear of the onboarding window.+ func show(asked: Bool = false) {guard let model else { return }if panel == nil {let p = NotesPanel(contentRect: defaultFrame(), styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView, .nonactivatingPanel],@@ -63,25 +67,97 @@ final class NotesWindowController: NSObject, NSWindowDelegate {// Others never see it when you share your screen, unless the user lets recordings in.p.sharingType = model.settings.notesCapturable ? .readOnly : .nonep.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]- p.minSize = NSSize(width: 300, height: 180)+ p.minSize = NSSize(width: Self.minWidth, height: 180)p.backgroundColor = .whitep.contentView = FirstClickHostingView(rootView: NotesWindowView(model: model, engine: model.notes, store: model.store, settings: model.settings,commands: commands.eraseToAnyPublisher(),setWidth: { [weak self] w, h in self?.resize(width: w, height: h) }))- p.setFrameAutosaveName("LiveSubsNotes")- if !p.setFrameUsingName("LiveSubsNotes") { p.setFrame(defaultFrame(), display: false) }+ p.setFrameAutosaveName(Self.autosave)+ if !p.setFrameUsingName(Self.autosave) { p.setFrame(defaultFrame(), display: false) }panel = p}+ if !keepClear() && !asked { return }+ waiting = falsepanel?.orderFrontRegardless()model.notesVisibilityChanged(true)}func hide() {+ waiting = falsepanel?.orderOut(nil)model?.notesVisibilityChanged(false)}+ // MARK: Keeping clear of the onboarding window++ /// The onboarding window while it's open. The panel floats above it and can't be clicked+ /// through, so it must never sit on it: on a 1024×768 screen the sidebar covered 继续.+ private weak var avoiding: NSWindow?+ /// The user's own frame, put back when the window closes, and where we put the panel instead.+ private var ownFrame: NSRect?+ private var placedFrame: NSRect?+ /// Asked to show while there was no room beside the window: shown once it closes.+ private var waiting = false++ /// `window`: the onboarding window as it opens; nil as it closes.+ func avoid(_ window: NSWindow?) {+ avoiding = window+ if window != nil {+ if panel?.isVisible == true && !keepClear() {+ panel?.orderOut(nil)+ model?.notesVisibilityChanged(false)+ }+ return+ }+ if let ownFrame, let p = panel {+ // Unless the user has moved it since; either way it's remembered again from here.+ if p.frame == placedFrame { p.setFrame(ownFrame, display: true) }+ p.setFrameAutosaveName(Self.autosave)+ }+ ownFrame = nil+ placedFrame = nil+ if waiting {+ waiting = false+ show()+ }+ }++ /// Moves the panel beside the window it avoids, or returns false (and waits) when neither side has room.+ private func keepClear() -> Bool {+ guard let p = panel, let w = avoiding, w.isVisible,+ let screen = w.screen ?? NSScreen.main, p.frame.intersects(w.frame) else { return true }+ guard let r = Self.beside(w.frame, in: screen.visibleFrame, width: p.frame.width, minWidth: Self.minWidth) else {+ waiting = true+ debugLog("notes window waits: no room beside onboarding \(w.frame) in \(screen.visibleFrame)")+ return false+ }+ if ownFrame == nil {+ ownFrame = p.frame+ // Not remembered: quit during onboarding and the next meeting still opens where the user left it.+ p.setFrameAutosaveName("")+ }+ p.setFrame(r, display: true)+ placedFrame = p.frame+ return true+ }++ /// The panel beside `window` within `visible`: right of it, else left, a gap away and as tall+ /// as the screen allows, no wider than `width`; nil when neither side has `minWidth`.+ nonisolated static func beside(_ window: NSRect, in visible: NSRect, width: CGFloat, minWidth: CGFloat) -> NSRect? {+ let gap: CGFloat = 12+ let right = visible.maxX - window.maxX - 2 * gap, left = window.minX - visible.minX - 2 * gap+ let y = visible.minY + gap, h = visible.height - 2 * gap+ if right >= minWidth {+ let w = min(width, right)+ return NSRect(x: visible.maxX - gap - w, y: y, width: w, height: h)+ }+ if left >= minWidth {+ return NSRect(x: visible.minX + gap, y: y, width: min(width, left), height: h)+ }+ return nil+ }+/// Closed with its close button (hide() doesn't come here): the meeting goes on in the/// records window, so the notes stay one click away.func windowWillClose(_ notification: Notification) {diff --git a/Tests/CicadaTests/NotesWindowTests.swift b/Tests/CicadaTests/NotesWindowTests.swiftindex 474cb48..8abdef3 100644--- a/Tests/CicadaTests/NotesWindowTests.swift+++ b/Tests/CicadaTests/NotesWindowTests.swift@@ -3,6 +3,25 @@ import Testing@testable import Cicada@Suite struct NotesWindowTests {+ @Test func notesWindowStandsBesideOnboardingOnlyWhereItFits() {+ let onboarding = { (screen: NSRect) in+ NSRect(x: screen.midX - 430, y: screen.minY + 12, width: 860, height: 668)+ }+ // 1024×768 (the menu bar and Dock taken): 82 pt either side, no room, so it waits.+ let small = NSRect(x: 0, y: 57, width: 1024, height: 686)+ #expect(NotesWindowController.beside(onboarding(small), in: small, width: 460, minWidth: 300) == nil)+ // 1920 wide: the full sidebar to the right, clear of the window.+ let big = NSRect(x: 0, y: 0, width: 1920, height: 1055)+ let r = NotesWindowController.beside(onboarding(big), in: big, width: 460, minWidth: 300)+ #expect(r?.width == 460)+ #expect(r.map { !$0.intersects(onboarding(big)) && big.contains($0) } == true)+ // Room only on the left (the window pushed right): narrower, still clear.+ let pushed = NSRect(x: 1600 - 860, y: 12, width: 860, height: 668)+ let l = NotesWindowController.beside(pushed, in: NSRect(x: 0, y: 0, width: 1600, height: 900), width: 460, minWidth: 300)+ #expect(l?.minX == 12)+ #expect(l.map { !$0.intersects(pushed) } == true)+ }+private func line(_ id: String, _ t: Double, _ speaker: String = "them", _ src: String = "a line") -> TranscriptLine {TranscriptLine(id: id, t: t, speaker: speaker, src: src, dst: nil, srcLang: "en", dstLang: "zh-CN")}