Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

feat: show a new version at the top of the menu bar panel and send one notification per version (held while a meeting is on), with a clearer dot on the menu bar icon

wqugurubc68dfef9d11
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings
index edfe665..934994b 100644
--- a/Resources/en.lproj/Localizable.strings
+++ b/Resources/en.lproj/Localizable.strings
@@ -844,6 +844,8 @@
"正在下载 %@:%lld%%" = "Downloading %@: %lld%%";
"没能自动更新:%@" = "Couldn’t update automatically: %@";
"有新版本 %@" = "Version %@ is available";
+"知了有新版本 %@" = "Cicada %@ is available";
+"点按安装,完成后自动重新打开" = "Click to install. Cicada reopens when it's done.";
"已是最新版本" = "You’re up to date";
"连不上 GitHub,请稍后再试" = "GitHub can’t be reached; try again later";
"上次检查 %@" = "Last checked %@";
diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.strings
index 5c8f870..6afa0b5 100644
--- a/Resources/ja.lproj/Localizable.strings
+++ b/Resources/ja.lproj/Localizable.strings
@@ -844,6 +844,8 @@
"正在下载 %@:%lld%%" = "%@ をダウンロード中:%lld%%";
"没能自动更新:%@" = "自動アップデートできませんでした:%@";
"有新版本 %@" = "新しいバージョン %@ があります";
+"知了有新版本 %@" = "Cicada %@ が利用可能です";
+"点按安装,完成后自动重新打开" = "クリックでインストール。完了すると自動で開き直します";
"已是最新版本" = "最新バージョンです";
"连不上 GitHub,请稍后再试" = "GitHub に接続できません。後でお試しください";
"上次检查 %@" = "最終確認 %@";
diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.strings
index d2080fe..cdac75d 100644
--- a/Resources/ko.lproj/Localizable.strings
+++ b/Resources/ko.lproj/Localizable.strings
@@ -844,6 +844,8 @@
"正在下载 %@:%lld%%" = "%@ 다운로드 중: %lld%%";
"没能自动更新:%@" = "자동 업데이트 실패: %@";
"有新版本 %@" = "새 버전 %@ 사용 가능";
+"知了有新版本 %@" = "Cicada %@ 버전이 나왔습니다";
+"点按安装,完成后自动重新打开" = "클릭하면 설치하고, 끝나면 다시 열립니다";
"已是最新版本" = "최신 버전입니다";
"连不上 GitHub,请稍后再试" = "GitHub에 연결할 수 없습니다. 나중에 다시 시도하세요";
"上次检查 %@" = "마지막 확인 %@";
diff --git a/Resources/zh-Hans.lproj/Localizable.strings b/Resources/zh-Hans.lproj/Localizable.strings
index 6b7cf4b..c4084be 100644
--- a/Resources/zh-Hans.lproj/Localizable.strings
+++ b/Resources/zh-Hans.lproj/Localizable.strings
@@ -844,6 +844,8 @@
"正在下载 %@:%lld%%" = "正在下载 %@:%lld%%";
"没能自动更新:%@" = "没能自动更新:%@";
"有新版本 %@" = "有新版本 %@";
+"知了有新版本 %@" = "知了有新版本 %@";
+"点按安装,完成后自动重新打开" = "点按安装,完成后自动重新打开";
"已是最新版本" = "已是最新版本";
"连不上 GitHub,请稍后再试" = "连不上 GitHub,请稍后再试";
"上次检查 %@" = "上次检查 %@";
diff --git a/Sources/LiveSubs/AppModel.swift b/Sources/LiveSubs/AppModel.swift
index 3314d82..0eda9d1 100644
--- a/Sources/LiveSubs/AppModel.swift
+++ b/Sources/LiveSubs/AppModel.swift
@@ -137,6 +137,8 @@ final class AppModel: ObservableObject {
private var heldJoin: (seg: Segment, t: Double, translation: String?)?
init() {
+ // A meeting or speaking holds the update notification until it ends (see stop()).
+ updates.busy = { [weak self] in guard let self else { return false }; return self.running || self.speak.phase != .idle }
listen.onSubtitle = { [weak self] src, dst in
// Someone is speaking either way; only the wrong model's words aren't shown.
let visible = self?.listen.hidesSource == true ? "" : src
@@ -520,6 +522,7 @@ final class AppModel: ObservableObject {
notes.finish()
overlay.hide()
refresh()
+ updates.notifyIfDue() // held while the meeting was on
}
func setRunning(_ on: Bool) { on ? start() : requestStop() }
@@ -1650,6 +1653,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, UNUs
model.openOnboarding = { [weak self] in self?.showOnboarding() }
runningObserver = model.$running.combineLatest(model.updates.$update).sink { [weak self] live, update in
self?.statusItem.button?.image = BrandImage.menuBar(live: live, badge: update != nil)
+ self?.statusItem.button?.toolTip = update.map { L("有新版本 \($0.version)") }
}
let poll = Timer(timeInterval: 1.0, repeats: true) { [weak self] _ in
MainActor.assumeIsolated { self?.model.refreshPermissions() }
@@ -1682,8 +1686,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, UNUs
}
nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
- let id = response.notification.request.content.userInfo["session"] as? String
+ let info = response.notification.request.content.userInfo
+ let id = info["session"] as? String
+ let update = info["update"] as? String
await MainActor.run {
+ // "有新版本": the panel shows the download, and install asks first if a meeting is on.
+ if update != nil {
+ if !popover.isShown { togglePopover() }
+ model.updates.install(model: model)
+ return
+ }
showMainWindow()
if let id { model.mainShow = id }
}
diff --git a/Sources/LiveSubs/Onboarding.swift b/Sources/LiveSubs/Onboarding.swift
index b11c0e5..f83096a 100644
--- a/Sources/LiveSubs/Onboarding.swift
+++ b/Sources/LiveSubs/Onboarding.swift
@@ -146,13 +146,18 @@ enum BrandImage {
/// The glyph with an orange dot top right, while an update is available. A coloured dot
/// can't be part of a template image, so the glyph is filled with the label colour instead.
+ /// The dot is cut out of the glyph with a clear ring, so it reads as a badge, not part of the logo.
private static func withBadge(_ glyph: NSImage) -> NSImage {
let image = NSImage(size: glyph.size, flipped: false) { rect in
glyph.draw(in: rect, from: .zero, operation: .sourceOver, fraction: 1)
NSColor.labelColor.setFill()
rect.fill(using: .sourceIn)
+ let dot = NSRect(x: rect.maxX - 7.5, y: rect.maxY - 7.5, width: 7.5, height: 7.5)
+ NSGraphicsContext.current?.compositingOperation = .clear
+ NSBezierPath(ovalIn: dot.insetBy(dx: -1.5, dy: -1.5)).fill()
+ NSGraphicsContext.current?.compositingOperation = .sourceOver
NSColor(red: 0xE8 / 255, green: 0x55 / 255, blue: 0x2B / 255, alpha: 1).setFill()
- NSBezierPath(ovalIn: NSRect(x: rect.maxX - 6, y: rect.maxY - 6, width: 5.5, height: 5.5)).fill()
+ NSBezierPath(ovalIn: dot).fill()
return true
}
image.accessibilityDescription = L("\(appDisplayName)(有新版本)")
diff --git a/Sources/LiveSubs/UpdateViews.swift b/Sources/LiveSubs/UpdateViews.swift
index 4e94f86..10abd41 100644
--- a/Sources/LiveSubs/UpdateViews.swift
+++ b/Sources/LiveSubs/UpdateViews.swift
@@ -1,28 +1,24 @@
import SwiftUI
-/// The panel's update strip, shown only while there is a newer release: install it, watch it
-/// download, or read why installing in place failed (the release page was opened instead).
+/// The panel's update strip, under the header while there is a newer release: install it, watch
+/// it download, or read why installing in place failed (the release page was opened instead).
+/// While a meeting is on it shrinks to one line, so it doesn't push the meeting's controls down.
struct UpdateBanner: View {
@ObservedObject var updates: Updates
- let model: AppModel
+ @ObservedObject var model: AppModel
var body: some View {
if let update = updates.update {
- VStack(alignment: .leading, spacing: 6) {
- HStack(spacing: 8) {
- Circle().fill(Palette.accent).frame(width: 7, height: 7)
- VStack(alignment: .leading, spacing: 2) {
- Text("新版本 \(update.version)").font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.ink)
- Text(detail(update)).font(.system(size: 11)).foregroundStyle(Palette.secondary)
- .fixedSize(horizontal: false, vertical: true)
- }
- Spacer()
- if updates.progress == nil {
- SoftButton(updates.failure == nil ? L("安装") : L("重试")) { updates.install(model: model) }
+ Group {
+ if model.running && updates.progress == nil && updates.failure == nil {
+ HStack(spacing: 8) {
+ Circle().fill(Palette.accent).frame(width: 7, height: 7)
+ Text("新版本 \(update.version)").font(.system(size: 12, weight: .semibold)).foregroundStyle(Palette.ink)
+ Spacer()
+ SoftButton(L("安装"), onGrey: true) { updates.install(model: model) }
}
- }
- if let p = updates.progress {
- ProgressView(value: p).controlSize(.small).tint(Palette.accent).accessibilityLabel(L("下载进度"))
+ } else {
+ full(update)
}
}
.padding(10).frame(maxWidth: .infinity, alignment: .leading)
@@ -31,6 +27,29 @@ struct UpdateBanner: View {
}
}
+ private func full(_ update: UpdateChecker.Update) -> some View {
+ VStack(alignment: .leading, spacing: 8) {
+ HStack(spacing: 8) {
+ Circle().fill(Palette.accent).frame(width: 7, height: 7)
+ Text("新版本 \(update.version)").font(.system(size: 13, weight: .semibold)).foregroundStyle(Palette.ink)
+ Spacer()
+ }
+ Text(detail(update)).font(.system(size: 11)).foregroundStyle(Palette.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ if let p = updates.progress {
+ ProgressView(value: p).controlSize(.small).tint(Palette.accent).accessibilityLabel(L("下载进度"))
+ } else {
+ HStack(spacing: 12) {
+ SoftButton(updates.failure == nil ? L("安装并重新打开") : L("重试"), dark: true) { updates.install(model: model) }
+ Button { NSWorkspace.shared.open(update.url) } label: {
+ Text("更新说明").font(.system(size: 12)).foregroundStyle(Palette.accentInk)
+ }
+ .buttonStyle(.plain)
+ }
+ }
+ }
+ }
+
private func detail(_ update: UpdateChecker.Update) -> String {
if let p = updates.progress { return L("正在下载 \(Int(p * 100))%,完成后自动重新打开") }
if let f = updates.failure { return L("没能自动更新:\(f)。已打开下载页") }
diff --git a/Sources/LiveSubs/Updates.swift b/Sources/LiveSubs/Updates.swift
index 16dc295..8f819f2 100644
--- a/Sources/LiveSubs/Updates.swift
+++ b/Sources/LiveSubs/Updates.swift
@@ -1,4 +1,5 @@
import AppKit
+@preconcurrency import UserNotifications
/// What the panel, the app menu and settings show about updates: a newer release, a manual
/// check's result, download progress, and why installing in place failed.
@@ -21,7 +22,10 @@ final class Updates: ObservableObject {
private(set) lazy var checker: UpdateChecker = UpdateChecker { [weak self] in
self?.update = $0
self?.lastChecked = self?.checker.lastChecked
+ self?.notifyIfDue()
}
+ /// True while a meeting or speaking is on: the notification waits for it to end.
+ var busy: () -> Bool = { false }
private var started = false
static let current = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? ""
@@ -50,6 +54,45 @@ final class Updates: ObservableObject {
return L("\(Int(s / 86_400)) 天前查过")
}
+ /// The version the system notification was last shown for, kept across launches: one per version.
+ private var notified: String? {
+ get { UserDefaults.standard.string(forKey: "updateNotified") }
+ set { UserDefaults.standard.set(newValue, forKey: "updateNotified") }
+ }
+
+ /// Whether a found version still needs its notification: not yet told, and nothing going on.
+ nonisolated static func shouldNotify(_ version: String, notified: String?, busy: Bool) -> Bool {
+ !busy && version != notified
+ }
+
+ /// One system notification per version, for people who never open the panel; a click installs.
+ /// Held while a meeting or speaking is on (stop() calls this again). Screen sharing and Focus
+ /// are the system's to hold: macOS keeps notifications back while the screen is shared.
+ func notifyIfDue() {
+ let center = UNUserNotificationCenter.current()
+ guard let update else {
+ center.removeDeliveredNotifications(withIdentifiers: ["update"])
+ return
+ }
+ guard Self.shouldNotify(update.version, notified: notified, busy: busy()) else {
+ debugLog("update: \(update.version) not notified (told \(notified ?? "-"), busy \(busy()))")
+ return
+ }
+ notified = update.version
+ let content = UNMutableNotificationContent()
+ content.title = L("知了有新版本 \(update.version)")
+ content.body = L("点按安装,完成后自动重新打开")
+ content.userInfo = ["update": update.version]
+ let request = UNNotificationRequest(identifier: "update", content: content, trigger: nil)
+ let version = update.version
+ center.requestAuthorization(options: [.alert]) { granted, _ in
+ guard granted else { debugLog("update: notification not allowed"); return }
+ UNUserNotificationCenter.current().add(request) { error in
+ debugLog(error.map { "update: notification not shown: \($0)" } ?? "update: notified \(version)")
+ }
+ }
+ }
+
func checkNow() {
guard check != .checking else { return }
check = .checking
diff --git a/Sources/LiveSubs/Views.swift b/Sources/LiveSubs/Views.swift
index 248c5a8..336e84a 100644
--- a/Sources/LiveSubs/Views.swift
+++ b/Sources/LiveSubs/Views.swift
@@ -188,6 +188,8 @@ struct MenuPanelView: View {
// In subtitle-bar mode this is where the bar sends you to pick.
if model.running { LanguageNotice(model: model) }
if model.roomPrompt { roomPromptStrip }
+ // Right under the header: below the settings it was easy to miss.
+ UpdateBanner(updates: model.updates, model: model)
VStack(spacing: 6) {
ChoiceRow(label: L("听哪里"), value: settings.listensToRoom ? L("会议室") : L("电脑声音"),
@@ -246,8 +248,6 @@ struct MenuPanelView: View {
if settings.displayMode != "notes" || !model.ling.hasKey { displayCard }
}
- UpdateBanner(updates: model.updates, model: model)
-
Divider()
footer
diff --git a/Tests/LiveSubsTests/UpdateTests.swift b/Tests/LiveSubsTests/UpdateTests.swift
index 2812bab..390b43e 100644
--- a/Tests/LiveSubsTests/UpdateTests.swift
+++ b/Tests/LiveSubsTests/UpdateTests.swift
@@ -76,6 +76,14 @@ import Testing
#expect(Updates.checkedAgo(now.addingTimeInterval(-2 * 3600 - 59), now: now) == L("2 小时前查过"))
#expect(Updates.checkedAgo(now.addingTimeInterval(-3 * 86_400), now: now) == L("3 天前查过"))
}
+
+ /// One notification per version, and none while a meeting or speaking is on.
+ @Test func notifiesOncePerVersionWhenIdle() {
+ #expect(Updates.shouldNotify("1.1.0", notified: nil, busy: false))
+ #expect(Updates.shouldNotify("1.2.0", notified: "1.1.0", busy: false))
+ #expect(!Updates.shouldNotify("1.1.0", notified: "1.1.0", busy: false))
+ #expect(!Updates.shouldNotify("1.1.0", notified: nil, busy: true))
+ }
}
@Suite struct UpdateMinimumSystemTests {