Skip to content

Doubao-powered voice input for Linux, Wayland and Omarchy

fix(macOS): hide Dock and app switcher entries after closing windows

quanru80cbddc97352
diff --git a/README.md b/README.md
index 64e8642..ce439c2 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,10 @@
> **macOS development preview:** A native Swift menu-bar client supports Doubao web sign-in, official Volcengine and Deepgram recognition, optional polishing, configurable shortcuts, microphone selection and input recovery. See the [Mac build and usage guide](macos/README.zh-CN.md) (Chinese). No Developer ID signed or notarized Mac release is available yet.
+On macOS, closing the last settings or sign-in window keeps dictation available
+from the menu bar while removing the app from the Dock and Cmd+Tab. Opening a
+window restores both entries; minimized windows keep their Dock entry.
+
[Website](https://doubao-say.lifeos.md/) · [简体中文](README.zh-CN.md)
![Doubao Say voice input running on Omarchy Linux](images/readme-en.jpeg)
diff --git a/macos/Package.swift b/macos/Package.swift
index 28d4320..ad7f8db 100644
--- a/macos/Package.swift
+++ b/macos/Package.swift
@@ -1,6 +1,6 @@
// swift-tools-version: 5.9
import PackageDescription
let package = Package(name: "DoubaoSayCore", platforms: [.macOS(.v13)], targets: [
- .target(name: "DoubaoSayCore", path: "Sources", exclude: ["APIASRClient.swift", "ASRParamsStore.swift", "AppState.swift", "AudioCaptureManager.swift", "AudioDevices.swift", "DoubaoASRClient.swift", "DoubaoSayApp.swift", "HotkeyManager.swift", "OverlayPanel.swift", "OverlayView.swift", "ListeningWaveform.swift", "PasteHelper.swift", "InputTargetCapture.swift", "SecretStore.swift", "SettingsWindow.swift", "StartupService.swift", "TranscriptionManager.swift", "UpdateInstaller.swift", "VibekeyReceiver.swift", "WebViewManager.swift", "WindowCapture.swift", "PersonalViews.swift", "SpeechEvaluationView.swift", "SpeechEvaluationModel.swift"], sources: ["InputLatency.swift", "SpeechEvaluation.swift", "VoiceMotion.swift", "HotkeyGesture.swift", "ASRResponse.swift", "FinalResultGate.swift", "ShortcutGesture.swift", "MacSettings.swift", "Strings.swift", "PolishDefaults.swift", "PolishClient.swift", "PolishCoordinator.swift", "SeedProtocol.swift", "VibekeyProtocol.swift", "UpdateRelease.swift", "UpdateChecker.swift", "PersonalData.swift", "PersonalCorrections.swift"]),
+ .target(name: "DoubaoSayCore", path: "Sources", exclude: ["ApplicationPresence.swift", "APIASRClient.swift", "ASRParamsStore.swift", "AppState.swift", "AudioCaptureManager.swift", "AudioDevices.swift", "DoubaoASRClient.swift", "DoubaoSayApp.swift", "HotkeyManager.swift", "OverlayPanel.swift", "OverlayView.swift", "ListeningWaveform.swift", "PasteHelper.swift", "InputTargetCapture.swift", "SecretStore.swift", "SettingsWindow.swift", "StartupService.swift", "TranscriptionManager.swift", "UpdateInstaller.swift", "VibekeyReceiver.swift", "WebViewManager.swift", "WindowCapture.swift", "PersonalViews.swift", "SpeechEvaluationView.swift", "SpeechEvaluationModel.swift"], sources: ["InputLatency.swift", "SpeechEvaluation.swift", "VoiceMotion.swift", "HotkeyGesture.swift", "ASRResponse.swift", "FinalResultGate.swift", "ShortcutGesture.swift", "MacSettings.swift", "Strings.swift", "PolishDefaults.swift", "PolishClient.swift", "PolishCoordinator.swift", "SeedProtocol.swift", "VibekeyProtocol.swift", "UpdateRelease.swift", "UpdateChecker.swift", "PersonalData.swift", "PersonalCorrections.swift"]),
.testTarget(name: "DoubaoSayCoreTests", dependencies: ["DoubaoSayCore"], path: "Tests", exclude: ["Transport", "Live", "Network", "Settings", "Input"])
])
diff --git a/macos/README.zh-CN.md b/macos/README.zh-CN.md
index ca6e256..909a8f8 100644
--- a/macos/README.zh-CN.md
+++ b/macos/README.zh-CN.md
@@ -17,7 +17,7 @@ open 'build/macos/arm64/Doubao Say.app'
1. 打开应用会显示“设置”和 Dock 图标;已运行时再次打开也会恢复设置窗。关闭设置窗后仍可使用菜单栏和全局快捷键。在“识别服务”中选择豆包账号、火山引擎官方 API 或 Deepgram Nova-3(英语)。豆包使用登录窗口;官方服务填写自己的 API Key,可先测试连接。火山资源 `volc.seedasr.sauc.duration` 已内置,不需要 App ID。Deepgram 使用美式英语、标点和智能格式化。
2. “使用准备”顶部四个步骤均可点击切换;检查或录音进行时暂时禁用切换,完成设置仍需通过全部检查。设置会自动保存,无需点击保存按钮。允许麦克风访问,并从“启用全局快捷键”授予辅助功能权限。系统要求本人输入密码时在系统弹窗完成,不向应用填写系统密码。
-3. 在“使用准备”中选择麦克风,先进行三秒本地检查,再进行五秒语音测试。语音测试会向已保存的识别服务发送音频,结果只显示在软件内,不粘贴,也不发送回车。全部检查完成后点击“完成设置”,后续打开应用仍显示设置窗。
+3. 在“使用准备”中选择麦克风,先进行三秒本地检查,再进行五秒语音测试。语音测试会向已保存的识别服务发送音频,结果只显示在软件内,不粘贴,也不发送回车。全部检查完成后点击“完成设置”,后续打开应用仍显示设置窗。关闭最后一个设置或登录窗口后,应用保留菜单栏运行,并从 Dock 和 Cmd+Tab 隐藏;通过菜单栏或重新打开应用显示窗口时恢复。最小化窗口仍保留 Dock 入口。
4. 在目标应用的普通文本输入框中放好光标。默认 `Control+Option+空格`,可在“快捷键”中录制其他组合或单独修饰键;选键不使用麦克风。
5. 短按切换录音;按住达到默认 350 毫秒后说话,松开结束。开始录音时可用默认 300 毫秒的双击识别阈值,可调整两项阈值或关闭双击。语音输入期间,其他按键(包括 `Esc`、回车、修饰键和快捷键组合)统一结束录音并上屏,不执行原有按键操作,也不额外发送回车。整个组合及其松开事件会被拦截,完成输入后恢复正常键盘操作。VibeKey 的按钮和旋钮也使用同一规则。非语音输入状态下,`Esc` 可关闭保留文字的浮窗,空闲时双击仍可发送回车。单次录音最多 60 秒。
diff --git a/macos/Sources/ApplicationPresence.swift b/macos/Sources/ApplicationPresence.swift
new file mode 100644
index 0000000..be813a4
--- /dev/null
+++ b/macos/Sources/ApplicationPresence.swift
@@ -0,0 +1,20 @@
+import AppKit
+
+/// Only interactive windows keep the app in the Dock and application switcher.
+/// Dictation overlays and the menu bar item do not participate.
+@MainActor
+enum ApplicationPresence {
+ private static let windows = NSHashTable<NSWindow>.weakObjects()
+
+ static func willShow(_ window: NSWindow) {
+ windows.add(window)
+ if NSApp.activationPolicy() != .regular { NSApp.setActivationPolicy(.regular) }
+ }
+
+ static func didHide(_ window: NSWindow) {
+ windows.remove(window)
+ if windows.allObjects.isEmpty && NSApp.activationPolicy() != .accessory {
+ NSApp.setActivationPolicy(.accessory)
+ }
+ }
+}
diff --git a/macos/Sources/SettingsWindow.swift b/macos/Sources/SettingsWindow.swift
index 79e77dc..96fedcf 100644
--- a/macos/Sources/SettingsWindow.swift
+++ b/macos/Sources/SettingsWindow.swift
@@ -658,15 +658,19 @@ final class SettingsWindow: NSObject, NSWindowDelegate {
}
func show(refresh: Bool = true) {
if refresh { model.refresh() }
+ ApplicationPresence.willShow(window)
if window.isMiniaturized { window.deminiaturize(nil) }
NSApp.activate(ignoringOtherApps: true)
window.makeKeyAndOrderFront(nil)
window.makeFirstResponder(nil)
}
- func windowWillClose(_ notification: Notification) { model.closeEditor() }
+ func windowWillClose(_ notification: Notification) {
+ model.closeEditor()
+ ApplicationPresence.didHide(window)
+ }
var isVisible: Bool { window.isVisible }
func close() { model.stopTests(); window.close() }
- func hide() { window.orderOut(nil) }
+ func hide() { window.orderOut(nil); ApplicationPresence.didHide(window) }
func updateTitle() { window.title = "Doubao Say · " + L("Settings", "设置") }
func captureImage(to path: String) {
WindowCapture.request(window)
diff --git a/macos/Sources/WebViewManager.swift b/macos/Sources/WebViewManager.swift
index 3fcdd07..7b82f18 100644
--- a/macos/Sources/WebViewManager.swift
+++ b/macos/Sources/WebViewManager.swift
@@ -2,7 +2,7 @@ import AppKit
import WebKit
@MainActor
-final class WebViewManager: NSObject, WKScriptMessageHandler, WKNavigationDelegate, WKUIDelegate {
+final class WebViewManager: NSObject, WKScriptMessageHandler, WKNavigationDelegate, WKUIDelegate, NSWindowDelegate {
private let appState: AppState
private var webView: WKWebView?
private var window: NSWindow?
@@ -31,19 +31,26 @@ final class WebViewManager: NSObject, WKScriptMessageHandler, WKNavigationDelega
let panel = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 1000, height: 720),
styleMask: [.titled, .closable, .resizable], backing: .buffered, defer: false)
panel.title = L("Doubao Say — Sign in", "豆包说 — 登录")
- panel.isReleasedWhenClosed = false; panel.contentView = view
+ panel.isReleasedWhenClosed = false; panel.contentView = view; panel.delegate = self
window = panel; webView = view
view.load(URLRequest(url: URL(string: "https://www.doubao.com/chat")!))
}
+ if let window { ApplicationPresence.willShow(window) }
window?.center(); window?.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
}
- func hideLoginWindow() { window?.orderOut(nil) }
+ func windowWillClose(_ notification: Notification) {
+ if let window { ApplicationPresence.didHide(window) }
+ }
+ func hideLoginWindow() {
+ window?.orderOut(nil)
+ if let window { ApplicationPresence.didHide(window) }
+ }
func destroyWebView() {
webView?.stopLoading()
webView?.configuration.userContentController.removeScriptMessageHandler(forName: "asrHandler")
webView?.navigationDelegate = nil; webView?.uiDelegate = nil
- window?.orderOut(nil); window?.contentView = nil
+ hideLoginWindow(); window?.contentView = nil
window = nil; webView = nil
}
func extractASRParams() async -> DoubaoASRParams? {
diff --git a/macos/Tests/Settings/WindowPresenceCheck.swift b/macos/Tests/Settings/WindowPresenceCheck.swift
new file mode 100644
index 0000000..56e63cc
--- /dev/null
+++ b/macos/Tests/Settings/WindowPresenceCheck.swift
@@ -0,0 +1,53 @@
+import AppKit
+
+@main struct WindowPresenceCheck {
+ @MainActor static func main() {
+ let app = NSApplication.shared
+ app.setActivationPolicy(.regular)
+ let settings = SettingsWindow(state: AppState())
+ settings.model.apply = { _, _, _ in }
+ Task { @MainActor in
+ func pause() async { try? await Task.sleep(nanoseconds: 500_000_000) }
+ settings.show(refresh: false)
+ await pause()
+ precondition(app.activationPolicy() == .regular && settings.isVisible)
+ settings.close()
+ await pause()
+ print("AFTER_CLOSE: \(app.activationPolicy().rawValue)")
+ precondition(app.activationPolicy() == .accessory, "Closing the last window must leave Dock and Cmd+Tab")
+ precondition(NSRunningApplication.current.activationPolicy == .accessory)
+ settings.show(refresh: false)
+ await pause()
+ precondition(app.activationPolicy() == .regular && settings.isVisible, "Reopening must restore the window and application presence")
+ settings.hide()
+ await pause()
+ print("AFTER_HIDE: \(app.activationPolicy().rawValue)")
+ precondition(app.activationPolicy() == .accessory)
+ let overlay = OverlayPanel(appState: AppState())
+ overlay.showOverlay()
+ await pause()
+ precondition(app.activationPolicy() == .accessory, "Dictation overlay must not restore Dock presence")
+ overlay.hideOverlay()
+ let other = SettingsWindow(state: AppState())
+ other.model.apply = { _, _, _ in }
+ settings.show(refresh: false)
+ other.show(refresh: false)
+ settings.close()
+ await pause()
+ precondition(app.activationPolicy() == .regular && other.isVisible, "A second interactive window must keep Dock presence")
+ guard let native = app.windows.first(where: { $0.isVisible && $0.title.hasPrefix("Doubao Say") }) else { fatalError("Missing interactive window") }
+ native.miniaturize(nil)
+ await pause()
+ precondition(app.activationPolicy() == .regular, "Minimizing must retain Dock access")
+ other.show(refresh: false)
+ await pause()
+ precondition(!native.isMiniaturized && other.isVisible)
+ other.close()
+ await pause()
+ precondition(app.activationPolicy() == .accessory)
+ print("PASS: close, reopen, hide, multiple windows, minimize and overlay lifecycle")
+ app.terminate(nil)
+ }
+ app.run()
+ }
+}
diff --git a/macos/Tests/Settings/check.sh b/macos/Tests/Settings/check.sh
index b835e27..0aa5cf0 100644
--- a/macos/Tests/Settings/check.sh
+++ b/macos/Tests/Settings/check.sh
@@ -15,3 +15,8 @@ xcrun swiftc -swift-version 5 -target "$(uname -m)-apple-macos13.0" \
-module-cache-path build/macos/module-cache \
macos/Sources/AudioDevices.swift macos/Sources/AudioCaptureManager.swift \
macos/Tests/Live/MicrophoneRouteCheck.swift -o build/macos/tests/microphone-route-check
+
+# Compile the opt-in application-presence check without opening windows in CI.
+xcrun swiftc -swift-version 5 -target "$(uname -m)-apple-macos13.0" \
+ -module-cache-path build/macos/module-cache \
+ "${sources[@]}" macos/Tests/Settings/WindowPresenceCheck.swift -o build/macos/tests/window-presence-check