Skip to content

General: Pick the right monitor mode automatically#591

Merged
d4rken merged 4 commits into
mainfrom
refactor/auto-monitor-mode
May 7, 2026
Merged

General: Pick the right monitor mode automatically#591
d4rken merged 4 commits into
mainfrom
refactor/auto-monitor-mode

Conversation

@d4rken

@d4rken d4rken commented May 7, 2026

Copy link
Copy Markdown
Member

What changed

The "Monitor mode" setting in General Settings has been removed. The app now picks the right mode automatically based on your profile setup — no more guessing whether to use "When app is open", "When device is connected", or "Always".

The choice was always opaque: the right answer depended on whether your profile had a paired device, whether auto-connect was enabled, and whether the BluetoothHeadset reflection trick still works on your Android version. Most users had no way to know which to pick.

Technical Context

  • Resolution rules (primary profile only, by list position): no profile or no paired address → MANUAL; paired + no auto-connect → AUTOMATIC; paired + auto-connect + nudge available/unknown → ALWAYS; paired + auto-connect + nudge known broken → AUTOMATIC.
  • Multi-profile rule is primary-only, not "max across all". AutoConnect only ever targets the primary device, so a secondary profile's autoConnect setting can't actually fire — demanding ALWAYS for it would be wasted scanning.
  • Nudge availability is now tri-state (UNKNOWN/AVAILABLE/BROKEN) persisted in a new NudgeCapabilityStore. UNKNOWN is treated as "assume available" so we get one shot to learn whether nudge works on the device. This replaces the old _isNudgeAvailable: Boolean = true field that reset every process restart, burning battery in ALWAYS mode until the next failed attempt.
  • nudgeConnection() now returns a typed NudgeAttemptResult discriminating success, rejection, missing-permission failures (transient — don't persist BROKEN), and hidden-API failures (persistent). Previously a missing BLUETOOTH_CONNECT would have permanently disabled auto-connect.
  • OverviewViewModel.workerAutolaunch is now reactive to mode changes. It used to only re-evaluate when missingScanPermissions emitted, so a transition AUTOMATIC → ALWAYS (e.g. after enabling auto-connect) wouldn't actually start the monitor. The new combine(...) of permissions + effective mode + connected devices fixes that.
  • DeviceSettingsViewModel no longer imperatively forces ALWAYS when autoConnect is toggled on. The resolver derives that from profile state, which means toggling autoConnect off again now properly relaxes back to AUTOMATIC — previously the bump was sticky.
  • The core.monitor.mode DataStore key on existing installs is silently ignored (Preferences DataStore tolerates orphan keys). No active migration needed.

@d4rken d4rken added the enhancement Add a new feature of improve an existing feature label May 7, 2026
d4rken added 3 commits May 7, 2026 13:33
- Seed connectedDevices flow with onStart so ALWAYS autolaunch fires before HEADSET profile binds

- Gate UnavailableMissingPermission classification on Android 12+ (BLUETOOTH_CONNECT only exists from API 31)

- Treat blank/empty profile.address as unpaired (matches AutoConnect)

- Subscribe DeviceSettingsViewModel to nudgeCapabilityStore.availability so UI updates immediately on verdict change

- Seed availability StateFlow with the persisted value via valueBlocking to close the cold-start race
Consolidate the nudge availability DataStoreValue with the rest of the persisted settings instead of carrying it in a separate Hilt module + DataStore file. Matches the existing convention where compat-style flags (offloaded filtering, indirect callbacks, etc.) live alongside theme/notification settings.

NudgeCapabilityStore keeps the verdict-mapping behavior; only the source of the persisted value changes.
@d4rken d4rken merged commit 83ef111 into main May 7, 2026
11 checks passed
@d4rken d4rken deleted the refactor/auto-monitor-mode branch May 7, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Add a new feature of improve an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant