Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

Overlay swapped with notch behavior for all modes and bug fixes

altic-dev1d0387e5b6a3
diff --git a/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
index 37abfa7c..1d65ecc4 100644
--- a/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
+++ b/Fluid.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
@@ -1,5 +1,5 @@
{
- "originHash" : "0e9edc93872d7a92fcff2d2765dc22155b0d0f13274eb53dcac8ebcf9819b368",
+ "originHash" : "08725b27cbcc3e1db547ffd44b1132eb063ef3464f375f35265fbfffd0613368",
"pins" : [
{
"identity" : "appupdater",
@@ -10,6 +10,15 @@
"version" : "1.1.1"
}
},
+ {
+ "identity" : "dynamicnotchkit",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/MrKai77/DynamicNotchKit",
+ "state" : {
+ "revision" : "3c405930fd4d9f8498303683f32492c26d3a9b2b",
+ "version" : "1.0.0"
+ }
+ },
{
"identity" : "eventsource",
"kind" : "remoteSourceControl",
diff --git a/Sources/Fluid/AppDelegate.swift b/Sources/Fluid/AppDelegate.swift
index b2337c74..3037ffd3 100644
--- a/Sources/Fluid/AppDelegate.swift
+++ b/Sources/Fluid/AppDelegate.swift
@@ -95,7 +95,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
if result.hasUpdate {
DebugLogger.shared.info("✅ Update available: \(result.latestVersion)", source: "AppDelegate")
// Show update notification on main thread
- await showUpdateNotification(version: result.latestVersion)
+ showUpdateNotification(version: result.latestVersion)
} else {
DebugLogger.shared.info("✅ App is up to date", source: "AppDelegate")
}
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index a9e83720..9ed03e8f 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -12,13 +12,6 @@ import Combine
import CoreAudio
import CoreGraphics
-// Visualization types moved to UI/Visualization
-
-// Removed inline default animations (now modular)
-
-// Import the talking animations from TalkingAnimations.swift
-// The TalkingAudioVisualizationView is now defined in TalkingAnimations.swift
-
// MARK: - Sidebar Item Enum
enum SidebarItem: Hashable {
@@ -32,44 +25,6 @@ enum SidebarItem: Hashable {
case rewriteMode
}
-// MARK: - Listening Overlay View (using modular components)
-struct ListeningOverlayView: View
-{
- var audioLevelPublisher: AnyPublisher<CGFloat, Never>?
-
- var body: some View
- {
- TalkingListeningOverlayView(
- audioLevelPublisher: audioLevelPublisher ?? Empty().eraseToAnyPublisher()
- )
- }
-}
-
-// MARK: - Example of switching animation styles
-/*
-// To use a different animation, simply replace the ListeningOverlayView implementation:
-
-struct PulseListeningOverlayView: View {
- let audioLevelPublisher: AnyPublisher<CGFloat, Never>
-
- var body: some View {
- PulseAudioVisualizationView(
- audioLevelPublisher: audioLevelPublisher ?? Empty().eraseToAnyPublisher(),
- config: PulseAnimationConfig()
- )
- }
-}
-
-// Then update ContentView to use PulseListeningOverlayView instead of ListeningOverlayView
-// in the .onChange modifier where the overlay is shown.
-*/
-
-// ListeningOverlayController moved to Services/
-
-// HotkeyShortcut moved to Models/
-
-// GlobalHotkeyManager moved to Services/
-
// MARK: - Minimal FluidAudio ASR Service (finalized text, macOS)
// MARK: - Saved Provider Model
@@ -530,10 +485,6 @@ struct ContentView: View {
DebugLogger.shared.debug("Hotkey manager initialized: \(self.hotkeyManagerInitialized)", source: "ContentView")
}
}
- .onChange(of: enableStreamingPreview) { enabled in
- // Sync streaming preview setting to MenuBarManager's overlay
- menuBarManager.updateOverlayPreviewSetting(enabled)
- }
}
private func resetPendingShortcutState()
@@ -2304,14 +2255,16 @@ struct ContentView: View {
let wasCommandMode = isRecordingForCommand
if wasRewriteMode {
isRecordingForRewrite = false
- menuBarManager.setOverlayMode(.dictation) // Reset overlay mode
+ // Don't reset overlay mode here - let it stay colored until it hides
}
if wasCommandMode {
isRecordingForCommand = false
- menuBarManager.setOverlayMode(.dictation) // Reset overlay mode
+ // Don't reset overlay mode here - let it stay colored until it hides
}
// Stop the ASR service and wait for transcription to complete
+ // This will set isRunning = false, which triggers overlay hide
+ // The overlay will hide while still showing the correct mode color (no gray transition)
let transcribedText = await asr.stop()
guard transcribedText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false else {
@@ -2414,6 +2367,11 @@ struct ContentView: View {
// Capture app context at start to avoid mismatches if the user switches apps mid-session
private func startRecording() {
+ // Ensure normal dictation mode is set (command/rewrite modes set their own)
+ if !isRecordingForCommand && !isRecordingForRewrite {
+ menuBarManager.setOverlayMode(.dictation)
+ }
+
let info = getCurrentAppInfo()
recordingAppInfo = info
DebugLogger.shared.debug("Captured recording app context: app=\(info.name), bundleId=\(info.bundleId), title=\(info.windowTitle)", source: "ContentView")
@@ -2906,6 +2864,9 @@ struct ContentView: View {
shortcut: hotkeyShortcut,
commandModeShortcut: commandModeHotkeyShortcut,
rewriteModeShortcut: rewriteModeHotkeyShortcut,
+ startRecordingCallback: {
+ self.startRecording()
+ },
stopAndProcessCallback: {
await stopAndProcessTranscription()
},
diff --git a/Sources/Fluid/Services/GlobalHotkeyManager.swift b/Sources/Fluid/Services/GlobalHotkeyManager.swift
index af4a99ed..002d4109 100644
--- a/Sources/Fluid/Services/GlobalHotkeyManager.swift
+++ b/Sources/Fluid/Services/GlobalHotkeyManager.swift
@@ -9,6 +9,7 @@ final class GlobalHotkeyManager: NSObject
private var shortcut: HotkeyShortcut
private var commandModeShortcut: HotkeyShortcut
private var rewriteModeShortcut: HotkeyShortcut
+ private var startRecordingCallback: (() async -> Void)?
private var stopAndProcessCallback: (() async -> Void)?
private var commandModeCallback: (() async -> Void)?
private var rewriteModeCallback: (() async -> Void)?
@@ -30,6 +31,7 @@ final class GlobalHotkeyManager: NSObject
shortcut: HotkeyShortcut,
commandModeShortcut: HotkeyShortcut,
rewriteModeShortcut: HotkeyShortcut,
+ startRecordingCallback: (() async -> Void)? = nil,
stopAndProcessCallback: (() async -> Void)? = nil,
commandModeCallback: (() async -> Void)? = nil,
rewriteModeCallback: (() async -> Void)? = nil
@@ -39,6 +41,7 @@ final class GlobalHotkeyManager: NSObject
self.shortcut = shortcut
self.commandModeShortcut = commandModeShortcut
self.rewriteModeShortcut = rewriteModeShortcut
+ self.startRecordingCallback = startRecordingCallback
self.stopAndProcessCallback = stopAndProcessCallback
self.commandModeCallback = commandModeCallback
self.rewriteModeCallback = rewriteModeCallback
@@ -470,7 +473,12 @@ final class GlobalHotkeyManager: NSObject
}
else
{
- self.asrService.start()
+ // Use callback if available, otherwise fallback to direct start
+ if let callback = self.startRecordingCallback {
+ await callback()
+ } else {
+ self.asrService.start()
+ }
}
}
}
@@ -481,7 +489,12 @@ final class GlobalHotkeyManager: NSObject
guard let self = self else { return }
if !self.asrService.isRunning
{
- self.asrService.start()
+ // Use callback if available, otherwise fallback to direct start
+ if let callback = self.startRecordingCallback {
+ await callback()
+ } else {
+ self.asrService.start()
+ }
}
}
}
diff --git a/Sources/Fluid/Services/ListeningOverlayController.swift b/Sources/Fluid/Services/ListeningOverlayController.swift
deleted file mode 100644
index 984db2d6..00000000
--- a/Sources/Fluid/Services/ListeningOverlayController.swift
+++ /dev/null
@@ -1,432 +0,0 @@
-import AppKit
-
-enum OverlayMode: String {
- case dictation = "Dictation"
- case rewrite = "Rewrite"
- case write = "Write" // No text selected - improve spoken text
- case command = "Command"
-}
-
-final class ListeningOverlayController
-{
- private var panel: NSPanel?
- private var asrService: ASRService
- private var line1TextField: NSTextField? // Top - faded (previous)
- private var line2TextField: NSTextField? // Bottom - bright (current)
- private var previousText: String = ""
- private var unifiedContainer: NSView?
- private var orbView: NSView?
- private var isShowingPreview: Bool = true
- private var modeLabel: NSTextField?
- private var currentMode: OverlayMode = .dictation
-
- init(asrService: ASRService)
- {
- self.asrService = asrService
- }
-
- func setMode(_ mode: OverlayMode) {
- currentMode = mode
- updateModeLabel()
- }
-
- func show(with view: NSView, showPreview: Bool = true)
- {
- // CRITICAL: Always clean up existing panel first to prevent duplicates
- if let existingPanel = panel {
- existingPanel.orderOut(nil)
- existingPanel.contentView = nil
- panel = nil
- }
-
- isShowingPreview = showPreview
-
- // Dynamic sizing based on preview state
- let width: CGFloat = 340
- let height: CGFloat = showPreview ? 100 : 90 // Compact for 2 lines
- let orbY: CGFloat = showPreview ? 40 : 10
-
- // Create fresh panel with dynamic size
- let style: NSWindow.StyleMask = [.borderless, .nonactivatingPanel]
- let p = NSPanel(contentRect: NSRect(x: 0, y: 0, width: width, height: height),
- styleMask: style,
- backing: .buffered,
- defer: false)
- p.level = .statusBar
- p.isOpaque = false
- p.hasShadow = true
- p.hidesOnDeactivate = false
- p.ignoresMouseEvents = true
- p.collectionBehavior = [.canJoinAllSpaces, .transient, .fullScreenAuxiliary]
- p.backgroundColor = .clear
- p.titleVisibility = .hidden
- p.titlebarAppearsTransparent = true
- panel = p
-
- // CRITICAL FIX: Create ONE unified container with background for both orb and text
- let container = NSView(frame: NSRect(x: 0, y: 0, width: width, height: height))
- container.wantsLayer = true
- container.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.85).cgColor
- container.layer?.cornerRadius = 12
- unifiedContainer = container
-
- // Create inner container for layout
- let containerView = NSView(frame: NSRect(x: 0, y: 0, width: width, height: height))
- container.addSubview(containerView)
-
- // Add SwiftUI hosting view to container (at top, no background)
- view.frame = NSRect(x: 0, y: orbY, width: width, height: 70)
- containerView.addSubview(view)
- orbView = view
-
- // Add mode indicator label (top-right corner, small)
- setupModeLabel(in: containerView, width: width)
-
- // Add text fields to container (at bottom) - only if preview enabled
- if showPreview {
- setupTranscriptionTextField(in: containerView)
- }
-
- panel?.contentView = container
- positionCenteredLower()
-
- // Set initial state for entrance animation
- container.wantsLayer = true
- container.layer?.anchorPoint = CGPoint(x: 0.5, y: 0.5)
- container.alphaValue = 0.0
-
- // Apply initial transform: scale 0.85 and translate Y -10px
- let initialTransform = CATransform3DIdentity
- let scaledTransform = CATransform3DScale(initialTransform, 0.85, 0.85, 1.0)
- let translatedTransform = CATransform3DTranslate(scaledTransform, 0, -10, 0)
- container.layer?.transform = translatedTransform
-
- panel?.orderFrontRegardless()
-
- // Animate entrance with spring effect
- NSAnimationContext.runAnimationGroup({ context in
- context.duration = 0.3
- context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
- context.allowsImplicitAnimation = true
-
- // Animate to final state: scale 1.0, opacity 1.0, Y position 0
- container.animator().alphaValue = 1.0
- container.layer?.transform = CATransform3DIdentity
- })
- }
-
- func hide()
- {
- guard let container = unifiedContainer else {
- panel?.orderOut(nil)
- return
- }
-
- // Animate exit before hiding panel
- NSAnimationContext.runAnimationGroup({ context in
- context.duration = 0.2
- context.timingFunction = CAMediaTimingFunction(name: .easeOut)
- context.allowsImplicitAnimation = true
-
- // Animate scale down and fade out
- container.animator().alphaValue = 0.0
- let exitTransform = CATransform3DScale(CATransform3DIdentity, 0.9, 0.9, 1.0)
- container.layer?.transform = exitTransform
- }, completionHandler: {
- // Hide panel after animation completes
- self.panel?.orderOut(nil)
- })
- }
-
- /// Show a brief toast message in the overlay area
- func showToast(_ message: String, duration: TimeInterval = 1.5) {
- // Clean up any existing panel
- if let existingPanel = panel {
- existingPanel.orderOut(nil)
- existingPanel.contentView = nil
- panel = nil
- }
-
- let width: CGFloat = 280
- let height: CGFloat = 50
-
- let style: NSWindow.StyleMask = [.borderless, .nonactivatingPanel]
- let p = NSPanel(contentRect: NSRect(x: 0, y: 0, width: width, height: height),
- styleMask: style,
- backing: .buffered,
- defer: false)
- p.level = .statusBar
- p.isOpaque = false
- p.hasShadow = true
- p.hidesOnDeactivate = false
- p.ignoresMouseEvents = true
- p.collectionBehavior = [.canJoinAllSpaces, .transient, .fullScreenAuxiliary]
- p.backgroundColor = .clear
- p.titleVisibility = .hidden
- p.titlebarAppearsTransparent = true
- panel = p
-
- // Create container with dark background
- let container = NSView(frame: NSRect(x: 0, y: 0, width: width, height: height))
- container.wantsLayer = true
- container.layer?.backgroundColor = NSColor.black.withAlphaComponent(0.85).cgColor
- container.layer?.cornerRadius = 10
- unifiedContainer = container
-
- // Create message label
- let label = NSTextField(frame: NSRect(x: 10, y: 10, width: width - 20, height: height - 20))
- label.isEditable = false
- label.isBordered = false
- label.drawsBackground = false
- label.textColor = .white
- label.alignment = .center
- label.font = NSFont.systemFont(ofSize: 13, weight: .medium)
- label.stringValue = message
- container.addSubview(label)
-
- panel?.contentView = container
- positionCenteredLower()
-
- // Animate in
- container.alphaValue = 0.0
- panel?.orderFrontRegardless()
-
- NSAnimationContext.runAnimationGroup({ context in
- context.duration = 0.2
- context.timingFunction = CAMediaTimingFunction(name: .easeOut)
- container.animator().alphaValue = 1.0
- })
-
- // Auto-hide after duration
- DispatchQueue.main.asyncAfter(deadline: .now() + duration) { [weak self] in
- self?.hide()
- }
- }
-
- private func activeScreen() -> NSScreen?
- {
- if let key = NSApp.keyWindow?.screen { return key }
- if let mouse = NSScreen.screens.first(where: { NSMouseInRect(NSEvent.mouseLocation, $0.frame, false) }) { return mouse }
- return NSScreen.main
- }
-
- private func positionCenteredLower()
- {
- guard let screen = activeScreen(), let panel else { return }
- let visible = screen.visibleFrame
- panel.layoutIfNeeded()
- let size = panel.frame.size
- let centerX = visible.midX - size.width / 2
- let bottomPadding: CGFloat = 140
- let yPosition = visible.minY + bottomPadding
- panel.setFrameOrigin(NSPoint(x: centerX.rounded(), y: yPosition.rounded()))
- }
-
- private func setupTranscriptionTextField(in containerView: NSView)
- {
- // Remove existing text fields if any
- line1TextField?.removeFromSuperview()
- line2TextField?.removeFromSuperview()
-
- // Create container for two-line scrolling layout (no background, uses unified)
- let textContainer = NSView(frame: .zero)
- textContainer.translatesAutoresizingMaskIntoConstraints = false
- containerView.addSubview(textContainer)
-
- // Line 1 (top) - Faded, previous
- let line1 = createTextField(alpha: 0.45, fontSize: 9, weight: .regular)
- textContainer.addSubview(line1)
-
- // Line 2 (bottom) - Bright, current
- let line2 = createTextField(alpha: 1.0, fontSize: 10, weight: .medium)
- textContainer.addSubview(line2)
-
- // Layout constraints for two-line stack (super compact)
- NSLayoutConstraint.activate([
- // Line 1 (top)
- line1.topAnchor.constraint(equalTo: textContainer.topAnchor, constant: 2),
- line1.leadingAnchor.constraint(equalTo: textContainer.leadingAnchor, constant: 10),
- line1.trailingAnchor.constraint(equalTo: textContainer.trailingAnchor, constant: -10),
-
- // Line 2 (bottom)
- line2.topAnchor.constraint(equalTo: line1.bottomAnchor, constant: 1),
- line2.leadingAnchor.constraint(equalTo: textContainer.leadingAnchor, constant: 10),
- line2.trailingAnchor.constraint(equalTo: textContainer.trailingAnchor, constant: -10),
- line2.bottomAnchor.constraint(equalTo: textContainer.bottomAnchor, constant: -2)
- ])
-
- // Position container at the bottom (super compact)
- NSLayoutConstraint.activate([
- textContainer.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 8),
- textContainer.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -8),
- textContainer.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -5),
- textContainer.heightAnchor.constraint(equalToConstant: 32) // Super compact for 2 lines
- ])
-
- line1TextField = line1
- line2TextField = line2
-
- // Hide container initially
- textContainer.alphaValue = 0.0
- }
-
- private func createTextField(alpha: CGFloat, fontSize: CGFloat, weight: NSFont.Weight) -> NSTextField {
- let field = NSTextField(frame: .zero)
- field.isEditable = false
- field.isBordered = false
- field.drawsBackground = false
- field.textColor = .white
- field.alignment = .center
- field.font = NSFont.systemFont(ofSize: fontSize, weight: weight)
- field.lineBreakMode = .byTruncatingTail
- field.maximumNumberOfLines = 1
- field.cell?.wraps = false
- field.cell?.isScrollable = false
- field.stringValue = ""
- field.alphaValue = alpha
- field.translatesAutoresizingMaskIntoConstraints = false
- return field
- }
-
- private func setupModeLabel(in containerView: NSView, width: CGFloat) {
- // Remove existing label if any
- modeLabel?.removeFromSuperview()
-
- let label = NSTextField(frame: .zero)
- label.isEditable = false
- label.isBordered = false
- label.drawsBackground = false
- label.alignment = .center
- label.font = NSFont.systemFont(ofSize: 9, weight: .semibold)
- label.translatesAutoresizingMaskIntoConstraints = false
-
- containerView.addSubview(label)
- modeLabel = label
-
- // Position at top-right
- NSLayoutConstraint.activate([
- label.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 6),
- label.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -10)
- ])
-
- updateModeLabel()
- }
-
- private func updateModeLabel() {
- guard let label = modeLabel else { return }
-
- switch currentMode {
- case .dictation:
- // Hide for normal dictation mode (it's the default)
- label.alphaValue = 0
- label.stringValue = ""
- case .rewrite:
- // Show "Rewrite" badge in blue - text was selected
- label.stringValue = "Rewrite"
- label.textColor = NSColor(calibratedRed: 0.4, green: 0.6, blue: 1.0, alpha: 1.0)
- label.alphaValue = 1.0
- case .write:
- // Show "Write" badge in teal/cyan - no text selected, improving spoken text
- label.stringValue = "Write"
- label.textColor = NSColor(calibratedRed: 0.3, green: 0.8, blue: 0.8, alpha: 1.0)
- label.alphaValue = 1.0
- case .command:
- // Show "Command" badge in green
- label.stringValue = "Command"
- label.textColor = NSColor(calibratedRed: 0.4, green: 0.8, blue: 0.4, alpha: 1.0)
- label.alphaValue = 1.0
- }
- }
-
- func setPreviewEnabled(_ enabled: Bool) {
- guard isShowingPreview != enabled else { return }
- isShowingPreview = enabled
-
- // Resize panel and container
- let width: CGFloat = 340
- let height: CGFloat = enabled ? 100 : 90 // Compact for 2 lines
- let orbY: CGFloat = enabled ? 40 : 10
-
- NSAnimationContext.runAnimationGroup({ context in
- context.duration = 0.3
- context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
-
- if let panel = panel {
- var frame = panel.frame
- let oldHeight = frame.size.height
- frame.size.height = height
- frame.size.width = width
- frame.origin.y += (oldHeight - height) // Keep bottom aligned
- panel.animator().setFrame(frame, display: true)
- }
-
- if let container = unifiedContainer {
- container.animator().frame = NSRect(x: 0, y: 0, width: width, height: height)
- }
-
- if let orb = orbView {
- orb.animator().frame = NSRect(x: 0, y: orbY, width: width, height: 70)
- }
- })
-
- // Show/hide text fields
- if enabled {
- if line1TextField == nil, let containerView = orbView?.superview {
- setupTranscriptionTextField(in: containerView)
- }
- } else {
- line1TextField?.superview?.animator().alphaValue = 0.0
- }
- }
-
- func updateTranscriptionText(_ text: String)
- {
- guard isShowingPreview else { return } // Don't update if preview disabled
-
- guard let line1 = line1TextField,
- let line2 = line2TextField,
- let container = line2.superview else { return }
-
- if text.isEmpty {
- // Fade out container and reset
- NSAnimationContext.runAnimationGroup({ context in
- context.duration = 0.3
- container.animator().alphaValue = 0.0
- })
- line1.stringValue = ""
- line2.stringValue = ""
- previousText = ""
- return
- }
-
- // Simple scrolling: show last ~100 characters across 2 lines
- let maxChars = 100
- let displayText = text.count > maxChars ? String(text.suffix(maxChars)) : text
-
- // Split into 2 lines based on space
- let words = displayText.split(separator: " ").map(String.init)
-
- if words.count <= 6 {
- // Short: only line 2
- line1.stringValue = ""
- line2.stringValue = displayText
- } else {
- // Long: split roughly in half
- let midPoint = words.count / 2
- line1.stringValue = words[..<midPoint].joined(separator: " ")
- line2.stringValue = words[midPoint...].joined(separator: " ")
- }
-
- previousText = text
-
- // Fade in container if needed
- if container.alphaValue < 1.0 {
- NSAnimationContext.runAnimationGroup({ context in
- context.duration = 0.3
- container.animator().alphaValue = 1.0
- })
- }
- }
-}
-
-
diff --git a/Sources/Fluid/Services/MenuBarManager.swift b/Sources/Fluid/Services/MenuBarManager.swift
index e1bef6af..6a0908ca 100644
--- a/Sources/Fluid/Services/MenuBarManager.swift
+++ b/Sources/Fluid/Services/MenuBarManager.swift
@@ -18,12 +18,18 @@ final class MenuBarManager: ObservableObject {
private var cancellables = Set<AnyCancellable>()
// Overlay management (persistent, independent of window lifecycle)
- private var overlay: ListeningOverlayController?
private var overlayVisible: Bool = false
@Published var isRecording: Bool = false
@Published var aiProcessingEnabled: Bool = false
+ // Track current overlay mode for notch
+ private var currentOverlayMode: OverlayMode = .dictation
+
+ // Track pending overlay operations to prevent spam
+ private var pendingShowOperation: DispatchWorkItem?
+ private var pendingHideOperation: DispatchWorkItem?
+
init() {
// Don't setup menu bar immediately - defer until app is ready
// Initialize from persisted setting
@@ -53,11 +59,6 @@ final class MenuBarManager: ObservableObject {
func configure(asrService: ASRService) {
self.asrService = asrService
- // Initialize overlay controller (persists for app lifetime)
- if overlay == nil {
- overlay = ListeningOverlayController(asrService: asrService)
- }
-
// Subscribe to recording state changes
asrService.$isRunning
.receive(on: DispatchQueue.main)
@@ -75,7 +76,8 @@ final class MenuBarManager: ObservableObject {
asrService.$partialTranscription
.receive(on: DispatchQueue.main)
.sink { [weak self] newText in
- self?.overlay?.updateTranscriptionText(newText)
+ guard self != nil else { return }
+ NotchOverlayManager.shared.updateTranscriptionText(newText)
}
.store(in: &cancellables)
@@ -89,42 +91,53 @@ final class MenuBarManager: ObservableObject {
let delay: DispatchTimeInterval = .milliseconds(150)
if isRunning {
+ // Cancel any pending hide operation
+ pendingHideOperation?.cancel()
+ pendingHideOperation = nil
+
overlayVisible = true
- DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
+
+ let showItem = DispatchWorkItem { [weak self] in
guard let self = self, self.overlayVisible else { return }
- let hosting = NSHostingView(rootView: ListeningOverlayView(audioLevelPublisher: asrService.audioLevelPublisher))
- hosting.wantsLayer = true
- hosting.layer?.cornerRadius = 20
- hosting.layer?.masksToBounds = true
- let showPreview = SettingsStore.shared.enableStreamingPreview
- self.overlay?.show(with: hosting, showPreview: showPreview)
+
+ // Show notch overlay
+ NotchOverlayManager.shared.show(
+ audioLevelPublisher: asrService.audioLevelPublisher,
+ mode: self.currentOverlayMode
+ )
+
+ self.pendingShowOperation = nil
}
+ pendingShowOperation = showItem
+ DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: showItem)
} else {
+ // Cancel any pending show operation
+ pendingShowOperation?.cancel()
+ pendingShowOperation = nil
+
overlayVisible = false
- DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
+
+ let hideItem = DispatchWorkItem { [weak self] in
guard let self = self, !self.overlayVisible else { return }
- self.overlay?.hide()
- // Clear transcription text when hiding overlay
- self.overlay?.updateTranscriptionText("")
+
+ // Hide notch overlay
+ NotchOverlayManager.shared.hide()
+
+ self.pendingHideOperation = nil
}
+ pendingHideOperation = hideItem
+ DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: hideItem)
}
}
- // MARK: - Public API for overlay management (for ContentView to sync)
+ // MARK: - Public API for overlay management
func updateOverlayTranscription(_ text: String) {
- overlay?.updateTranscriptionText(text)
- }
-
- func updateOverlayPreviewSetting(_ enabled: Bool) {
- overlay?.setPreviewEnabled(enabled)
+ NotchOverlayManager.shared.updateTranscriptionText(text)
}
func setOverlayMode(_ mode: OverlayMode) {
- overlay?.setMode(mode)
- }
-
- func showToast(_ message: String) {
- overlay?.showToast(message)
+ currentOverlayMode = mode
+ NotchOverlayManager.shared.setMode(mode)
}
private func setupMenuBarSafely() {
diff --git a/Sources/Fluid/Services/NotchOverlayManager.swift b/Sources/Fluid/Services/NotchOverlayManager.swift
new file mode 100644
index 00000000..a88fd46c
--- /dev/null
+++ b/Sources/Fluid/Services/NotchOverlayManager.swift
@@ -0,0 +1,167 @@
+//
+// NotchOverlayManager.swift
+// Fluid
+//
+// Created by Assistant
+//
+
+import DynamicNotchKit
+import SwiftUI
+import Combine
+import AppKit
+
+// MARK: - Overlay Mode
+enum OverlayMode: String {
+ case dictation = "Dictation"
+ case rewrite = "Rewrite"
+ case write = "Write"
+ case command = "Command"
+}
+
+@MainActor
+final class NotchOverlayManager {
+ static let shared = NotchOverlayManager()
+
+ private var notch: DynamicNotch<NotchExpandedView, NotchCompactLeadingView, NotchCompactTrailingView>?
+ private var currentMode: OverlayMode = .dictation
+
+ // State machine to prevent race conditions
+ private enum State {
+ case idle
+ case showing
+ case visible
+ case hiding
+ }
+ private var state: State = .idle
+
+ // Generation counter to track show/hide cycles and prevent race conditions
+ // Uses UInt64 to avoid overflow concerns in long-running sessions
+ private var generation: UInt64 = 0
+
+ // Track pending retry task for cancellation
+ private var pendingRetryTask: Task<Void, Never>?
+
+ private init() {}
+
+ func show(audioLevelPublisher: AnyPublisher<CGFloat, Never>, mode: OverlayMode) {
+ // Cancel any pending retry operations
+ pendingRetryTask?.cancel()
+ pendingRetryTask = nil
+
+ // If already visible or in transition, wait for cleanup to complete
+ if notch != nil || state != .idle {
+ // Increment generation to invalidate stale operations
+ generation &+= 1
+ let targetGeneration = generation
+
+ // Start async cleanup and retry
+ pendingRetryTask = Task { [weak self] in
+ guard let self = self else { return }
+
+ // Perform cleanup synchronously first
+ await self.performCleanup()
+
+ // Small delay to ensure cleanup completes
+ try? await Task.sleep(nanoseconds: 50_000_000) // 50ms
+
+ // Check if we're still the active operation
+ guard !Task.isCancelled, self.generation == targetGeneration else { return }
+
+ // Retry show
+ self.showInternal(audioLevelPublisher: audioLevelPublisher, mode: mode)
+ }
+ return
+ }
+
+ showInternal(audioLevelPublisher: audioLevelPublisher, mode: mode)
+ }
+
+ private func showInternal(audioLevelPublisher: AnyPublisher<CGFloat, Never>, mode: OverlayMode) {
+ guard state == .idle else { return }
+
+ // Increment generation for this operation
+ generation &+= 1
+ let currentGeneration = generation
+
+ state = .showing
+ currentMode = mode
+
+ // Update shared content state immediately
+ NotchContentState.shared.mode = mode
+ NotchContentState.shared.updateTranscription("")
+
+ // Create notch with SwiftUI views
+ let newNotch = DynamicNotch(
+ hoverBehavior: [.keepVisible, .hapticFeedback],
+ style: .notch(topCornerRadius: 12, bottomCornerRadius: 18)
+ ) {
+ NotchExpandedView(audioPublisher: audioLevelPublisher)
+ } compactLeading: {
+ NotchCompactLeadingView()
+ } compactTrailing: {
+ NotchCompactTrailingView()
+ }
+
+ self.notch = newNotch
+
+ // Show in expanded state
+ Task {
+ await newNotch.expand()
+ // Only update state if we're still the active generation
+ guard self.generation == currentGeneration else { return }
+ self.state = .visible
+ }
+ }
+
+ func hide() {
+ // Cancel any pending retry operations
+ pendingRetryTask?.cancel()
+ pendingRetryTask = nil
+
+ // Increment generation to invalidate any pending show tasks
+ generation &+= 1
+ let currentGeneration = generation
+
+ // Handle visible or showing states (can hide while still expanding)
+ guard state == .visible || state == .showing, let currentNotch = notch else {
+ // Force cleanup if stuck or in inconsistent state
+ Task { await performCleanup() }
+ return
+ }
+
+ state = .hiding
+
+ Task {
+ await currentNotch.hide()
+ // Only clear if we're still the active operation
+ guard self.generation == currentGeneration else { return }
+ self.notch = nil
+ self.state = .idle
+ }
+ }
+
+ /// Async cleanup that properly waits for hide to complete
+ private func performCleanup() async {
+ // Cancel any pending retry operations
+ pendingRetryTask?.cancel()
+ pendingRetryTask = nil
+
+ if let existingNotch = notch {
+ await existingNotch.hide()
+ }
+ notch = nil
+ state = .idle
+ }
+
+ func setMode(_ mode: OverlayMode) {
+ // Always update NotchContentState to ensure UI stays in sync
+ // (can get out of sync during show/hide transitions)
+ currentMode = mode
+ NotchContentState.shared.mode = mode
+ }
+
+ func updateTranscriptionText(_ text: String) {
+ NotchContentState.shared.updateTranscription(text)
+ }
+}
+
diff --git a/Sources/Fluid/TalkingAnimations.swift b/Sources/Fluid/TalkingAnimations.swift
index cf0b6012..2043c1ad 100644
--- a/Sources/Fluid/TalkingAnimations.swift
+++ b/Sources/Fluid/TalkingAnimations.swift
@@ -390,99 +390,6 @@ struct PremiumTalkingParticle: View {
}
}
-// MARK: - ECG-Style Listening Overlay
-struct TalkingListeningOverlayView: View {
- let audioLevelPublisher: AnyPublisher<CGFloat, Never>
- @StateObject private var appTracker = ActiveAppTracker()
-
- private var appDisplayName: String {
- if let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String, name.isEmpty == false {
- return name
- }
- if let name = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String, name.isEmpty == false {
- return name
- }
- return "Fluid"
- }
-
- // Optional brand wordmark image from asset catalog
- private var brandWordmarkImage: NSImage? {
- // Try a few common names so you can drop in any of these
- return NSImage(named: "BrandWordmark")
- ?? NSImage(named: "FluidWordmark")
- ?? NSImage(named: "fluid_wordmark")
- }
-
- var body: some View {
- ZStack {
- // NO BACKGROUND - Using unified container from ListeningOverlayController
-
- // Centered visualizer - absolutely positioned
- TalkingAudioVisualizationView(audioLevelPublisher: audioLevelPublisher)
-
- // Brand label - absolutely positioned center-right (wordmark if available, else icon + name)
- HStack {
- Spacer()
- HStack(spacing: 4) {
- if let wordmark = brandWordmarkImage {
- Image(nsImage: wordmark)
- .resizable()
- .interpolation(.high)
- .antialiased(true)
- .scaledToFit()
- .frame(height: 24)
- .shadow(color: .black.opacity(0.5), radius: 1, x: 0, y: 1)
- } else {
- if let nsIcon = NSApp.applicationIconImage {
- Image(nsImage: nsIcon)
- .resizable()
- .interpolation(.high)
- .antialiased(true)
- .frame(width: 14, height: 14)
- .cornerRadius(3)
- .shadow(color: .black.opacity(0.5), radius: 1, x: 0, y: 1)
- }
- Text(appDisplayName.uppercased())
- .font(.system(size: 11, weight: .semibold, design: .rounded))
- .kerning(0.5)
- .foregroundColor(.white.opacity(0.6))
- .shadow(color: .black.opacity(0.8), radius: 2, x: 1, y: 1)
- .shadow(color: .black.opacity(0.6), radius: 4, x: 2, y: 2)
- .shadow(color: .black.opacity(0.3), radius: 8, x: 0, y: 0)
- }
- }
- .padding(.horizontal, 8)
- .padding(.vertical, 4)
- .background(
- RoundedRectangle(cornerRadius: 14)
- .fill(
- LinearGradient(
- gradient: Gradient(colors: [
- Color.black.opacity(0.4),
- Color.black.opacity(0.6)
- ]),
- startPoint: .topLeading,
- endPoint: .bottomTrailing
- )
- )
- .overlay(
- RoundedRectangle(cornerRadius: 14)
- .stroke(
- Color.white.opacity(0.1),
- lineWidth: 0.5
- )
- )
- )
- .shadow(color: Color.black.opacity(0.3), radius: 2, x: 0, y: 1)
- .padding(.trailing, 12)
- }
- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
- }
- .frame(maxWidth: .infinity, maxHeight: .infinity)
- .onReceive(audioLevelPublisher) { _ in }
- }
-}
-
// MARK: - Individual Spokenly Bar
struct SpokenlyBar: View {
let height: CGFloat
@@ -499,19 +406,3 @@ struct SpokenlyBar: View {
.shadow(color: Color.black.opacity(0.2), radius: 1, x: 0, y: 1)
}
}
-
-struct EnhancedTalkingListeningOverlayView: View {
- let audioLevelPublisher: AnyPublisher<CGFloat, Never>
-
- var body: some View {
- ZStack {
- EnhancedTalkingAudioVisualizationView(audioLevelPublisher: audioLevelPublisher)
- }
- .frame(width: 100, height: 32)
- .background(
- RoundedRectangle(cornerRadius: 16)
- .fill(Color.black.opacity(0.08))
- .blur(radius: 6)
- )
- }
-}
\ No newline at end of file
diff --git a/Sources/Fluid/UI/SettingsView.swift b/Sources/Fluid/UI/SettingsView.swift
index 9c35c8cc..bf6f6d81 100644
--- a/Sources/Fluid/UI/SettingsView.swift
+++ b/Sources/Fluid/UI/SettingsView.swift
@@ -518,10 +518,6 @@ struct SettingsView: View {
)
.onChange(of: enableStreamingPreview) { newValue in
SettingsStore.shared.enableStreamingPreview = newValue
- menuBarManager.updateOverlayPreviewSetting(newValue)
- if !newValue {
- menuBarManager.updateOverlayTranscription("")
- }
}
// Copy to clipboard toggle
diff --git a/Sources/Fluid/Views/CommandModeView.swift b/Sources/Fluid/Views/CommandModeView.swift
index 93c495da..f62d56f9 100644
--- a/Sources/Fluid/Views/CommandModeView.swift
+++ b/Sources/Fluid/Views/CommandModeView.swift
@@ -4,6 +4,7 @@ struct CommandModeView: View {
@ObservedObject var service: CommandModeService
@ObservedObject var asr: ASRService
@ObservedObject var settings = SettingsStore.shared
+ @EnvironmentObject var menuBarManager: MenuBarManager
var onClose: (() -> Void)?
@State private var inputText: String = ""
@@ -65,6 +66,12 @@ struct CommandModeView: View {
}
.onAppear {
updateAvailableModels()
+ // Set overlay mode to command when this view appears
+ menuBarManager.setOverlayMode(.command)
+ }
+ .onDisappear {
+ // Reset overlay mode to dictation when leaving
+ menuBarManager.setOverlayMode(.dictation)
}
.onChange(of: asr.finalText) { newText in
if !newText.isEmpty {
diff --git a/Sources/Fluid/Views/NotchContentViews.swift b/Sources/Fluid/Views/NotchContentViews.swift
new file mode 100644
index 00000000..bcac3297
--- /dev/null
+++ b/Sources/Fluid/Views/NotchContentViews.swift
@@ -0,0 +1,229 @@
+//
+// NotchContentViews.swift
+// Fluid
+//
+// Created by Assistant
+//
+
+import SwiftUI
+import Combine
+
+// MARK: - Observable state for notch content (Singleton)
+
+@MainActor
+class NotchContentState: ObservableObject {
+ static let shared = NotchContentState()
+
+ @Published var transcriptionText: String = ""
+ @Published var mode: OverlayMode = .dictation
+
+ // Cached transcription lines to avoid recomputing on every render
+ @Published private(set) var cachedLine1: String = ""
+ @Published private(set) var cachedLine2: String = ""
+
+ private init() {}
+
+ /// Update transcription and recompute cached lines
+ func updateTranscription(_ text: String) {
+ guard text != transcriptionText else { return }
+ transcriptionText = text
+ recomputeTranscriptionLines()
+ }
+
+ /// Recompute cached transcription lines (called only when text changes)
+ private func recomputeTranscriptionLines() {
+ let text = transcriptionText
+
+ guard !text.isEmpty else {
+ cachedLine1 = ""
+ cachedLine2 = ""
+ return
+ }
+
+ // Show last ~100 characters
+ let maxChars = 100
+ let displayText = text.count > maxChars ? String(text.suffix(maxChars)) : text
+
+ // Split into words
+ let words = displayText.split(separator: " ").map(String.init)
+
+ if words.count <= 6 {
+ // Short: only line 2
+ cachedLine1 = ""
+ cachedLine2 = displayText
+ } else {
+ // Long: split roughly in half
+ let midPoint = words.count / 2
+ cachedLine1 = words[..<midPoint].joined(separator: " ")
+ cachedLine2 = words[midPoint...].joined(separator: " ")
+ }
+ }
+}
+
+// MARK: - Shared Mode Color Helper
+
+extension OverlayMode {
+ /// Mode-specific color for notch UI elements
+ var notchColor: Color {
+ switch self {
+ case .dictation:
+ return Color.white.opacity(0.85)
+ case .rewrite:
+ return Color(red: 0.45, green: 0.55, blue: 1.0) // Lighter blue
+ case .write:
+ return Color(red: 0.4, green: 0.6, blue: 1.0) // Blue
+ case .command:
+ return Color(red: 1.0, green: 0.35, blue: 0.35) // Red
+ }
+ }
+}
+
+// MARK: - Expanded View (Main Content) - Minimal Design
+
+struct NotchExpandedView: View {
+ let audioPublisher: AnyPublisher<CGFloat, Never>
+ @ObservedObject private var contentState = NotchContentState.shared
+
+ private var modeColor: Color {
+ contentState.mode.notchColor
+ }
+
+ private var modeLabel: String {
+ switch contentState.mode {
+ case .dictation: return "Dictate"
+ case .rewrite: return "Rewrite"
+ case .write: return "Write"
+ case .command: return "Command"
+ }
+ }
+
+ private var hasTranscription: Bool {
+ !contentState.transcriptionText.isEmpty
+ }
+
+ var body: some View {
+ VStack(spacing: 4) {
+ // Visualization + Mode label row
+ HStack(spacing: 6) {
+ NotchWaveformView(audioPublisher: audioPublisher, color: modeColor)
+ .frame(width: 80, height: 22)
+
+ // Mode label
+ Text(modeLabel)
+ .font(.system(size: 9, weight: .medium))
+ .foregroundStyle(modeColor)
+ .opacity(0.9)
+ }
+
+ // Transcription preview (single line, minimal)
+ if hasTranscription {
+ Text(contentState.cachedLine2)
+ .font(.system(size: 10, weight: .medium))
+ .foregroundStyle(.white.opacity(0.75))
+ .lineLimit(1)
+ .truncationMode(.tail)
+ .frame(maxWidth: 180)
+ .transition(.opacity.combined(with: .scale(scale: 0.95)))
+ }
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 6)
+ .background(Color.black)
+ .animation(.spring(response: 0.25, dampingFraction: 0.8), value: hasTranscription)
+ .animation(.easeInOut(duration: 0.2), value: contentState.mode)
+ }
+}
+
+// MARK: - Minimal Notch Waveform (Color-matched)
+
+struct NotchWaveformView: View {
+ let audioPublisher: AnyPublisher<CGFloat, Never>
+ let color: Color
+
+ @StateObject private var data: AudioVisualizationData
+ @State private var barHeights: [CGFloat] = Array(repeating: 3, count: 7)
+
+ private let barCount = 7
+ private let barWidth: CGFloat = 3
+ private let barSpacing: CGFloat = 4
+ private let minHeight: CGFloat = 3
+ private let maxHeight: CGFloat = 20
+
+ init(audioPublisher: AnyPublisher<CGFloat, Never>, color: Color) {
+ self.audioPublisher = audioPublisher
+ self.color = color
+ self._data = StateObject(wrappedValue: AudioVisualizationData(audioLevelPublisher: audioPublisher))
+ }
+
+ var body: some View {
+ HStack(spacing: barSpacing) {
+ ForEach(0..<barCount, id: \.self) { index in
+ RoundedRectangle(cornerRadius: barWidth / 2)
+ .fill(color)
+ .frame(width: barWidth, height: barHeights[index])
+ .shadow(color: color.opacity(0.4), radius: 2, x: 0, y: 0)
+ }
+ }
+ .onChange(of: data.audioLevel) { level in
+ updateBars(level: level)
+ }
+ .onAppear {
+ // Initialize with idle animation
+ updateBars(level: 0)
+ }
+ }
+
+ private func updateBars(level: CGFloat) {
+ let normalizedLevel = min(max(level, 0), 1)
+ let isActive = normalizedLevel > 0.02
+
+ withAnimation(.spring(response: 0.15, dampingFraction: 0.6)) {
+ for i in 0..<barCount {
+ let centerDistance = abs(CGFloat(i) - CGFloat(barCount - 1) / 2)
+ let centerFactor = 1.0 - (centerDistance / CGFloat(barCount / 2)) * 0.4
+
+ if isActive {
+ let randomVariation = CGFloat.random(in: 0.7...1.0)
+ barHeights[i] = minHeight + (maxHeight - minHeight) * normalizedLevel * centerFactor * randomVariation
+ } else {
+ // Subtle idle pulse
+ let idleVariation = CGFloat.random(in: 0.8...1.2)
+ barHeights[i] = minHeight * idleVariation
+ }
+ }
+ }
+ }
+}
+
+// MARK: - Compact Views (Small States)
+
+struct NotchCompactLeadingView: View {
+ @ObservedObject private var contentState = NotchContentState.shared
+ @State private var isPulsing = false
+
+ var body: some View {
+ Image(systemName: "waveform")
+ .font(.system(size: 9, weight: .medium))
+ .foregroundStyle(contentState.mode.notchColor)
+ .scaleEffect(isPulsing ? 1.1 : 1.0)
+ .animation(.easeInOut(duration: 0.8).repeatForever(autoreverses: true), value: isPulsing)
+ .onAppear { isPulsing = true }
+ .onDisappear { isPulsing = false }
+ }
+}
+
+struct NotchCompactTrailingView: View {
+ @ObservedObject private var contentState = NotchContentState.shared
+ @State private var isPulsing = false
+
+ var body: some View {
+ Circle()
+ .fill(contentState.mode.notchColor)
+ .frame(width: 5, height: 5)
+ .opacity(isPulsing ? 0.5 : 1.0)
+ .scaleEffect(isPulsing ? 0.85 : 1.0)
+ .animation(.easeInOut(duration: 1.0).repeatForever(autoreverses: true), value: isPulsing)
+ .onAppear { isPulsing = true }
+ .onDisappear { isPulsing = false }
+ }
+}