Power Mode Configuration UI
Relevant source files
The following files were used as context for generating this wiki page:- VoiceInk/PowerMode/PowerModeConfigView.swift
- VoiceInk/PowerMode/PowerModeView.swift
- VoiceInk/PowerMode/PowerModeConfig.swift
- VoiceInk/PowerMode/PowerModeViewComponents.swift
- VoiceInk/PowerMode/PowerModeValidator.swift
- VoiceInk/PowerMode/PowerModePopover.swift
- VoiceInk/Views/Settings/PowerModeSettingsSection.swift
The Power Mode Configuration UI provides a comprehensive interface for users to create, manage, and customize "Power Modes." These are context-aware configurations that automatically apply specific transcription and AI enhancement settings based on the active application or website. This system allows for highly automated and tailored workflows, adapting VoiceInk's behavior to different tasks without manual intervention.
The UI is composed of a main view for listing and reordering configurations, and a detailed editor view for creating or modifying individual Power Modes. All configurations are managed by the PowerModeManager singleton, which persists them to UserDefaults.
Sources: VoiceInk/PowerMode/PowerModeView.swift:65-76, VoiceInk/PowerMode/PowerModeConfig.swift:125-128
Core Architecture
The Power Mode feature is built around a few key SwiftUI views and a central manager class. The PowerModeView serves as the entry point, displaying all existing configurations and providing options to add or reorder them. Selecting to add or edit a configuration navigates the user to the ConfigurationView, which is a detailed form for setting up a PowerModeConfig data object.
This diagram illustrates the primary navigation and component flow within the Power Mode UI.
Data Model: PowerModeConfig
The entire feature is centered around the PowerModeConfig struct, which encapsulates all settings for a single Power Mode. This struct is Codable and is stored as an array in UserDefaults.
| Property | Type | Description |
|---|---|---|
id | UUID | A unique identifier for the configuration. |
name | String | The user-defined name of the Power Mode. |
emoji | String | An emoji to visually represent the mode. |
appConfigs | [AppConfig]? | An optional array of applications that trigger this mode. |
urlConfigs | [URLConfig]? | An optional array of website URLs that trigger this mode. |
isAIEnhancementEnabled | Bool | Toggles AI enhancement for this mode. |
selectedPrompt | String? | The UUID of the selected CustomPrompt for AI enhancement. |
selectedTranscriptionModelName | String? | The name of the transcription model to use. |
selectedLanguage | String? | The language for transcription. |
useScreenCapture | Bool | Enables "Context Awareness" by using screen capture. |
selectedAIProvider | String? | The AI provider for enhancement (e.g., "openAI"). |
selectedAIModel | String? | The specific AI model for enhancement. |
isAutoSendEnabled | Bool | If true, automatically presses 'Enter' after pasting text. |
isEnabled | Bool | A toggle to enable or disable the Power Mode. |
isDefault | Bool | If true, this mode is used as a fallback when no other triggers match. |
Sources: VoiceInk/PowerMode/PowerModeConfig.swift:4-21
Management: PowerModeManager
PowerModeManager is a singleton ObservableObject responsible for all CRUD (Create, Read, Update, Delete) operations on PowerModeConfig objects. It loads configurations from and saves them to UserDefaults under the key powerModeConfigurationsV2.
Key responsibilities include:
- Adding, removing, and updating configurations.
- Reordering configurations.
- Finding a matching configuration for a given application
bundleIdor websiteurl. - Setting a configuration as the default.
- Providing a clean, normalized version of URLs for matching.
The following class diagram shows the structure of the PowerModeManager and its relationship with the configuration data models.
Main View (PowerModeView)
This view acts as the dashboard for all Power Modes. It displays a list of all created configurations using PowerModeConfigurationsGrid. Each configuration is rendered in a ConfigurationRow, which provides a summary of its settings and a toggle to enable or disable it.
Key UI elements and actions:
- Add Power Mode Button: Navigates to
ConfigurationViewto create a new mode. - Reorder Button: Toggles a mode where the user can drag and drop configurations to change their priority.
- Configuration List: Shows all
PowerModeConfiginstances. Double-tapping a row opens it for editing. - Empty State: If no configurations exist, a message prompts the user to create one.
Sources: VoiceInk/PowerMode/PowerModeView.swift:59-223, VoiceInk/PowerMode/PowerModeViewComponents.swift:50-293
Configuration Editor (ConfigurationView)
This is the primary interface for creating and editing a PowerModeConfig. It operates in two modes: .add for new configurations and .edit(PowerModeConfig) for modifying existing ones. The view is divided into several logical sections.
Sources: VoiceInk/PowerMode/PowerModeConfigView.swift:4-13
Basic Information
This section captures the name, emoji, and default status of the Power Mode.
- Emoji Picker: A popover (
EmojiPickerView) allows the user to select a visual identifier. - Name Field: A
TextFieldfor the configuration's name. This field is auto-focused on view appearance. - Default Toggle: A
Toggleto set the configuration as the default fallback.
Sources: VoiceInk/PowerMode/PowerModeConfigView.swift:162-200
Triggers ("When to Trigger")
This section defines the conditions under which the Power Mode will be activated.
- Applications: Users can click "Add App" to open an
AppPickerSheet. This sheet lists all installed applications on the system, which are discovered by scanning standard application directories. Selected apps are displayed as a grid of icons. - Websites: A
TextFieldallows users to enter website URLs. The input is cleaned (e.g.,https://www.google.combecomesgoogle.com) before being added as a trigger. Added websites are displayed as tags.
Sources: VoiceInk/PowerMode/PowerModeConfigView.swift:207-313, VoiceInk/PowerMode/PowerModeConfigView.swift:759-803
Transcription & AI Settings
These sections allow for overriding global transcription and AI enhancement settings.
- Transcription Model: A
Pickerlists all usable models fromwhisperState.usableModels. - Language: If the selected model is multilingual, a
Pickerallows specifying a language. This is disabled for certain models like Parakeet or Gemini that only support auto-detection. - AI Enhancement: A master
Toggleenables or disables AI processing. When enabled, the user can configure:- AI Provider & Model: Pickers to select the AI service and specific model.
- Enhancement Prompt: A
PromptSelectionGridto choose from available prompt templates. - Context Awareness: A
Toggleto enable or disableuseScreenCapture.
Sources: VoiceInk/PowerMode/PowerModeConfigView.swift:315-555
Advanced Settings
- Auto Send: A
Toggleto control theisAutoSendEnabledflag, which automatically simulates an "Enter" key press after pasting text. This is useful for chat applications.
Sources: VoiceInk/PowerMode/PowerModeConfigView.swift:557-573
Saving and Validation
When the user clicks the "Save" button, the saveConfiguration function is called. This function orchestrates validation and persistence.
The flow is as follows:
- A
PowerModeConfigobject is created from the current state of the form. - An instance of
PowerModeValidatoris created. validator.validateForSave()is called, which checks for several potential issues.- If validation errors are returned, an alert is shown to the user with the first error message.
- If validation passes,
powerModeManageris used to eitheraddConfigurationorupdateConfiguration. - If the
isDefaultflag is set,powerModeManager.setAsDefault()is called to ensure only one configuration is the default. - The view is dismissed.
This flowchart shows the logic of the save operation.
The PowerModeValidator enforces the following rules before a configuration can be saved:
| Rule | Error Type | Description |
|---|---|---|
| Name is not empty | emptyName | The configuration name cannot be blank. |
| Name is unique | duplicateName | Another Power Mode with the same name already exists. |
| App trigger is unique | duplicateAppTrigger | An application is already used as a trigger in another Power Mode. |
| Website trigger is unique | duplicateWebsiteTrigger | A website URL is already used as a trigger in another Power Mode. |
Sources: VoiceInk/PowerMode/PowerModeValidator.swift:5-30
Summary
The Power Mode Configuration UI is a powerful and flexible feature within VoiceInk that enables deep customization and automation. Through a clear, sectioned interface (ConfigurationView), users can define specific behaviors tied to their active context. The PowerModeManager provides robust, centralized state management, while the PowerModeValidator ensures data integrity, creating a reliable and user-friendly system for managing complex, context-aware workflows.