Commit Graph

20 Commits

Author SHA1 Message Date
Jonas Bark
20788e46b6 fix(requirements): stop the permission sheet opening for a granted permission
Toggling the "Direct connection" card could wedge: the sheet opened for a
permission that was already granted, and then sat there, because PermissionList
only re-probes on app resume.

ConnectionMethod probed one requirement list, awaited, then re-read
`widget.requirements` on the far side of the gap:

    Future.wait(widget.requirements.map((e) => e.getStatus())).then((_) async {
      final notDone = widget.requirements.filter((e) => !e.status).toList();

The tiles build that list inside `build()`, so any rebuild in that window hands
back fresh objects whose mutable `status` is still false — and these tiles
rebuild on every isConnected/isStarted tick, plus onChange's own setState. The
probe result was read off objects that were never probed.

Capture the list once per operation instead. This was pre-existing and not
specific to Local Network: di2_ble_tile and openbikecontrol_ble_tile pass
getRemoteControlRequirements() the same way, so they had the same latent race.

Also hoist the requirement lists out of build() into State fields across the
five tiles, so a probed `status` is not discarded every frame.

Separately: LocalNetworkRequirement was only wired into the network tiles, so
onboarding, app start and scanning never checked it at all — every one of those
reads getScanRequirements(). Add it there for iOS and macOS. The list is
filtered to unsatisfied requirements, so it surfaces only on an actual denial.

Note for macOS: keyboard-control-only users will now see a Local Network prompt
they do not need. Accepted deliberately in favour of one list over a
platform-split.

The regression test drives the real race — gate the probe, force a rebuild
mid-flight, release — and fails with "Found 1 widget with type PermissionList"
without the capture fix.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 08:55:04 +02:00
Jonas Bark
905c2641cd feat(ios/macos): detect the Local Network permission instead of failing silently
Denial of Apple's Local Network privacy permission is the most common cause of
"BikeControl can't see my trainer app" on iOS and macOS, and it fails
completely silently: Bonjour browses return nothing forever, advertisements
never leave the device, nothing throws. An app watching only for errors cannot
tell "permission is off" from "there is nothing out there".

Apple ships no authorization-status API for it (not iOS 14...26, not macOS
15...26), so the new local_network_permission plugin measures it: an NWListener
and an NWBrowser on _bikecontrol-preflight._tcp, then

  browser discovers the listener        -> granted
  kDNSServiceErr_PolicyDenied (-65570)  -> denied
  neither, before the deadline          -> unknown

unknown is a real outcome, not an error — a device with no usable network never
completes the round trip even when the permission is fine — so everything fails
open on it and only a positive denial blocks the user.

The probe *is* the request: the system prompt fires on the first Bonjour
operation, so there is no separate request step, and after the user answers,
System Settings is the only way back.

- LocalNetworkAccess caches the result (probes cost a real round trip while
  getStatus() runs on every tile mount, tap and resume) and collapses
  concurrent probes into one, since two listeners on the same service type
  would resolve each other.
- LocalNetworkRequirement gates the three LAN tiles: MyWhoosh Link, Zwift mDNS
  and OpenBikeControl mDNS. Suppressed in screenshot/demo mode like the rest.
- Diagnostics drop the old guess (inferred from whether a discovery scan
  returned anything, which could not tell denied from an empty LAN) for the
  measured local-network=granted|denied|unknown.
- _bikecontrol-preflight._tcp added to NSBonjourServices on both platforms;
  without it the browse fails for a reason unrelated to the permission.

The Xcode project deployment-target bumps (ios 13.0->15.0, macos 10.15->12.0)
are Flutter's own migration aligning project defaults with the Podfiles; they
happen on any first build.

Verified with real builds on both platforms, not just analysis: flutter build
macos --debug and flutter build ios --no-codesign both succeed, the framework
is linked in, and the preflight service type is present in both built
Info.plists. 35 tests cover the mapping, cache, concurrency and fail-open
behaviour.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 07:58:18 +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
642fc754a1 UI adjustments, BLE advertisement fix 2026-04-26 09:14:00 +02:00
Jonas Bark
9c17ea0fc0 wording adjustments 2026-04-07 08:26:51 +02:00
Jonas Bark
00d546e75b connection method adjustments 2026-03-25 13:49:49 +01:00
Jonas Bark
5ed2bce59b revise connection methods 2026-03-25 09:27:37 +01:00
Jonas Bark
922c785df1 new ui #4 2026-03-10 19:04:51 +01:00
Jonas Bark
a215a35e0c mark some connection methods as recommended 2026-03-04 14:22:38 +01:00
Jonas Bark
8997b54a9a group buttons by device, add new unlock mechanism 2026-01-23 15:27:32 +01:00
Jonas Bark
1a56ea1047 list supported actions of connection method 2026-01-11 13:00:43 +01:00
Jonas Bark
3b76ad22ec error reporting when starting connection method 2025-12-15 13:13:57 +01:00
Jonas Bark
5a67f2ee76 remove remains of swift_control 2025-12-14 16:22:07 +01:00
Jonas Bark
3426b8a669 add more instructions, clarify mail support 2025-12-10 21:17:49 +01:00
Jonas Bark
727727f8fb ui, fixes 2025-12-04 19:32:02 +00:00
Jonas Bark
541e6f8a42 connection method badges 2025-12-04 14:00:39 +00:00
Jonas Bark
3d1380f72a ui adjustments 2025-12-01 22:58:29 +00:00
Jonas Bark
a9149a7499 translations 2025-12-01 15:46:02 +00:00
Jonas Bark
400379ff93 zwift keep alive 2025-12-01 15:34:50 +00:00