Commit Graph

327 Commits

Author SHA1 Message Date
Jonas Bark
1d1a0dbf72 feat(click v2): keep the right puck awake, and say when it can't
The right puck switches itself off after a minute of not being used.
BikeControl now prevents that on its own, with no button to press. The
sequence lives in prop; this side supplies what only it knows and shows
the rider the one case they can fix.

- the gate reads raw adverts, not the device list: the sibling only has
  to be nearby, and a left puck the rider ignored — every left puck in
  right-side-only mode — still counts. Discovery is also the retrigger,
  since an ignored puck never completes a handshake
- an optional step on the controller card, and a note on the right puck's
  own card, when no left puck is in range. An offer, never a blocker
- drops the D-pad line from "use the right side only"

Fixes a related bug: the controller link counted every undone step,
optional or not, so an optional offer alone turned a working controller
amber and held back "Ready to ride". The other two links already
excluded optional steps.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-20 14:55:15 +02:00
Jonas Bark
9ba09657a1 fix(controller): firmware hints now point at the Zwift Companion app
Riders who can't find their controller are told the firmware may be out of
date, but never where to update it — a support report showed someone had no
idea updates run through the Zwift Companion app.

- name the Companion app in every firmware hint and give each one an action
  that opens it (scan-time Zwift Ride toast, missing-custom-service alert,
  newer-firmware-available alert)
- add a firmware tip with the same link to the onboarding "no controllers
  found" state, where riders actually get stuck
- localize the three hints, which were hardcoded English, across all 6 locales

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-18 20:23:48 +02:00
Jonas Bark
8023060121 fix(click-v2): unlock-with-Zwift folds the split entries back into one controller
Picking unlock-with-Zwift on the right puck's card updated the mode but left
the separate right-side entry connected, with no way back to the joined
controller. chooseUnlockWithZwift has never touched useNewUnlockMethod — the
only thing that could turn the split representation off was the "use new
unlock method" switch, and removing that switch (74bb2737) left the setting a
one-way door: chooseRightSideOnly turns it on, nothing turned it back off.

Make the mode own the representation, mirroring chooseRightSideOnly in the
other direction. Unlock-with-Zwift is the both-pucks mode and the unified
controller is both pucks as one device; the split exists so the RIGHT puck
can work alone, unlock free, which is the other mode. So the choice drops
every split instance, clears the scan cache and rescans: the left puck's
advert rebuilds as the unified controller and the right puck's builds nothing,
which is what removes the separate entry. The flag is set before
restoreLeftSides(), which can restart the scan and would otherwise rebuild the
very entry being folded away.

The unified controller's card carries the unlock-mode row now too. It only
ever rendered its unlock warnings, so landing on it would have been a trip
with no route back to right-side-only.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-13 08:54:33 +02:00
Jonas Bark
74bb2737ba fix: UI feedback round — remembered devices, Click V2 unlock, paywall, Pro dialog
- Remembered controllers offer a single "Forget" instead of two disconnect
  variants: there is no link to drop on a device that isn't here.
- Click V2: drop the unlock-mode dropdown and the new-unlock-method toggle.
  The explainer stays the one place the mode is chosen — it also does the
  follow-on work (un-ignoring the left puck, the right-side-only remap,
  cancelling the reset timer) that the bare dropdown never did. "Set up
  again" now sits on the right puck's card too.
- Paywall: the Base column reads "Basis"/"Base" rather than "VOLL"/"FULL",
  and the one-time Base card moves above the Pro plans so top-to-bottom
  matches the comparison table's left-to-right.
- A remembered controller's own settings page shows its button mapping
  again. The gate counted live controllers only and KeymapExplanation
  looked its filterDevice up in the live list, so the page fell through to
  a warning about connection methods, which had nothing to do with it.
- showGoProDialog takes a feature name for its title, so the keymap sync
  cloud icon says what it does instead of only "Pro Feature".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-13 07:50:34 +02:00
Jonas Bark
6dc4136567 fix(click-v2): enabling the new unlock method lands on the right puck
Reported from a device: switching "use new unlock method" on from the
detail page connected only the LEFT puck — the one that needs unlocking
— which is the setup the switch exists to move the rider off.

Two causes, both needed fixing.

Nothing put the rider into a mode. The toggle only flipped the
representation, so with unlock-with-Zwift off and right-side-only off,
the left puck's gate let it connect while the right puck's gate — which
needs one of those two settings — kept it out. Enabling now routes
through chooseRightSideOnly(), so the toggle and the explainer leave
identical state. A rider who deliberately chose unlock-with-Zwift keeps
both sides; this only redirects the default.

And even with the mode set, the right puck could never appear. In the
legacy representation its advert IS scanned and cached, but
fromScanResult returns null for it — the advert is remembered while
resolving to no device, and the scanner then dedupes against that cache
forever. So the switch also restarts the scan, the same thing
restoreLeftSides already needed.

That meant widening what counts as a left puck. In the legacy
representation the unified ZwiftClickV2 IS the left puck, built from its
advert (the right one builds nothing), so ignoring only
ZwiftClickV2LeftSide missed the very case this bug is about.
_ignoreLeftSides now matches ZwiftClickV2 — which covers both classes
and cannot catch the right side, since that extends ZwiftRide — and
restoreLeftSides recognises both label constants, or a puck ignored as
the unified controller could never be restored.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 18:02:03 +02:00
Jonas Bark
c69c0819ab fix(home): show the unlock deadline, and fix "Unlock again" on the details page
Two things.

The unlock step now says when the unlock runs out rather than just
ticking. That makes it the one done step in the chain carrying detail,
deliberately: an unlock expires, so a bare tick would hide that this
comes back tomorrow.

It also has to distinguish two states the device page already drew
apart. BikeControl cannot read a Click V2's lock state back — after an
unlock it knows when the 24 hours ought to run out, but not whether the
unlock took — so SetupStep.uncertain carries that, and the step reads
"Likely unlocked until Friday, 14:30" instead of claiming more than is
known. The date is preformatted at the page: the chain model stays free
of locales and date formats, which is what keeps it testable without a
loaded locale.

ZwiftClickV2 grows an `unlockedUntil` getter rather than the page
reaching into propPrefs. The +24h arithmetic already existed twice in
that file, and widening its `prop` import is its own hazard — that
package exports a `Set` which shadows dart:core's.

Separately, "Unlock again" on the controller details page threw "No
DrawerOverlay found in the widget tree" and did nothing. The page wraps
itself in a DrawerOverlay, but _buildDeviceCard and _buildActions are
methods on the State, so the context they close over is State.context —
which sits ABOVE the overlay its own build creates. Two callers were
hitting it, "Unlock again" and the device-script drawer. Both now build
from the context under the overlay, the pattern onboarding_page already
documents for the same trap.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 17:46:15 +02:00
Jonas Bark
77596ffbe0 fix(click-v2): ignore the left puck in right-side-only, and name both pucks
Three things the first cut of right-side-only got wrong on a real phone.

The left puck was held back by a setting rather than ignored, so it kept
its entry in the device list and the active scan handed it straight back
— an orphan stuck on "connecting" that never could. Filtering it out of
controllerDevices fixed the onboarding list and missed the home chain,
which also draws from offlineControllers. That is the argument against
inventing a second mechanism: ignoring is the one the scan filter, the
remembered-device loader and the device list all already honour, so
using it takes the puck out of every list at once. The dedicated gate
and the isExcludedBySetup filter are gone with it.

Ignoring has to cover the remembered stand-in too, not just a live
device — the chain lists both side by side, and the card in the report
was a stand-in.

It also has to be undoable, or picking "unlock with Zwift" after
right-side-only silently still yields one controller. Removing the
ignored entry is not enough on its own: the scanner dedupes against its
cached advert, and performScanning() returns immediately while a scan is
already running, so the puck only came back on the next launch. It now
restarts the scan.

Both lists showed "Zwift Click" for both pucks: `name` is the raw BLE
advertised name, identical for the two. They use displayName, which
carries the translated left/right suffix.

Finally, the chain sat 24px in from each screen edge on mobile —
Overview's scroll view pads it by 12 and HomePage added 12 of its own,
before each card's padding on top. Desktop keeps its inset; there the
chain sits in a centred max-width box with no padding of its own.

Known sharp edge, left deliberately: un-ignoring the left puck by hand
while still in right-side-only mode brings both up live, and the right
side's handshake cancels the left's restart timer.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 16:23:38 +02:00
Jonas Bark
aa0720b984 fix(click-v2): the no-unlock option is the right puck, not the left
The first-run explainer offered "use the left side only" as the way to
avoid Zwift. That is the one puck Zwift actually locks. Picking it left
the rider on the 59-second restart loop, and — because
ZwiftClickV2RightSide.shouldAutoConnect required unlock-with-Zwift — it
also withheld the puck that needs nothing at all. Worse, with Zwift's
built-in keymap binding the right paddle to shiftUp and the left paddle
to shiftDown, the left side alone could only ever shift down. The
genuinely clean setup was reachable only by first choosing the mode it
was meant to replace, then tapping "Use the right side only" on the
right card.

So the option becomes right-side-only: no unlock ever, no restarts, and
the +/B remap the right card already applied so one puck covers both
shift directions. The cons now name the real price — no D-pad, so no
steering and no action bar.

Click V2 state is three modes now, not a boolean, and both connect gates
say so out loud. ClickLogic drives the left side's restart loop from a
single static timer that the right side's handshake cancels, so those
two can never be live together; that invariant used to be implied by one
gate and is now stated in both. Left-restart mode survives as the left
card's existing Select for riders who want the D-pad, just not as a
first-run choice.

The right card's shortcut delegates to the same policy rather than
keeping its own path, so both leave identical state: the left side held
back by the setting instead of pushed onto the ignored-devices list,
which is what lets "Set up again" undo it. Its confirmation copy moves
accordingly, and it stops offering itself once the left side is merely
listed rather than connected.

The remap sits in its own recordError guard. It needs a trainer app to
have been picked, and a mode the rider explicitly chose must not be left
half-written because an optional convenience could not run.

This also turns emulation_zwift_profiles_test's right-side case green:
it had been red since the gate landed, because e74c5920 fixed only the
isPending half of what was holding that side back.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 15:40:00 +02:00
Jonas Bark
56a8e87f7d i18n(home): translate the setup chain, align its checklist, stop billing
undelivered shifts

Three things.

The chain's 68 strings existed only in English, so five locales fell back
to it on the app's main screen. Now translated, in each file's own register
— informal second person throughout, matching the copy already around
them. Polish needed a `few` plural category for the step and day counters:
it uses a distinct form for 2-4, so `other` would have rendered "Zostały 2
kroków" instead of "kroki". Two keys written speculatively and never wired
up are dropped rather than sent to five translators.

The checklist's summary row sat inside a Button whose own padding inset it
past the steps below, and the leading glyphs differed in both width (15px
icon, 17px tick) and gap, so matching the outer inset alone would not have
lined them up. One _rowInset / _leadingSize / _leadingGap now governs both,
with the glyphs centred in a box of equal width. Two tests pin the tick and
the label columns, because this is exactly what drifts back unnoticed.

Finally, shifting with a trainer connected but no app holding the bridge
was charged to the daily command budget. Those shifts reach nothing. The
existing exemption only covered the case where the 20-minute
virtual-shifting budget was already ticking — that avoids double-billing —
so it grows a second reason: a command that was never delivered anywhere is
not a command the rider spent.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 14:39:07 +02:00
jonas.bark@gmx.de
599e2e644d fix: let trainer apps on the network find BikeControl again
Retires the Windows IPv6 workaround instructions along with it — they no
longer apply.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 14:33:34 +02:00
Jonas Bark
d98483fa3b fix(click-v2): explainer auto-opens once per pair, right side stays off in left-only mode
The wizard's Click V2 auto-prompt marked 'the pair' by uniqueId before the
second side was even discovered, so two concurrent connectionStream runs
each opened the explainer — replaced with a single flag set synchronously
before the await (the row's Setup-needed button remains the way back in).

ZwiftClickV2RightSide.shouldAutoConnect now also requires unlock-with-
Zwift mode: after 'left side only' the right controller is deliberately
unused, and connecting it anyway burned battery and disturbed ClickLogic's
restart cycle. Covers both the auto-connect queue and ClickV2Onboarding's
_connectPending (connect() is a no-op while the gate is false).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-10 11:24:53 +02:00
Jonas Bark
653dfbf461 feat(click-v2): hold discovered controllers for unlock-mode onboarding 2026-08-03 09:21:02 +02:00
Jonas Bark
0f81549740 refactor: share BLE advertising "already started" recovery via mixin
Extracts the recovery added for OpenBikeControl (abe636d4) into
PeripheralAdvertisingRecovery and applies it to ZwiftEmulator too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 09:08:18 +02:00
Jonas Bark
95b7a7ff06 fix(zwift): put Rouvy advertisement service UUIDs in the scan response
The Rouvy Zwift-BLE advertisement (Zwift fc82 + OBC 128-bit UUID + name
"BikeControl" = ~38 bytes) overflows Android's 31-byte primary packet, so
startAdvertising fails with "Data too large" — Rouvy users on 6.1 can't
connect (the bluetooth_low_energy -> universal_ble migration stopped
splitting service UUIDs into the scan response).

Bump universal_ble to the fork commit that adds
PeripheralAndroidOptions.addServicesInScanResponse, expose it through
PeripheralServer.startAdvertising, and enable it for the Rouvy branch of
the Zwift emulator. Primary packet becomes flags+name (~16B), scan
response carries the UUIDs (~22B); active scanners still see everything.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 08:27:39 +02:00
Jonas Bark
282841bd37 feat(zwift): forward frontShift as both-shifters combo frame
Intercept InGameAction.frontShift in ZwiftEmulator.sendAction and emit
the SHFT_UP_R|SHFT_UP_L combined buttonMap frame followed by the release
frame — the standard Zwift Ride gesture that triggers a front-chainring
shift in Zwift (SRAM) and a generic controller gesture in other apps.
No app-capability flag, no fallback, no toggle state.

UNVERIFIED: bitmask vs live Zwift SRAM — confirm on-device.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 16:24:41 +02:00
Jonas Bark
786621a11b Localize TrainerConnection titles (re-evaluate per locale)
The connection titles ("Connect using Bluetooth", "Connect directly over
Network", "Connect using MyWhoosh Link", ...) were captured once at object
construction in English, so they didn't follow the active locale. Back the
title with a builder (String Function()) and expose it via a getter so it
re-localizes — fixing the English titles in the localized store screenshots.
Updated all 10 subclasses and the fake connection in the bridge-transport test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 11:47:43 +02:00
Jonas Bark
b5da4ac595 fix: persist the right-side-only keymap remap across restarts
The "use the right side only" button remapped the active keymap (+ shifts up,
B shifts down) in memory, but the change was lost on the next launch when the
active profile was a built-in app: those keymaps are code-defined templates
rebuilt on startup, and Settings.setKeyMap only persists key pairs for custom
profiles.

Mirror the button editor: if the active profile isn't already a custom one,
fork it into a "<App> (Copy)" custom profile (via KeymapManager.duplicateSync)
before applying the remap, then persist. The remap now runs before the left
side is disconnected so the forked copy keeps every connected controller's
existing mappings. Adds a regression test covering both the built-in-fork and
already-custom paths, including a reload from storage.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-17 20:51:59 +02:00
Jonas Bark
f4023892cf fix: show "Use new unlock method" toggle only on the controller detail page
Move the new-unlock-method toggle from showAdditionalInformation (rendered on
both the compact overview card and the detail page) into buildPreferences,
which the controller detail page renders under "Preferences". The toggle now
appears only when the controller entry is opened, not on the overview card.
The Click V2 left side inherits this from ZwiftClickV2; the right side gets its
own override. Unlock-status warnings and the "use right side only" prompt are
unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-17 20:40:36 +02:00
Jonas Bark
e37a9de61d increase Zwift Click recommended firmware to 1.2.0, cleanup 2026-06-17 20:38:59 +02:00
Jonas Bark
6778c1e45b feat: optimize Zwift Click V2 left/right experience
- Make the split left/right controllers available to everyone: replace the
  isPro gate in the device factory with a "Use new unlock method" setting
  (default on); off falls back to the legacy unified ZwiftClickV2.
- Add the "Use new unlock method" toggle to all three Click V2 settings panels;
  flipping it reconnects the Click as the new/legacy representation.
- Fix the "Unlock again" button placement: on narrow side-by-side cards the
  action now drops below the status text instead of squeezing it.
- Add "Use the right side only" to the right side when a left side is connected:
  ignores the left side (reversible via Ignored Devices) and remaps the active
  keymap so + shifts up and B shifts down.
- Localize new strings (de/es/fr/it/pl; en already present) and add
  factory/settings unit tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-17 19:50:08 +02:00
Jonas Bark
6e0861e556 Name the trainer app and show its transport in connection alerts
The "connected"/"disconnected" activity alerts fired when a trainer app
attaches to one of our emulators now name the app ("Connected to Zwift",
"Disconnected from Zwift") and tag the alert with the transport, so the
activity log shows a WiFi or Bluetooth icon depending on how the app is
connected instead of always Bluetooth.

- AlertNotification gains a connectionType field + a connection() factory
  that builds the localized, app-named message and tags the transport.
- All 6 emulator call sites (Zwift BLE, FTMS/Rouvy mDNS) route through it,
  passing their own type and core.settings.getTrainerApp()?.name.
- ConnectionMethodType.activityIcon maps network -> wifi, else -> bluetooth;
  overview threads connectionType through and uses it for the leading icon.
- Reuse existing connectedTo string; add disconnectedFrom (en/de/es/fr/it/pl).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 21:22:59 +02:00
Jonas Bark
c41683421e Merge remote-tracking branch 'origin/6.0.1' into custom-mdns-responder
# Conflicts:
#	.gitignore
#	lib/bluetooth/devices/openbikecontrol/obc_mdns_emulator.dart
#	prop
2026-06-12 12:03:37 +02:00
Jonas Bark
e736425331 Keep Zwift/Rouvy controller connection alive when idle (#367)
Zwift and Rouvy drop a wired LAN controller after ~30s without traffic. The Ftms/Rouvy mDNS emulators only emit on a button press, so an idle rider (pedalling, not shifting) goes silent and gets disconnected.

Add a ControllerKeepAlive timer that re-emits the neutral "released" controller frame every 5s while a client is connected, started/stopped from each emulator's isConnected listener. It's the same frame a key-up sends, so it resets the peer's inactivity watchdog without registering a phantom press.

Also drops an earlier keepalive attempt from OpenBikeControlMdnsEmulator — that path speaks the OpenBikeControl protocol, which Zwift doesn't use.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-12 11:03:42 +02:00
Jonas Bark
df18e4ff2f advertisement fix 2026-06-10 11:09:35 +02:00
Jonas Bark
a60a1384e3 Merge origin/universal-ble-2-peripheral: universal_ble 2.0.0 peripheral mode
Brings the BLE peripheral-mode migration to universal_ble 2.0.0 into the
WiFi DirCon trainer-discovery branch and bumps universal_ble to the latest
fork commit (ref: changes, 2.0.0).

Conflict resolutions:
- prop submodule: merged the universal_ble 2.0 transporter migration with
  the WiFi DirCon TrainerTransport refactor; kept the '0x' short-UUID
  normalisation on startAdvertising. Updated BleCharacteristic call sites
  to the new 3-arg (uuid, properties, descriptors) constructor.
- obc_ble_emulator.dart: took the PeripheralServer / universal_ble 2.0
  write-handler migration; kept the richer Error(button:) context on
  sendAction (using _currentDeviceId, the migrated connection tracker).
- unlock.dart: kept the main.dart import.
- pubspec.yaml: kept version 6.0.0+135; took ref: changes for universal_ble.

Pre-existing prop test failures (composite/dircon/fitness serviceUUIDs) are
unchanged by this merge — they fail identically on the pre-merge branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 09:19:58 +02:00
Jonas Bark
4e2a922760 feat: use shared BikeControl mDNS marker constants; register obc advertisement
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 07:10:40 +02:00
Jonas Bark
365893256d UX 2026-06-07 08:32:14 +02:00
Jonas Bark
6ca4852491 fix mobile UI 2026-06-06 21:33:01 +02:00
Jonas Bark
8310e881dc Fix UX, translation 2026-06-06 20:21:13 +02:00
Jonas Bark
27919882b4 Fix UX, translation 2026-06-06 20:20:29 +02:00
Jonas Bark
8f221245cc new unlock method 2026-06-06 19:54:00 +02:00
Jonas Bark
f35ff80b1e fix #3 2026-06-03 16:10:55 +02:00
Jonas Bark
e9772a34a8 add missing Zwift Play button placements 2026-06-03 11:39:13 +02:00
Jonas Bark
ce19e629c2 add missing Zwift Play button placements 2026-06-03 11:35:44 +02:00
Jonas Bark
a68b68a1b4 fix button mapping popup 2026-06-01 11:53:55 +02:00
Jonas Bark
0bfd483ba1 Merge branch '5.5.0' into draft
# Conflicts:
#	prop
2026-05-31 10:26:25 +02:00
Jonas Bark
461fe8a420 Zwift Play Firmware 2.0.1 support 2026-05-25 21:14:49 +02:00
Jonas Bark
218a7e2e98 zwift adjustments 2026-05-21 22:01:14 +02:00
Jonas Bark
51f2455166 rouvy mode 2026-05-21 20:34:51 +02:00
Jonas Bark
c360ef17a7 document findings 2026-05-21 12:42:02 +02:00
Jonas Bark
cfadaff94e adjustments 2026-05-21 12:27:37 +02:00
Jonas Bark
0a76de870a refactor: ProxyDevice owns trainer identity and def construction
handleServices builds both ProxyBikeDefinition and
FitnessBikeDefinition up front and attaches to the right emulator
based on retrofit mode. ProxyDevice provides advertisementName +
mdnsTxt to ftmsEmulator/_proxyEmulator via the new startServer
parameters. Drops DirconEmulator state mirroring that's no longer
needed. ZwiftClickV2 no longer calls startServer (click-alone
path removed per prop strip). UI consumers route through
ProxyDevice.advertisementName and device.retrofitMode.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 00:08:33 +02:00
Jonas Bark
cb2fbe7db0 refactor: move unlock state from emulator to ZwiftClickV2
isUnlocked / alreadyUnlocked / waiting notifiers + the vendor message
capture move to ZwiftClickV2. ftmsEmulator.setScanResult and
handleServices are no longer called from the click flow. The unlock
page binds to widget.device's notifiers. The prefs-based unlock check
is renamed isPersistedUnlocked to avoid shadowing the new live notifier.
2026-05-20 23:16:14 +02:00
Jonas Bark
9fb8d63f9a refactor: collapse to a single shared DirconEmulator for VS mode
ftmsEmulator is now the single emulator for Virtual Shifting traffic
across all trainers and the Click V2. ProxyDevice keeps a per-instance
emulator only for proxy mode (each proxy trainer advertises its own
mDNS identity). ZwiftClickV2 attaches its def to ftmsEmulator directly.

ProxyDevice exposes its own state ValueListenables (isStartedListenable,
isConnectedListenable, retrofitMode, localAddress) that mirror the active
emulator, so UI bindings survive mode swaps. setRetrofitMode and
switchRetrofitMode live on ProxyDevice and migrate the FBD between
proxy/shared emulators.

Removes companionProvider, refreshCompanions, and the click-def
internal seeding in DirconEmulator.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:05:40 +02:00
Jonas Bark
822c929b09 refactor: drop EmulatorRegistry, use DirconEmulator.companionProvider
ZwiftClickV2 no longer tracks which emulator hosts its definition or
listens for trainer arrival/departure. Instead:

- ProxyDevice installs an emulator.companionProvider that returns click
  defs for any connected ZwiftClickV2 at start time.
- ZwiftClickV2.handleServices builds the def, asks running trainer
  emulators to refreshCompanions, or starts the standalone if no
  trainer is running.
- ProxyDevice.disconnect migrates the click def back to the standalone
  so the Click stays usable after a trainer goes away.

Removes EmulatorRegistry singleton, the rebind handler, and the
sharedTrainerEmulator listener.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 22:36:54 +02:00
Jonas Bark
cd6626c507 feat: always advertise Click service while a Click V2 is connected
ZwiftClickDefinition is now attached to the resolved DirconEmulator at
Click-connect time, regardless of whether the unlock page is open:
- No trainer → ZwiftClickV2.handleServices starts the standalone so
  Zwift / Rouvy see BikeControl-as-Click as soon as the user plugs the
  Click in.
- Trainer present → click def attaches to the trainer's emulator; the
  trainer's existing peripheral advertises both services via the
  composite, so Zwift auto-subscribes to the Click service when it
  pairs with the trainer.

unlock.dart no longer drives the standalone's lifecycle; it just
listens to the shared unlock notifiers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 22:08:57 +02:00
Jonas Bark
feba139ada fix: harden unlock page and route attach/detach errors through recordError
- unlock.dart now seeds ftmsEmulator.scanResult before calling
  startServer, so the unlock page works when the Click is bound to the
  trainer's emulator (and never told the standalone about itself).
  Also guards the startServer call behind isStarted.value to avoid
  double-starting.
- ZwiftClickV2 attach/detach call sites now wrap their futures in
  catchError(recordError, context: '...') per the project's
  feedback_record_error rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 18:27:28 +02:00
Jonas Bark
ea8fbc51ef fix(zwift_clickv2): don't overwrite trainer emulator's scanResult/services
ZwiftClickV2.handleServices / _onSharedTrainerChanged were calling
setScanResult and handleServices on whichever DirconEmulator the
registry resolved to — corrupting the trainer's mDNS advertisement
(which reads scanResult.deviceId + scanResult.services for its TXT
record) and breaking subsequent _createDefinitionAndTransporter
rebuilds whenever a trainer was the resolve target.

The Click's hardware identity already lives inside the
ZwiftClickDefinition (services / device constructor args). Only the
standalone ftmsEmulator should learn the Click as its primary device.
2026-05-20 18:15:43 +02:00
Jonas Bark
1eb96c7d39 feat: route ZwiftClickV2 through EmulatorRegistry + attachDefinition
When a smart trainer is connected, the Click V2's ZwiftClickDefinition
attaches to the trainer's emulator so Zwift/Rouvy pair once and see
both services. When no trainer is connected, falls back to the
standalone ftmsEmulator (existing unlock path). Trainer arrival /
departure while the Click is connected rebinds the definition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 18:11:05 +02:00
Jonas Bark
6fd18d9c03 feat: add EmulatorRegistry for companion-device emulator resolution
ZwiftClickV2 uses this to find the trainer's DirconEmulator at connect
time and attach its ZwiftClickDefinition there, falling back to the
standalone emulator only when no trainer is connected.
2026-05-20 18:04:22 +02:00