Skip to content

Add toggle to command mode and write mode - #38

Merged
altic-dev merged 5 commits into
mainfrom
disable-command-and-write-mode
Dec 16, 2025
Merged

altic-dev merged 5 commits into
mainfrom
disable-command-and-write-mode

Conversation

@grohith327

@grohith327 grohith327 commented Dec 4, 2025 •

Copy link
Copy Markdown
Collaborator

Description

  • Add toggle to enable/disable command mode and write mode
  • Store the toggle setting in user defaults to ensure it is remembered after app restarts

Issue #35

Testing

Check recording - https://drive.google.com/file/d/1kXM2nqO8QpyISBx3Bv0wB9tZHYyMCPW6/view?usp=sharing

Summary by CodeRabbit

  • New Features
    • Added per-shortcut toggles for Command Mode and Rewrite Mode in Settings; toggles persist and update the Preferences UI (rows dim and Change is disabled when off).
  • Behavior
    • Turning a shortcut off immediately cancels active recording for that mode, stops speech capture if running, and resets overlays/state; disabled shortcuts no longer trigger.
  • Chores
    • Minor cleanup to import/preprocessor guards.

✏️ Tip: You can customize this high-level summary in your review settings.

@grohith327
grohith327 requested a review from altic-dev December 4, 2025 16:26
@coderabbitai

coderabbitai Bot commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds per-shortcut enable toggles for command and rewrite modes, persists them in SettingsStore, exposes bindings to SettingsView and ContentView, and updates GlobalHotkeyManager to gate shortcut handling and clear/cleanup active mode state when a shortcut is disabled.

Changes

Cohort / File(s) Change Summary
Settings Persistence
Sources/Fluid/Persistence/SettingsStore.swift
Added keys and persisted Bool properties commandModeShortcutEnabled and rewriteModeShortcutEnabled (defaults true) with UserDefaults persistence and observer notification.
App State & UI Wiring
Sources/Fluid/ContentView.swift
Added @State flags isCommandModeShortcutEnabled and isRewriteModeShortcutEnabled initialized from SettingsStore; propagated bindings to Preferences/Settings views; added onChange handlers that update SettingsStore, call hotkey manager update methods, and perform cleanup (cancel recordings, stop ASR, reset overlay) when a flag is disabled.
Hotkey Management
Sources/Fluid/Services/GlobalHotkeyManager.swift
Extended initializer to accept both enabled flags; added updateCommandModeShortcutEnabled(_:) and updateRewriteModeShortcutEnabled(_:); introduced gating so command/rewrite handling only runs when respective flag is true and clears per-mode pressed state when disabling.
Settings UI Controls
Sources/Fluid/UI/SettingsView.swift
Added @Binding properties commandModeShortcutEnabled and rewriteShortcutEnabled; shortcutRow gains isEnabled param; UI shows per-shortcut Toggle, disables Change buttons and adjusts opacity when shortcut is disabled.
Noise/Import Cleanup
Sources/Fluid/Networking/ModelDownloader.swift
Removed duplicate import Foundation and redundant nested preprocessor guard; import structure simplified (no behavioral change).

Sequence Diagram

sequenceDiagram
    participant User
    participant SettingsView
    participant ContentView
    participant SettingsStore
    participant GlobalHotkeyManager

    User->>SettingsView: Toggle shortcut enable/disable
    SettingsView->>ContentView: Bound state updates
    ContentView->>SettingsStore: set commandModeShortcutEnabled / rewriteModeShortcutEnabled
    SettingsStore->>SettingsStore: persist to UserDefaults
    ContentView->>GlobalHotkeyManager: updateCommandModeShortcutEnabled(enabled) / updateRewriteModeShortcutEnabled(enabled)
    GlobalHotkeyManager->>GlobalHotkeyManager: update flag & clear per-mode pressed state if disabled
    alt If disabled while active
        ContentView->>ContentView: cancel recording, stop ASR, clear mode state, reset overlay
    end
    SettingsView->>SettingsView: reflect UI (toggle position, opacity, disable buttons)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Review GlobalHotkeyManager: ensure all keyDown/keyUp and modifier-only paths consistently check enabled flags and that state clearing on disable is complete.
  • Inspect ContentView onChange handlers for duplication and correct ordering (SettingsStore update -> hotkeyManager update -> recording/ASR cleanup).
  • Verify binding propagation to SettingsView avoids feedback loops and that UI disables recording controls correctly.

Possibly related PRs

  • Intel changes #51 — Overlaps changes to ContentView, SettingsView, and SettingsStore adding settings/UI wiring for shortcuts.

Poem

🐰 I toggled a key with a twitch of my paw,

Shortcuts now mind when I say “no more.”
If command or rewrite decide to sleep tight,
I hush the recorder and dim the light.
Hoppity hops — settings snug and light. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding toggle controls to enable/disable command mode and write mode shortcuts, which is fully reflected in the changeset across multiple files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch disable-command-and-write-mode

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ed7a71 and 8d10ad1.

📒 Files selected for processing (1)
  • Sources/Fluid/UI/SettingsView.swift (4 hunks)
🔇 Additional comments (3)
Sources/Fluid/UI/SettingsView.swift (3)

28-29: LGTM: New toggle state bindings added.

The new commandModeShortcutEnabled and rewriteShortcutEnabled bindings integrate cleanly with the existing state management pattern.


302-330: LGTM: Toggle bindings wired correctly for Command and Write modes.

The selective application of isEnabled bindings to only Command Mode and Write Mode shortcuts aligns with the PR objectives, while Transcribe Mode remains always enabled by design.


794-870: LGTM: Well-structured toggle implementation with good UX decisions.

The refactored shortcutRow implementation demonstrates several strengths:

  • The optional isEnabled parameter (line 802) with nil default maintains backward compatibility for shortcuts that don't support toggling.
  • The two-section VStack layout (header with toggle, then shortcut controls) provides clear visual hierarchy.
  • Disabling the Change button when !enabledValue (line 866) prevents state inconsistencies—users must enable the shortcut before modifying it.
  • The conditional recording prompt (line 836) correctly gates on both isRecording && enabledValue.
  • Row-level opacity (line 869) provides appropriate visual feedback for disabled state without readability issues.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
Sources/Fluid/UI/SettingsView.swift (1)

28-29: Shortcut enable toggles and disabled-row behavior look consistent end‑to‑end

  • The new @Binding flags for commandModeShortcutEnabled / rewriteShortcutEnabled, their use in the two VStacks, and the isEnabled handling in shortcutRow are wired coherently: disabling hides the live shortcut text, shows a “Shortcut disabled” pill, disables the Change button, and slightly dims the row while leaving the feature itself intact.
  • State cancellation on disable (handled in ContentView via the bindings) ensures you won’t get stuck in a “recording new shortcut” UI while the row is disabled.

No functional issues from this file for the new toggles; behavior is clear and matches the PR intent.

You might later consider a brief footnote/help text near each toggle explaining that it only disables the shortcut (not Command/Write Mode entirely), to avoid user confusion in settings-heavy UIs.

Also applies to: 302-347, 810-880

Sources/Fluid/Persistence/SettingsStore.swift (1)

51-52: Persistence for per‑mode shortcut enable flags is correct; consider regrouping constants

  • The commandModeShortcutEnabled / rewriteModeShortcutEnabled properties correctly default to true when unset and send objectWillChange on writes, which matches how you use them in ContentView + SwiftUI.
  • Minor organizational nit: Keys.rewriteModeShortcutEnabled currently sits under the “Model Reasoning Config Keys” section (Line 61). For readability, it would be clearer to keep it adjacent to the other “Rewrite Mode Keys” so all rewrite settings live together.

Also applies to: 61-62, 413-423, 592-602

Sources/Fluid/Services/GlobalHotkeyManager.swift (1)

13-14: Shortcut enable flags and gating in the hotkey handler are sound

  • The new commandModeShortcutEnabled / rewriteModeShortcutEnabled fields, constructor parameters, and update methods correctly gate command/rewrite handling in all three event paths (keyDown, keyUp, flagsChanged).
  • Clearing isCommandModeKeyPressed / isRewriteKeyPressed when disabling avoids press‑and‑hold scenarios leaving the internal state stuck while ContentView separately stops ASR.

Implementation is functionally solid.

If you want to reduce duplication later, you could wrap the command/rewrite checks in small helpers (e.g. handleCommandShortcutIfEnabled(...)) so the handleKeyEvent branches read a bit more linearly.

Also applies to: 35-42, 52-53, 108-124, 269-314, 333-345, 367-399

Sources/Fluid/ContentView.swift (1)

56-57: End‑to‑end wiring of shortcut enable flags is correct and handles disable‑while‑active safely

  • The new @State flags seeded from SettingsStore and passed into SettingsView and GlobalHotkeyManager form a coherent data flow: settings are persisted, UI reflects current state, and the event tap respects the enable flags.
  • The .onChange handlers for isCommandModeShortcutEnabled and isRewriteModeShortcutEnabled correctly:
    • persist to SettingsStore,
    • notify hotkeyManager (if present),
    • and, on disable, cancel any in‑progress shortcut recording, stop ASR for the corresponding mode, clear rewrite state, and reset the overlay to dictation.

This covers the main correctness and UX edge case (turning a mode off mid‑recording) cleanly.

If similar “disable while active” flows crop up elsewhere, consider extracting tiny helpers (e.g. cancelActiveCommandShortcutIfNeeded()) to keep the main body modifier chain thinner.

Also applies to: 507-539, 923-924, 3633-3639

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 60234a0 and b6f15e5.

📒 Files selected for processing (4)
  • Sources/Fluid/ContentView.swift (4 hunks)
  • Sources/Fluid/Persistence/SettingsStore.swift (4 hunks)
  • Sources/Fluid/Services/GlobalHotkeyManager.swift (10 hunks)
  • Sources/Fluid/UI/SettingsView.swift (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
Sources/Fluid/UI/SettingsView.swift (1)
Sources/Fluid/Services/DebugLogger.swift (1)
  • debug (145-147)
Sources/Fluid/Services/GlobalHotkeyManager.swift (1)
Sources/Fluid/Services/DebugLogger.swift (1)
  • info (133-135)
Sources/Fluid/ContentView.swift (4)
Sources/Fluid/Services/GlobalHotkeyManager.swift (2)
  • updateCommandModeShortcutEnabled (108-115)
  • updateRewriteModeShortcutEnabled (117-124)
Sources/Fluid/Services/ASRService.swift (1)
  • stopWithoutTranscription (411-426)
Sources/Fluid/Services/MenuBarManager.swift (1)
  • setOverlayMode (197-200)
Sources/Fluid/Services/RewriteModeService.swift (1)
  • clearState (103-108)

@grohith327

Copy link
Copy Markdown
Collaborator Author
CleanShot 2025-12-15 at 17 11 08

Moved the shortcut change button and display below to render the toggle on the right and keep things symmetrical

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Sources/Fluid/UI/SettingsView.swift (1)

824-829: Optional: Add accessibility label to toggle.

The toggle uses .labelsHidden() but lacks an explicit accessibility label for screen readers.

Consider adding an accessibility label:

                if let isEnabled {
                    Toggle("", isOn: isEnabled)
                        .toggleStyle(.switch)
                        .tint(theme.palette.accent)
                        .labelsHidden()
+                        .accessibilityLabel("Enable \(title) shortcut")
                }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6f15e5 and 2ed7a71.

📒 Files selected for processing (2)
  • Sources/Fluid/Networking/ModelDownloader.swift (0 hunks)
  • Sources/Fluid/UI/SettingsView.swift (4 hunks)
💤 Files with no reviewable changes (1)
  • Sources/Fluid/Networking/ModelDownloader.swift
🔇 Additional comments (3)
Sources/Fluid/UI/SettingsView.swift (3)

28-29: LGTM! New bindings properly added.

The new binding properties for controlling shortcut enablement are correctly declared and follow the existing pattern.


287-330: LGTM! Enable/disable applied correctly to command and write modes.

The implementation correctly provides enable/disable toggles only for command mode and write mode shortcuts, while keeping transcribe mode always enabled. This aligns with the PR objectives.


802-870: The recording state is already properly cleared when shortcuts are disabled. ContentView includes onChange handlers for both isCommandModeShortcutEnabled and isRewriteModeShortcutEnabled that explicitly set the recording flags to false and stop the ASR service when a shortcut is disabled.

Comment thread Sources/Fluid/UI/SettingsView.swift Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants