Menu Bar Interface
Relevant source files
The following files were used as context for generating this wiki page:
The Menu Bar Interface is a core component of VoiceInk, providing users with quick access to essential features, settings, and application controls directly from the macOS menu bar. It serves a dual purpose: as a quick-action dropdown menu for common tasks and as the primary controller for the application's main window, especially when running in "Menu Bar Only" mode.
The interface is managed by the MenuBarManager class, which handles the application's presentation state (standard vs. menu bar only) and the lifecycle of the main window. The UI of the menu itself is defined in the MenuBarView SwiftUI view, which is populated with controls for transcription, AI enhancements, and navigation.
Architecture and Core Components
The Menu Bar Interface is established at the application's entry point and involves several key components working together.
Sources: VoiceInk/VoiceInk.swift:13-29, 63-90, VoiceInk/MenuBarManager.swift, VoiceInk/Views/MenuBarView.swift
Component Relationships
The VoiceInkApp initializes the MenuBarManager and injects it, along with other critical services, into the environment of the MenuBarView. The MenuBarManager holds references to these services to perform its functions.
Initialization
The menu bar is instantiated as a MenuBarExtra scene within the VoiceInkApp struct. The MenuBarView is used as its content, and all necessary services and managers are passed down as environment objects. The icon displayed in the menu bar is menuBarIcon.png.
Sources: VoiceInk/VoiceInk.swift:125-139, VoiceInk/Assets.xcassets/menuBarIcon.imageset/Contents.json
"Menu Bar Only" Mode
VoiceInk can operate in a "Menu Bar Only" mode, where its Dock icon is hidden, and it functions as an accessory application. This behavior is controlled by the MenuBarManager.
Sources: VoiceInk/MenuBarManager.swift:5-11, 41-53, VoiceInk/Views/Settings/SettingsView.swift:214-215, VoiceInk/Views/MenuBarView.swift:156-158
State Management
The isMenuBarOnly property in MenuBarManager is a @Published boolean that persists its state in UserDefaults. When this property changes, the updateAppActivationPolicy() method is called to toggle the application's activation policy between .regular (with Dock icon) and .accessory (without Dock icon).
This diagram shows the application's activation policy state based on the isMenuBarOnly flag.
Sources: VoiceInk/MenuBarManager.swift:41-53
UI Toggles
Users can toggle this mode from two places:
- A button in the
MenuBarView:Button(menuBarManager.isMenuBarOnly ? "Show Dock Icon" : "Hide Dock Icon"). - A toggle switch in the
SettingsView:Toggle("Hide Dock Icon (Menu Bar Only)", isOn: $menuBarManager.isMenuBarOnly).
Sources: VoiceInk/Views/MenuBarView.swift:156-158, VoiceInk/Views/Settings/SettingsView.swift:214-215
Main Window Management
A primary responsibility of the MenuBarManager is to open and navigate the main application window (ContentView) in response to user actions in the menu bar.
Sources: VoiceInk/MenuBarManager.swift:55-116, VoiceInk/Views/ContentView.swift:142-164
Navigation Flow
When a user clicks a menu item like "Settings" or "History", the menuBarManager.openMainWindowAndNavigate(to:) function is invoked. This function ensures the app is active, creates the main window if it doesn't exist, brings it to the front, and then posts a .navigateToDestination notification. The ContentView listens for this notification and updates its selectedView state to display the correct screen.
This sequence diagram illustrates the process of a user clicking the "Settings" button in the menu bar.
Window Creation
The createMainWindow() function within MenuBarManager is responsible for instantiating the ContentView and embedding it within a new NSWindow. It ensures all required environment objects are injected into the view hierarchy. A WindowDelegate is also attached to the window to clear the manager's reference to it upon closing, allowing a new window to be created on the next request.
Sources: VoiceInk/MenuBarManager.swift:92-116
Menu Bar UI and Functionality
The MenuBarView defines the structure and actions of the dropdown menu. It is composed of several sections, each providing specific controls.
Sources: VoiceInk/Views/MenuBarView.swift
| Feature / Control | UI Element | Action | Source File & Lines |
|---|---|---|---|
| Transcription Model | Menu | Selects the default transcription model from whisperState.usableModels. | [MenuBarView.swift:16-32](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L16-L32) |
| Manage Models | Button | Opens the main window and navigates to the "AI Models" view. | [MenuBarView.swift:34-36](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L34-L36) |
| AI Enhancement | Toggle | Enables or disables AI enhancement via enhancementService. | [MenuBarView.swift:40-40](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L40) |
| Enhancement Prompt | Menu | Selects the active enhancement prompt from enhancementService.allPrompts. | [MenuBarView.swift:42-56](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L42-L56) |
| AI Provider | Menu | Selects the AI provider for enhancement from aiService.connectedProviders. | [MenuBarView.swift:67-83](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L67-L83) |
| AI Model | Menu | Selects the specific AI model for the chosen provider. | [MenuBarView.swift:94-110](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L94-L110) |
| Language Selection | LanguageSelectionView | Sets the transcription language. | [MenuBarView.swift:121-121](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L121) |
| Clipboard Context | Button (in "Additional" menu) | Toggles enhancementService.useClipboardContext. | [MenuBarView.swift:124-134](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L124-L134) |
| Context Awareness | Button (in "Additional" menu) | Toggles enhancementService.useScreenCaptureContext. | [MenuBarView.swift:136-146](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L136-L146) |
| Retry Last Transcription | Button | Calls LastTranscriptionService.retryLastTranscription(...). | [MenuBarView.swift:149-151](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L149-L151) |
| Copy Last Transcription | Button | Calls LastTranscriptionService.copyLastTranscription(...). | [MenuBarView.swift:152-154](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L152-L154) |
| History | Button | Opens the main window and navigates to the "History" view. | [MenuBarView.swift:156-158](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L156-L158) |
| Settings | Button | Opens the main window and navigates to the "Settings" view. | [MenuBarView.swift:160-162](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L160-L162) |
| Dock Icon | Button | Toggles "Menu Bar Only" mode via menuBarManager.toggleMenuBarOnly(). | [MenuBarView.swift:164-166](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L164-L166) |
| Launch at Login | Toggle | Toggles the LaunchAtLogin.isEnabled property. | [MenuBarView.swift:168-171](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L168-L171) |
| Check for Updates | Button | Calls updaterViewModel.checkForUpdates(). | [MenuBarView.swift:175-177](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L175-L177) |
| Help and Support | Button | Opens a support email. | [MenuBarView.swift:179-181](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L179-L181) |
| Quit VoiceInk | Button | Terminates the application. | [MenuBarView.swift:185-187](https://github.com/Beingpax/VoiceInk/blob/HEAD/MenuBarView.swift#L185-L187) |
Summary
The Menu Bar Interface is a versatile and crucial part of the VoiceInk user experience. It acts as a centralized hub for controlling transcription settings, managing AI features, and accessing different parts of the application. Through the MenuBarManager, it intelligently manages the application's visibility and windowing behavior, providing a seamless transition between a full application and a lightweight, menu-bar-driven utility. This flexibility allows users to tailor the app's presence to their workflow, whether they need the full interface or just quick, on-demand access.