Commit Graph

46 Commits

Author SHA1 Message Date
Jonas Bark
b85264369a fix(overlay/ios): reuse the Live Activity instead of orphaning one per ride
A rider's diagnostics (iOS 26.6, 6.4.3) carried this four times inside a
minute, with "virtual shifting isn't working" attached:

  PlatformException(LIVE_ACTIVITY_ERROR, can't launch live activity,
  Maximum number of activities for target already exists)

That is ActivityKit's `targetMaximumExceeded`. On iOS the Live Activity IS
the gear overlay — the only place a rider can read BikeControl's virtual
gear, because trainer apps never show it — so once it fires the readout is
dead until the phone reboots.

show() minted a fresh random activity name and called createActivity every
time, and the id it got back lived only in this isolate's memory. Every
force-quit, engine restart or swiped-away activity therefore left an
activity behind that still held one of ActivityKit's per-target slots, and
nothing ever went looking for it. After enough rides the target is full and
every request throws.

- Query what iOS actually holds, adopt the one activity that is still
  live (updateActivity writes under its own attributes prefix, so an
  activity from a previous launch picks up fresh gear data), and end
  everything else before requesting anything.
- Collapse overlapping show() calls onto one in-flight future, so a
  trainer app flapping its connection can't queue up requests.
- Retry once after sweeping everything when the request still throws:
  `Activity.activities` reads empty for a beat after a cold start, which
  the plugin works around the same way in createOrUpdateActivity.
- Ask for removeWhenAppIsKilled so a graceful termination frees the slot.
- Use a stable activity name, which also stops each ride from leaking a
  new set of never-collected App Group UserDefaults keys.
- A show() that starts nothing now reports isShowing == false, instead of
  leaving the Overlay switch and the auto-show guard claiming an overlay
  the rider cannot see.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 11:07:00 +02:00
Jonas Bark
dc715c9cf2 feat(home): offer local control too, and make the offers act rather than point
Three things a rider asked for, all on the same idea: an offer's button should
do the thing, and nothing should be labelled optional that is plainly working.

- "Enable overlay" now enables the overlay and *then* opens the Overlay
  section. A button that only navigates to another switch is the toast
  problem again, one tap further along. The enable path moved into a shared
  enableTrainerOverlay(), run by both the section's switch and the step, so
  the two cannot drift; it persists the flag only when the platform actually
  put something on screen, so declining Android's draw-over prompt can't
  leave a setting claiming an invisible overlay. A refusal says why, and the
  page opens anyway — that is where the permission tile lives.

- New optional step on the app card: "Add keyboard and mouse actions",
  offered when Local is available on this device but switched off (target is
  This device, per CoreLogic.showLocalControl) and an app is chosen. Local is
  not a way to reach the app, it is a way to do more to it — keystrokes and
  clicks the button editor only offers once it is on — and a rider who never
  turns it on never learns those actions exist. Its button runs the existing
  enableLocalControl(), permission sheet and all.

- The card header drops its OPTIONAL tag once the link is off "off". The
  link stays optional underneath, which is what keeps a trainer nobody owns
  from blocking "Ready to ride", but the word is there to reassure someone
  looking at an empty slot — not to caption connected hardware.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 14:52:46 +02:00
Jonas Bark
f0d2d1253b feat(home): make the gear overlay an optional checklist step, not a toast
Riders keep writing in about the wrong gear number in MyWhoosh and others.
The answer has always been the gear overlay, and the one-time toast that said
so was the wrong messenger: it fired once, mid-connect, and scrolled away
before anyone read it.

Move the offer onto the trainer card, where it stays until it is acted on.

- New SetupStepId.trainerGearOverlay, last in the trainer checklist and
  offered only once the bridge is up, the trainer app runs on this device
  (Target.thisDevice), the platform can draw an overlay, and a Virtual
  Shifting session is producing a gear to draw. Ticks off — and leaves the
  card — as soon as the overlay is enabled.
- Its button reads "Enable overlay" and deep-links to the trainer detail
  page's Overlay section, which owns the permission and PiP flows.
- SetupStep gains an `optional` flag so an offer stays an offer: it does not
  colour the card, does not count towards the banner's steps, and never
  stops "Ready to ride". Marked OPTIONAL on its own line, via the tag the
  card header already wore (now a shared OptionalTag).
- Drops OverlayConnectHint, its ProxyDevice listener and the
  overlay_connect_hint_shown flag. The two l10n strings it owned are reused
  as the step's hint and button label in all six locales.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-16 13:03:56 +02:00
Jonas Bark
f4c8aba982 feat: overlay hint when trainer app first connects
Nearly every MyWhoosh/Rouvy bridge rider pairs the virtual trainer, then
writes support asking why the gear shown in the trainer app doesn't sync
— trainer apps can't display BikeControl's virtual gears. Surface the
canonical answer (the gear overlay) exactly once, at the moment the
question would otherwise arise: the first time a trainer app connects to
the virtual trainer while the overlay is off.

- OverlayConnectHint fires an AlertNotification (toast + activity-log
  entry) whose button deep-links to the trainer detail page, scrolled to
  the Overlay section (new revealOverlaySection param).
- Hooked on ProxyDevice's device-level isConnected wrapper so it
  survives emulator/mode swaps; gated on an active VS session
  (fitnessBike != null), overlay disabled, and a persisted one-time
  flag (overlay_connect_hint_shown).
- New l10n strings in all six locales.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-14 14:06:24 +02:00
Jonas Bark
db5cc74a12 fix(erg,sram): shared ERG stepping with boundary guards; scope §7 guard to shifting-enabled; coalesce iOS echo presses
ERG (review findings on the ±5W change):
- New ErgPowerStepping extension is the single home for the 5W step and
  500W manual cap, replacing 7 inline copies (physical buttons, hero-card
  buttons/slider, three overlay controllers).
- Boundaries are guards, not clamps: up at >=500W is a no-op like the
  disabled UI button (a 600W FTMS target is no longer slashed to 500),
  down from >500W steps relative, and an unknown baseline (hub-commanded
  ERG reports no target) is a no-op with a new localized message instead
  of slamming the trainer to ~150W.
- ERG shift-up Success carries the button again so +5W presses show
  activity feedback (missed conversion from 843f7985).

SRAM gesture:
- Same-lever repeats inside the 90ms combo window coalesce as duplicates:
  a finger can't re-press in 90ms, but iOS re-delivers a colliding read
  response of the 0xFF edge through the notify callback — it must not
  actuate twice (nor break a combo when it misdecodes to the other lever).
- The §7 multishift guard only runs while shifting is enabled — the one
  state where a held paddle actually bursts (per c94b87f0's --observe
  capture). Bonded rapid tapping and both-lever combos are never
  throttled. Timer-driven instead of DateTime.now() (deterministic under
  fakeAsync) and cleared by _resetGesture on (re)connect.
- The "set up SRAM control" warning fires once per connection, not on
  every undecoded press.

Harness:
- EmulationSession.notify drops notifications for removed peripherals so
  delayed notifies (SRAM double-tap) can't land after teardown.
- The 0xFF press edge is SramAxsConstants.triggerEdge at all call sites;
  the emulation test waits on the named TRIGGER_UUID constant.
- New coverage: guard behavior through processCharacteristic in both
  states, burst suppression while unbonded, all-taps-delivered once
  bonded, ERG boundary/game-set-target cases.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 17:51:35 +02:00
Jonas Bark
82917c3c9d fix(overlay): widen drag hit area; fix PiP show/hide race; orientation-safe DI detection
- The floating overlay's drag handle now fills the full 24px trailing slot
  instead of only the 14px icon.
- iOS overlay: arm PiP only while still showing and tear it down if a hide
  lands mid-start(), so a show/hide race can't orphan a frozen PiP window.
- Detect Dynamic Island via the max safe-area inset instead of the top inset,
  which collapsed in landscape and could auto-start an unwanted PiP.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 19:58:26 +02:00
Jonas Bark
ff57b005d5 feat(shifting): show 2×N gear position when the front derailleur is active
With the virtual front derailleur on, the compact gear readout switches
from rear gear/total (14/25) to head-unit-style front×rear position
notation (small ring 1×N, large ring 2×N, e.g. 2×14) — matching how
Garmin/Wahoo display Di2/AXS gearing. With it off, it stays 14/25.

- Add tested formatGearReadout helper.
- Wire into the proxy card, debug menu, desktop second window + Android
  PiP/overlay (trainer_overlay_view), and the gear hero card (2× · 50T).
- Carry frontShiftEnabled + frontRingLarge through TrainerOverlayState
  (json, ==, hashCode, activity map) so the snapshot reaches the overlay
  and the iOS surfaces.
- iOS PiP + Live Activity: format 2×N centrally in GearSnapshot.
- Standardize the off-state readout to 14/25 across all surfaces.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 15:02:40 +02:00
Jonas Bark
b60876e6dd feat(pip): opt-in on Dynamic-Island iPhones + immediate floating window on iPad
- New "Floating window (Picture-in-Picture)" overlay setting (iOS 16+). Default
  follows the per-device auto behavior (on for iPad / non-DI iPhones, off for
  Dynamic-Island iPhones); DI-iPhone users can opt in. The Live Activity keeps
  running alongside it (additive).
- iPad: start PiP immediately on activation (foreground) instead of only when
  backgrounded — there's screen room (DeviceCapabilities.prefersForegroundPip +
  scheduleForegroundStart poll).
- DeviceCapabilities.isPipCapable (any iOS 16+ PiP device) + bike_control/pip_ios
  "isCapable"; settings.getOverlayUsePip/setOverlayUsePip; show() resolves the
  preference.
- requiresLinearPlayback = true to drop the PiP skip/scrub (next/prev) controls
  (it's a live HUD; central play/pause is system chrome, harmless no-op).
- overlayUsePip + overlayUsePipSubtitle in all 6 languages; changelog updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 18:50:33 +02:00
Jonas Bark
842eaeab4d fix(overlay): guard PiP stop() in hide() so _pipActive always resets
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 18:19:46 +02:00
Jonas Bark
f4130d1dad feat(overlay): drive PiP gear window from IosOverlayController on eligible devices 2026-06-24 18:19:46 +02:00
Jonas Bark
69af34f1cb feat(overlay): add IosPipController + shared overlayStateToActivityMap 2026-06-24 18:19:46 +02:00
Jonas Bark
9648e5e604 overlay/ios: add Dynamic Island stop button that disconnects all devices
Replaces the trailing mode pill in the Dynamic Island expanded
region (which was redundant — the bottom row already shows the
SIM/ERG pill) with an `xmark.circle.fill` button.

Tapping the button:
1. Fires a new `StopRideIntent` App Intent.
2. That intent posts a Darwin notification
   `de.jonasbark.swiftcontrol.overlay.action.stop`.
3. `AppDelegate.swift`'s observer forwards `action: 'stop'` over
   the `bike_control/overlay_actions_ios` MethodChannel.
4. `IosOverlayController._stopRide`:
     - `core.connection.disconnectAll()`
     - `core.connection.stop()`
     - `core.settings.setOverlayEnabled(false)` so Navigation's
       auto-show doesn't immediately re-open the activity on the
       next BLE reconnect.
     - `hide()` ends the Live Activity.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 09:42:56 +02:00
Jonas Bark
abf52e4d7a overlay: re-resolve live FitnessBikeDefinition + fix macOS close + recordError
Fixes the user-reported bugs after the auto-show landed:

1. Auto-opened overlay buttons did nothing
   The trainer emulator rebinds a fresh FitnessBikeDefinition each time
   its transport restarts (e.g. when a trainer app connects), so the
   `def` captured at show() time can already be stale by the time the
   user taps + / −. Action handlers now re-resolve through a new
   `LiveDefinitionLookup` callback on every dispatch. Navigation's
   auto-show and OverlaySettingsSection's manual show both pass a
   lookup that reads `device.emulator.activeDefinition` live.

2. Toggling "Show overlay during ride" off didn't close the panel
   The vendored macOS plugin's `closeWindow` handler ignored its args
   and called `closeWindow(NSApp.mainWindow)`, which either terminated
   the app or no-op'd silently. Patched it to honor
   `isMainWindow: false` and close the (single) secondary window.

3. "Error in overlay.position.decode: Unexpected character: light"
   The vendored macOS plugin packs the Dart entrypoint args in the
   order [routeName, theme, argsJson]; the Windows runner uses
   `std::map` iteration order. The sub-window was indexing `args[1]`
   blindly. Now it scans `args[1..]` for the first JSON-looking
   payload with `x`/`y`.

Also:
- TrainerOverlayController.show now takes optional `liveDef`; all
  three implementations (desktop, android, ios) thread it through.
- Navigation initState no longer early-`return`s after auto-show, so
  the post-frame system-UI / changelog logic still runs.
- All silent `catch (_) {}` blocks in the overlay code now forward
  via `recordError(e, s, context: '...')`. New project memory
  entry [feedback_record_error.md] documents the rule.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:48:53 +02:00
Jonas Bark
e4ad6135eb overlay: auto-show on startup when trainer connects + remove debug logs
Auto-show:
- Navigation initState now subscribes to core.connection.connectionStream
  when the persisted overlay_enabled flag is true. The first connected
  smart trainer with a FitnessBikeDefinition triggers
  TrainerOverlayService.show(...) with the persisted overlay fields.
- Subscription is one-shot (cancels itself after a successful show) and
  also checks already-connected devices on mount, so the overlay reopens
  whether the trainer was reconnected before or after Navigation mounted.

Debug-log cleanup:
- Removed the `bikecontrol_dart_alive.log` liveness probe, the
  `[main:entry]` / `[main:entry/stderr]` print + stderr.writeln, the
  `[overlay-main]` step-by-step logs in the sub-window dispatch, the
  `[main:wm-spy]` channel-handler wrapper, the `[overlay-run]` /
  `[overlay-sub]` action logs in desktop_overlay_window, the
  `[overlay-main]` action-receive / dispatch-fail logs in
  desktop_overlay_controller, the `[main]` Android handler-retry logs,
  and the noisy `[multi_window_native] CreateNewWindow` cerr in the
  Windows runner.
- Kept catch handlers as silent (or kDebugMode-guarded) where the
  original error path was still useful.

Also: MainFlutterWindow simplified back to NSWindow — the vendored
multi_window_native plugin now creates the overlay sub-window as an
NSPanel with .screenSaver level + .fullScreenAuxiliary itself, so
the main window no longer needs the canBecomeMain/canBecomeKey
NSPanel overrides or the .normal level pin.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:35:31 +02:00
Jonas Bark
6a69efb5d4 overlay/desktop: fix macOS sub-window size + fullscreen elevation timing
Two macOS regressions reported by the user:

- Initial sub-window size way too large. multi_window_native's macOS
  plugin hard-codes the sub-window at 1000x1000 with minSize 800x900
  (see plugin source createNewWindow ~line 148). Override from Dart
  in `_runOverlay`: setMinimumSize(180, 100) then setSize(220, 140).

- Overlay no longer appears above fullscreened trainer apps. The
  plugin fires `onEngineCreatedCallback` BEFORE it creates the
  NSWindow + sets its contentViewController, so our previous single
  `DispatchQueue.main.async { ... }` raced the plugin's own setup and
  found nothing in NSApp.windows. Retry up to 30 times (0.1s apart)
  until the window with our `engine` appears, then apply
  `.statusBar` level + `.fullScreenAuxiliary` collection behaviour.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:05:41 +02:00
Jonas Bark
3d5a2b5521 fix background 2026-05-12 11:56:48 +02:00
Jonas Bark
a416f59411 overlay/desktop: fix zone mismatch, transparent macOS bg, action diagnostics
Three issues:

1. Zone mismatch from runApp:104. The diagnostic
   `WidgetsFlutterBinding.ensureInitialized()` + ping MethodChannel call
   ran BEFORE `runZonedGuarded` and bound the binding to the root zone;
   `runApp` then fired inside the zone -> mismatch. Removed the outer
   diagnostic — Dart liveness is no longer the unknown here, and the
   file-write probe at the top of main() still confirms it if needed.

2. Black window background looks bad on macOS. Win32 can't do real
   transparency without WS_EX_LAYERED, so it needs the dark fill, but
   macOS handles NSWindow alpha properly via window_manager. Make the
   Scaffold backgroundColor platform-conditional:
   - Windows: opaque 0xFF111114
   - everything else: transparent

3. Button events from the overlay don't arrive in the main app. Adding
   debugPrint at both ends ([overlay-sub] −/+ tap and [overlay-main]
   action received) to see where the BroadcastToAll → Dart listener
   chain breaks. Behaviour unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 11:27:17 +02:00
Jonas Bark
960a12d077 overlay/desktop: use multi_window_native on both platforms with selective plugin registration
Drop desktop_multi_window entirely; unify macOS + Windows on
multi_window_native. Windows runner re-gets the CreateNewWindow /
CloseWindow / SetMainWindowMethodHandler plumbing with selective
sub-engine registration (only WindowManagerPlugin +
MultiWindowNativePlugin) to avoid the deadlock caused by full
RegisterPlugins on secondary engines. macOS MainFlutterWindow narrows
onEngineCreatedCallback from RegisterGeneratedPlugins to the same two
plugins for consistency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 11:14:05 +02:00
Jonas Bark
20fc10395d overlay/desktop: use desktop_multi_window on Windows, keep multi_window_native on macOS
Add `desktop_multi_window: ^0.3.0` alongside `multi_window_native: ^1.0.4`.
On Windows the sub-window is now spawned via `WindowController.create` with a
JSON `role=trainer-overlay` argument (detected in `main()` before any heavy
bootstrap), and state/actions flow over `WindowMethodChannel(kOverlayChannel)`.
macOS continues using `MultiWindowNative.createWindow` / `notifyAllWindows` /
`registerListener` unchanged.

Windows runner reverts all `multi_window_native` plumbing:
`SecondaryWindowContext`, `CreateNewWindow`, `CloseWindow`,
`SetMainWindowMethodHandler`, and the plugin source compiled directly into the
runner are removed. `flutter_window.cpp` instead registers
`DesktopMultiWindowSetWindowCreatedCallback` so every sub-engine gets plugins.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:33:14 +02:00
Jonas Bark
b5a300db66 overlay/desktop: add diagnostic prints to sub-window boot
Even a flat Container doesn't render in the sub-window on Windows.
Need to know whether Dart main() reaches runApp at all — if
`wm.windowManager.waitUntilReadyToShow()` or `getId()` blocks, the
engine never gets widgets to paint and we see the Win32 background
brush regardless of widget tree.

These prints land on the console attached to `flutter run` and will
show us the exact step that stalls.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 10:00:08 +02:00
Jonas Bark
202b321d6f overlay/desktop: drop WindowOptions setup that wedges the Windows sub-window
`waitUntilReadyToShow(WindowOptions(...))` tries to apply size +
titleBarStyle + backgroundColor + alwaysOnTop all at once. On Windows
that combination misbehaves:

- `Colors.transparent` background can't be honoured without
  `WS_EX_LAYERED`, so it ends up filling the window with white.
- `TitleBarStyle.hidden` rewrites window styles mid-startup, which the
  sub-window's render surface doesn't recover from — the engine paints
  once at the wrong size and then sits idle.

The package example's `SecondScreen` never calls `waitUntilReadyToShow`
with options. Match that: apply each setting individually after the
engine boots — set alwaysOnTop, minimumSize, hasShadow, and (macOS only)
visibleOnAllWorkspaces. No titleBarStyle/backgroundColor on Windows.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 09:35:46 +02:00
Jonas Bark
431828089d overlay/desktop: fix sub-window first-frame + visibility on Windows
Two issues caused the sub-window to show as "all white initially, white
box on black after resize":

- The runner's CreateNewWindow skipped FlutterWindow::OnCreate's engine
  kickoff (`SetNextFrameCallback` + `ForceRedraw`). The sub-window's
  engine then never spontaneously painted and stayed at its construction
  metrics; a manual resize forced a paint but with the old 220x100
  surface, hence the "white box that doesn't follow the window".
  Replicating the same boot sequence in CreateNewWindow.

- The Scaffold background used `Theme.of(context).colorScheme.background`,
  which resolves to near-white under shadcn's light theme, masking the
  gear card on its near-white surface. Win32 doesn't do real transparency
  without WS_EX_LAYERED anyway, so use an explicit opaque dark colour
  (0xFF111114) — gives the window a clear chrome regardless of the
  user's system theme.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 09:25:48 +02:00
Jonas Bark
b668350226 fix dynamic island 2026-05-11 14:13:19 +02:00
Jonas Bark
aa9283137b fix multi window macOS 2026-05-11 10:02:09 +02:00
Jonas Bark
c39d4191f6 overlay/desktop: switch to multi_window_native
Drops desktop_multi_window 0.3.0 in favour of multi_window_native 1.0.4
on a new branch (feature/trainer-overlay-multi-window-native).

Mechanism is different but the responsibilities map cleanly:
- `MultiWindowNative.createWindow([routeName, argsJson, theme])` spawns
  the sub-window; main() detects it via the first arg.
- Communication is broadcast by method name through
  `notifyAllWindows` + `registerListener`. Conventions:
    main → overlay: trainerOverlay.state
    overlay → main: trainerOverlay.action / ready / positionChanged
  Each side filters by method name; the API has no per-window targeting.
- The overlay window grabs its windowId via `windowManager.getId()` and
  broadcasts `trainerOverlay.ready` so the controller can later close it.
- `notifyUiRendered()` is called after the first frame, per the package's
  black-screen workaround on macOS/Windows.

Native shims:
- macOS MainFlutterWindow.swift: re-register plugins on every new
  sub-engine via `MultiWindowNativePlugin.onEngineCreatedCallback`. Kept
  the `.statusBar` / `.fullScreenAuxiliary` elevation for visibility
  above fullscreened trainer apps; the callback now finds the new
  sub-window's NSWindow by matching the FlutterViewController's engine.
- Windows flutter_window.cpp: reverted the desktop_multi_window callback;
  multi_window_native's Windows wiring requires a more invasive
  flutter_window.h / cpp change (SetOnCloseCallback, GetFlutterViewController,
  callback registration in main.cpp) which is TBD. The overlay is only
  verified on macOS in this branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 09:11:00 +02:00
Jonas Bark
4033ad1dd5 android: silence the trainer-overlay foreground-service notification
Android's SYSTEM_ALERT_WINDOW + specialUse foreground service requires
*some* notification — we can't suppress it entirely. Empty the content
line and set visibility to secret so it doesn't appear on the lock
screen or as a heads-up; it lives unobtrusively in the notification
shade only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 07:56:16 +02:00
Jonas Bark
9c43a07cb0 fix gear change buttons 2026-05-10 11:10:22 +02:00
Jonas Bark
ca65e9631f fix Android 2026-05-10 09:46:12 +02:00
Jonas Bark
971fef3c5e Revert "fix(overlay/android): match working example for sizing, position, and root widget"
This reverts commit 56730fa25e.
2026-05-10 09:36:42 +02:00
Jonas Bark
56730fa25e fix(overlay/android): match working example for sizing, position, and root widget
Two reasons the Android overlay was rendering invisibly:

1. flutter_overlay_window 0.5.0 passes the width/height args through to
   WindowManager.LayoutParams as RAW PIXELS (not dp). Passing width=400
   produced a ~100dp-wide strip on a high-density phone. The default y
   position is -statusBarHeightPx(), which hid most of the surface
   behind the status bar.
   - Use WindowSize.matchParent for width (-1 = MATCH_PARENT).
   - Use a generous pixel height (600).
   - Pass an explicit startPosition so y isn't negative.
   - Close any stale active overlay before re-showing (survives hot restart).

2. ShadcnApp does not produce stable layout constraints in the overlay's
   secondary Flutter engine. Match the package's working example: use
   MaterialApp + Material(color: transparent) at the root and a
   plain-Material overlay card with hardcoded colors. The shared
   TrainerOverlayView is for desktop only; Android needs its own
   minimal Material-friendly variant.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 09:28:32 +02:00
Jonas Bark
307941b4d4 overlay: remove trainerOverlayMode ValueNotifier (now unused)
The global trainerOverlayMode notifier was only used by TrainerOverlayHost
to swap the main window UI. Both are gone; remove the notifier from
trainer_overlay_service.dart and drop the corresponding test assertion.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 16:12:51 +02:00
Jonas Bark
55f225dae4 overlay: rewrite DesktopOverlayController to use desktop_multi_window
Replace the compact-mode-of-main-window logic (which mutated
window_manager properties on the single main window) with a real
second-window approach:

- WindowController.create() spawns the overlay sub-window via
  desktop_multi_window.
- State is pushed from the main isolate at ~10 Hz (debounced) through
  WindowController.invokeMethod('state', json).
- The parent registers a WindowMethodChannel handler for 'hide',
  'toggleMode', and 'positionChanged' callbacks from the overlay.
- Dragging and window-move position persistence are handled in the
  sub-window via window_manager's WindowListener.onWindowMoved.
- No window_manager mutations on the main window at all.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 16:12:33 +02:00
Jonas Bark
ce592adc1d overlay: add sub-window entry point and dispatch from main()
Add lib/services/overlay/desktop_overlay_window.dart with
runDesktopOverlayWindow(): configures the sub-window via window_manager
(220×140, frameless, transparent, always-on-top), registers a
setWindowMethodHandler for 'state'/'close' calls from the parent, and
routes 'hide'/'toggleMode'/'positionChanged' back via WindowMethodChannel.

Update main() to call WindowController.fromCurrentEngine() after
WidgetsFlutterBinding.ensureInitialized(); if the arguments indicate
role=trainer-overlay it dispatches to runDesktopOverlayWindow and
returns early, keeping all heavy init (Settings, IAP, Supabase) out of
the sub-window process.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 16:12:22 +02:00
Jonas Bark
8bdca5f4a6 fix live activity 2026-05-09 16:00:31 +02:00
Jonas Bark
3d1a2ba175 fix(overlay): make Android overlay actually render and gate permission tile
The overlay isolate's overlayMain was annotated @pragma('vm:entry-point')
but the file was not imported anywhere, so Flutter never compiled it into
the binary. Android then logged 'Width is zero' followed by 'Destroying
the overlay window service' because the secondary engine couldn't find
the entry point. Importing it from android_overlay_controller.dart pulls
the file into the build.

Also gate the 'Grant overlay permission' settings tile on the actual
runtime permission state (FlutterOverlayWindow.isPermissionGranted),
hiding it once permission has been granted.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 10:28:17 +02:00
Jonas Bark
255b6a477f fix(overlay): omit null values from iOS Live Activity payload
live_activities routes the map through NSUserDefaults in the App Group,
which crashes with NSInvalidArgumentException on null values. Swift's
Codable decoder maps missing keys to nil for Optional types, so omitting
power/cadence/ergTarget when null produces the same ContentState without
the crash.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 10:23:11 +02:00
Jonas Bark
ca8bb63066 fix(overlay): guard ios push against null _def race
Pass def explicitly to _snapshot(FitnessBikeDefinition) instead of
force-unwrapping _def! inside it. In _push(), capture both _activityId
and _def upfront and bail early if either is null, preventing a crash
when hide() clears them between a Timer callback and _push() executing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 09:45:54 +02:00
Jonas Bark
320cf64934 fix(overlay): restore opaque desktop background after hide
Set background color back to opaque black in _restore() before
reverting other window properties, so the transparent overlay color
does not leak into the restored main-window state on macOS/Windows.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 09:44:00 +02:00
Jonas Bark
fd1161c91e feat(overlay): iOS controller backed by Live Activities (debounced 2 Hz)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 09:24:22 +02:00
Jonas Bark
7db9f12fb6 feat(overlay): Android controller with permission flow and debounced state push
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 09:16:31 +02:00
Jonas Bark
3eb3e39426 feat(overlay): Android overlay isolate entry point 2026-05-09 09:12:43 +02:00
Jonas Bark
4204a1d271 feat(overlay): desktop controller via window_manager (compact mode) 2026-05-08 23:09:09 +02:00
Jonas Bark
73954458bd refactor(overlay): rename OverlayState -> TrainerOverlayState to avoid Flutter collision
Removes the need to `hide OverlayState` on shadcn_flutter imports in
trainer_overlay_view.dart and its widget test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-08 23:06:24 +02:00
Jonas Bark
e96cdb157f feat(overlay): platform router and global overlay-mode notifier 2026-05-08 23:00:45 +02:00
Jonas Bark
173ae7f24e feat(overlay): TrainerOverlayController interface and no-op impl 2026-05-08 22:59:07 +02:00
Jonas Bark
e61f27de41 feat(overlay): OverlayField enum and OverlayState data class 2026-05-08 22:47:54 +02:00