Without this, in-the-wild VS reports can't be correlated with whether
the new opt-in spike filter was active. Mirrors the existing
gradeSmoothing → grade_smoothing plumbing.
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>
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>
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>
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>
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>
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>
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>
`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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Trial users haven't yet decided whether the app is worth paying for, so
prompting them to rate it produces noisy reviews. Hide the banner while
the trial is active; it returns once the user buys or the trial ends.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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>
The power / cadence / speed / hr fields aren't useful for diagnosing
a stuck Bridge or proxy issue — they're just current-rider state. The
BLE service & characteristic UUIDs are the actually-diagnostic bits,
and TelemetrySnapshot already builds that block as the chat freetext.
Promotes _buildServicesFreetext in telemetry_snapshot.dart to a
public buildProxyServicesFreetext, then has _describeProxyDevice in
menu.dart drop the live-metric fields and append the services block
indented under each proxy entry. Same exact text the support chat
freetext already includes, so report and freetext stay in lockstep.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a sticky 'support_chat_active' bool to Settings, flipped to true
the first time SupportChatService.openChat succeeds. HelpButton becomes
a StatefulWidget; if the flag is set in initState it kicks off a
background fetchChat() and counts admin-side messages whose createdAt
is later than the chat's lastSeenAt. When at least one is found, a
small destructive-coloured dot appears both on the button's leading
icon (top-right corner) and as the trailing slot of the inline 'Chat
with Support' menu entry.
Opening the chat clears the dot locally and re-runs the unread check
on return so the indicator stays in sync with what the user has now
seen. All checks are best-effort: missing auth, network errors, and
edge-function failures are swallowed and the dot just stays off.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The Supabase Dart SDK doesn't expose these getters on SupabaseClient,
so the support-chat attachment upload failed to compile. Hardcode the
URL (matching Supabase.initialize() in settings.dart and the existing
iap_status_widget.dart usage) and pull the anon key from the same
SUPABASE_ANON_KEY define for the raw multipart edge-function upload.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a Supabase-backed support chat that replaces the existing trainer
feedback page and the mail support entry in the help dropdown. The chat
captures the same telemetry snapshot (extracted into a shared
TelemetrySnapshot module) and supports threaded replies and attachments.
- New SupportChatService wrapping the four edge functions plus a signed
URL helper for support-attachments storage.
- New SupportChatPage / SupportThreadPage with composer, attachment chips,
optimistic send, sign-in gate, and pull-to-refresh.
- Help dropdown's Mail entry replaced with "Chat with Support" that
pre-fills debugText() as freetext on the first message.
- Trainer device details "Provide Feedback" button now opens the chat
with TelemetrySnapshot.fromDevice telemetry.
- Login screen gets a subordinate "Don't want to sign in? Write a mail
instead" ghost button (mobile only) that opens the existing mailto.
- Telemetry helpers moved out of the deleted trainer feedback files into
lib/services/telemetry_snapshot.dart; test rewritten for the new class.
https://claude.ai/code/session_0155Bb4kCYaxKh7zQfoQHZET
Persists the WorkoutSummary alongside each saved workout as a sidecar
JSON file (workout-…fit.json) so the past-workouts list can render
duration, distance, avg power, and avg HR per row without parsing the
FIT. Reading is best-effort — older workouts without a sidecar fall
back to the previous filename-only layout.
Splits WorkoutsListPage into a Scaffold-wrapped page (kept for
backwards compatibility / desktop nav) and a chrome-free WorkoutsList
widget that the MiniWorkoutCard now mounts inside openSheet at the
bottom edge. WorkoutsList renders a small header and the "open folder"
shortcut when its showHeader flag is set so it stays self-contained
inside the sheet.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds PastWorkout model, WorkoutRepository (save/list/delete) with UTC-stamped filenames, and wires it into Core.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements WorkoutRecorder with start/pause/resume/stop transitions, 1 Hz
sampling loop via configurable tick timer, active duration tracking that
excludes pause time, and WorkoutResult with summary. Wires recorder into Core.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>