Recorder UI (Mini & Notch)
Relevant source files
The following files were used as context for generating this wiki page:
- VoiceInk/Views/Recorder/MiniRecorderView.swift
- VoiceInk/Views/Recorder/MiniWindowManager.swift
- VoiceInk/Views/Recorder/NotchRecorderView.swift
- VoiceInk/Views/Recorder/NotchWindowManager.swift
- VoiceInk/Whisper/WhisperState+UI.swift
- VoiceInk/Whisper/WhisperState.swift
- VoiceInk/Views/Settings/SettingsView.swift
The Recorder UI is the primary interface for capturing audio in VoiceInk. It offers two distinct visual styles: a compact "Mini Recorder" and a "Notch Recorder" designed to integrate with the MacBook's screen notch. The user can select their preferred style in the application's settings.
This system is managed by WhisperState, which holds the current recorderType and orchestrates the display and dismissal of the appropriate recorder window. Each style has a dedicated View for its UI and a WindowManager to handle the underlying NSPanel behavior.
Architecture Overview
The recorder UI architecture is designed to be modular, with a central state manager (WhisperState) controlling which UI is presented. The user's choice in SettingsView updates the recorderType property in WhisperState, which is then used by the UI management logic in WhisperState+UI.swift to instantiate and control the correct WindowManager.
This diagram illustrates the relationship between the key components involved in the Recorder UI system.
Recorder Style Selection
Users can choose their preferred recorder interface from the "Recorder Style" section within the app's settings. This choice is persisted in UserDefaults under the key RecorderType.
Sources: VoiceInk/Views/Settings/SettingsView.swift:233-245
// VoiceInk/Views/Settings/SettingsView.swift:233-245
SettingsSection(
icon: "rectangle.on.rectangle",
title: "Recorder Style",
subtitle: "Choose your preferred recorder interface"
) {
VStack(alignment: .leading, spacing: 8) {
Text("Select how you want the recorder to appear on your screen.")
.settingsDescription()
Picker("Recorder Style", selection: $whisperState.recorderType) {
Text("Notch Recorder").tag("notch")
Text("Mini Recorder").tag("mini")
}
.pickerStyle(.radioGroup)
.padding(.vertical, 4)
}
}
The recorderType property in WhisperState is directly bound to this Picker. When changed, its didSet observer saves the new value to UserDefaults.
Sources: VoiceInk/Whisper/WhisperState.swift:20-24
// VoiceInk/Whisper/WhisperState.swift:20-24
@Published var recorderType: String = UserDefaults.standard.string(forKey: "RecorderType") ?? "mini" {
didSet {
UserDefaults.standard.set(recorderType, forKey: "RecorderType")
}
}
UI and Window Management
The presentation of the recorder UI is handled by the WhisperState+UI.swift extension, which acts as a factory and controller for the recorder windows.
Lifecycle Functions
The WhisperState class exposes several functions to manage the recorder's visibility and state.
| Function | Description | Source File |
|---|---|---|
showRecorderPanel() | Checks recorderType and shows the corresponding window (Mini or Notch). It lazily instantiates the appropriate WindowManager if it doesn't exist. | WhisperState+UI.swift:9-23 |
hideRecorderPanel() | Hides the currently active recorder window based on recorderType. | WhisperState+UI.swift:25-31 |
toggleMiniRecorder() | The main entry point for hotkeys. It toggles recording on/off if the panel is visible, or shows the panel and starts recording if it's hidden. | WhisperState+UI.swift:35-51 |
dismissMiniRecorder() | Hides the recorder panel, stops any active recording, and performs cleanup. | WhisperState+UI.swift:53-83 |
cancelRecording() | Plays a cancellation sound and calls dismissMiniRecorder() to abort the session. | WhisperState+UI.swift:92-96 |
The isMiniRecorderVisible property in WhisperState uses a didSet observer to automatically call showRecorderPanel() or hideRecorderPanel() when its value changes, simplifying the control flow.
Sources: VoiceInk/Whisper/WhisperState.swift:26-34
Window Managers (MiniWindowManager & NotchWindowManager)
Both MiniWindowManager and NotchWindowManager are responsible for creating and configuring a non-activating, floating NSPanel to host their respective SwiftUI views. This ensures the recorder UI can overlay other applications without stealing focus.
Key NSPanel configurations include:
isFloatingPanel = truelevel = .floatingcollectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary]isOpaque = falsebackgroundColor = .clearhidesOnDeactivate = false
Sources: VoiceInk/Views/Recorder/MiniWindowManager.swift:25-46, VoiceInk/Views/Recorder/NotchWindowManager.swift:25-46
The following sequence diagram shows how WhisperState interacts with a WindowManager to display a recorder panel.
Recorder Views
Mini Recorder (MiniRecorderView)
The MiniRecorderView is a compact, floating panel that displays the recording status. It includes:
- A central
RecorderStatusDisplayshowing the current state (e.g., idle, recording, transcribing) and an audio meter. - Buttons on the left and right for accessing Power Modes (
RecorderPowerModeButton) and Prompts (RecorderPromptButton). - An error message display area that shows text from
whisperState.miniRecorderError.
The view is designed to be minimal and unobtrusive, appearing near the top center of the screen.
Sources: VoiceInk/Views/Recorder/MiniRecorderView.swift
Notch Recorder (NotchRecorderView)
The NotchRecorderView is specifically designed for MacBooks with a screen notch. It integrates into the menu bar area, wrapping around the physical notch.
- Layout: It uses an
HStackwith three sections:leftSection,centerSection, andrightSection. - Center Section: This is a transparent rectangle whose width is dynamically calculated to match the screen's notch (
exactNotchWidth). - Left/Right Sections: These contain the UI elements, such as the
RecorderStatusDisplayand buttons for prompts and power modes, positioned on either side of the notch area. - Appearance: The view has a black background and is masked with a custom
NotchShapeto create the rounded appearance that blends with the system menu bar.
The height and width of the notch area are determined by querying NSScreen.main.safeAreaInsets and NSApplication.shared.mainMenu?.menuBarHeight.
Sources: VoiceInk/Views/Recorder/NotchRecorderView.swift:13-33, 47-64
Summary
The dual recorder UI system provides users with a choice between a standard floating panel and a notch-integrated interface. The architecture effectively separates state management (WhisperState), window management (MiniWindowManager, NotchWindowManager), and UI presentation (MiniRecorderView, NotchRecorderView). This modular design allows for flexible and maintainable UI components for the core recording functionality of the application.