Add support for choosing custom audio input
Description
Add support for choosing custom audio input separate from MacOS default. The following is the behavior
- Toggle on: input dropdown stays enabled.
- Toggle on + user changes input: FluidVoice immediately syncs that selection to the Mac default input.
- Toggle off + user changes input: FluidVoice only saves the manual preference and does not immediately change the Mac input.
- Toggle on transition still restores/syncs back to the captured system input when available.
Also, add a menu bar setting to toggle micrphone
Type of Change
- [ ] ๐ Bug fix
- [x] โจ New feature
- [ ] ๐ฅ Breaking change
- [ ] ๐งน Chore
- [ ] ๐ Documentation update
Related Issue or Discussion
Closes #136
Testing
- [ ] Tested on Intel Mac
- [x] Tested on Apple Silicon Mac
- [x] Tested on macOS version: 27
- [x] Ran linter locally:
swiftlint --strict --config .swiftlint.yml Sources - [x] Ran tests locally
Screenshots / Video
https://github.com/user-attachments/assets/8506c208-6379-4a73-8b91-b57879c977f7
@altic-dev Good to review, tested with the new audio optimized pipeline
@greptileai review
Greptile Summary
This PR introduces a MicrophoneSelectionMode enum (.system / .manual) to replace the previously inert syncAudioDevicesWithSystem stub, adds a new MicrophonePreferenceCoordinator that centralises preferred-device enforcement with retry logic, and surfaces both a Settings-panel toggle and a menu-bar item for switching between modes.
MicrophonePreferenceCoordinatorโ new testable coordinator withAudioDeviceManagingprotocol injection; handles enforcement, fallback, and hardware-change stabilisation.SettingsStore.setMicrophoneSelectionModeโ atomically transitions modes, saves the pre-manual system UID for restoration, and returns the UID to restore on.systemre-entry.- One confirmed desync โ
ContentView.microphoneSelectionModeis a@Stateinitialised once fromSettingsStore; changes made via the menu bar are not reflected in the binding passed toSettingsView, causingonChange(of: inputDevices)to branch on the wrong mode after a menu-bar toggle.
Confidence Score: 4/5
Safe to merge after addressing the mode-binding desync between the menu bar and SettingsView.
The menu bar can change SettingsStore.microphoneSelectionMode independently of the @State copy held by ContentView. After such a toggle, SettingsView.onChange(of: inputDevices) branches on the stale local value, which can silently reset selectedInputUID to the system default even when the user just enabled manual mode. The coordinator design, SettingsStore transitions, recording-path device resolution, and test coverage are all solid.
Sources/Fluid/ContentView.swift โ the microphoneSelectionMode @State needs to be kept in sync with SettingsStore when the mode is changed via the menu bar.
Reviews (6): Last reviewed commit: "fix for preferred device being unavailab..." | Re-trigger Greptile
Greptile Summary
This PR introduces a MicrophoneSelectionMode enum (.system / .manual) to replace the always-true syncAudioDevicesWithSystem flag, giving users explicit control over whether FluidVoice follows the macOS default input or locks to a preferred microphone. A new MicrophonePreferenceCoordinator service centralizes enforcement of the preferred device โ re-asserting it after hardware topology changes โ and is injected via a lazy property on AppServices.
- New coordinator:
MicrophonePreferenceCoordinatorprovidesenforcePreferredInput,inputDeviceForCapture, and a debouncedstabilizePreferredInputAfterHardwareChangewith a progressive retry schedule; aAudioDeviceManagingprotocol makes it fully unit-testable viaFakeAudioDeviceManager. - Settings & menu bar: a toggle is added to both the Settings panel and the menu bar microphone submenu;
SettingsStore.setMicrophoneSelectionModesnapshots the system UID before entering manual mode so it can be restored on toggle-off. - One defect identified: the hardware-change handler in
ContentViewsetsselectedInputUIDto the stored preferred UID without verifying the device is still in the refreshed device list, leaving the picker blank when the preferred device disconnects.
Confidence Score: 3/5
The core recording path correctly delegates device resolution to MicrophonePreferenceCoordinator, which handles device unavailability safely. However, the ContentView hardware-change handler leaves the picker UI in a broken blank state when a preferred device disconnects in manual mode.
The device-availability check dropped from the ContentView hardware-change .manual branch is a real UI regression: after the preferred device is unplugged, the Picker renders no matching item while the stored UID persists, and neither the ContentView handler nor the SettingsView .onChange(of: inputDevices) recovers it. The actual recording path falls back correctly, but the UI state is wrong and will mislead users.
Sources/Fluid/ContentView.swift โ hardware-change handler for .manual mode needs an availability check with a system-default fallback.
Prompt To Fix All With AI
Fix the following 3 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 3
Sources/Fluid/ContentView.swift:365-368
**Preferred-device unavailability not handled after hardware change**
In `.manual` mode the hardware-change handler now sets `selectedInputUID` to the stored `preferredInputDeviceUID` unconditionally, even when the device was just disconnected. Because `refreshDevices()` runs first, `inputDevices` is already up-to-date, so the picker immediately shows a UID that is not in the list โ the selection renders blank/missing. The old implementation guarded against this with an availability check and fell back to the system default, which needs to be restored here. Note: `MicrophonePreferenceCoordinator.inputDeviceForCapture()` does fall back correctly for the actual recording path, but the UI state is left stale.
```suggestion
case .manual:
if let prefIn = SettingsStore.shared.preferredInputDeviceUID,
self.inputDevices.contains(where: { $0.uid == prefIn })
{
self.selectedInputUID = prefIn
} else if let sysIn = AudioDevice.getDefaultInputDevice()?.uid {
self.selectedInputUID = sysIn
}
```
### Issue 2 of 3
Sources/Fluid/Services/AppServices.swift:71-79
**Manual lazy-init pattern is not thread-safe; prefer `lazy var`**
The same manual double-check pattern is used for `_asr`, so it's consistent with the existing style, but `MicrophonePreferenceCoordinator` is `@MainActor`-isolated and is accessed from multiple call sites. Swift's `lazy var` is automatically initialized on first access and is thread-safe for value-type initialization, making intent clearer and removing the possibility of a race if the surrounding class ever stops being exclusively main-actor-accessed.
```suggestion
lazy var microphonePreferenceCoordinator: MicrophonePreferenceCoordinator = MicrophonePreferenceCoordinator()
```
### Issue 3 of 3
Sources/Fluid/Services/MenuBarManager.swift:621-647
**Duplicated mode-toggle logic diverges from SettingsView**
`MenuBarManager.toggleMicrophoneSelectionMode` and `SettingsView.updateMicrophoneSelectionMode` implement the same "switch mode and seed the manual preference" flow independently. The key difference: the menu-bar path checks `SettingsStore.shared.preferredInputDeviceUID` to decide whether to seed a default, while the settings-view path checks the local UI binding `selectedInputUID`. This means flipping the toggle from the menu bar when `preferredInputDeviceUID` already holds a value will skip seeding (correct), but if the state somehow diverges the two call-sites will behave differently. Extracting the shared transition logic into `SettingsStore.setMicrophoneSelectionMode` (or a dedicated coordinator method) would remove this maintenance risk.
Reviews (2): Last reviewed commit: "centralize microhpone input irrespective..." | Re-trigger Greptile
@greptileai review latest changes