Commit Graph

22 Commits

Author SHA1 Message Date
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
69088cbb7f fix(screen-recording): guard re-entrant toggle; recover native start failures
- Ignore toggles during the transient starting/stopping states (in-flight
  guard) so a double-press can't double-start or stop-during-start.
- macOS: reset the recorder handle when start() throws, so one failure no
  longer permanently blocks recording (only stop() nilled it before).
- iOS: remove the broadcast picker view after triggering so a 1x1 view doesn't
  accumulate on the key window on every start.
- Report failures via recordError (was debugPrintStack, which vanishes in
  release builds). Adds an in-flight-toggle guard test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 19:58:26 +02:00
Jonas Bark
d649e396b9 fix(screen_recorder): correct upside-down Windows recording
WGC/D3D surfaces are top-down, but the MF SinkWriter's RGB32->NV12
conversion treats uncompressed RGB as bottom-up, so feeding our top-down
buffer through produced a vertically-flipped (upside-down) recording.
Cancel the fixed flip by writing each source row into the mirrored
destination row, handing MF a bottom-up buffer. Same number of memcpys,
no extra cost.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 11:55:49 +02:00
Jonas Bark
489cc93175 fix(screen_recorder): qualify IDirect3DDxgiInterfaceAccess to fix Windows build
The interop interface lives in the ABI namespace
::Windows::Graphics::DirectX::Direct3D11, not the winrt projection
namespace pulled in via `using namespace`. The bare name was undeclared
(C2065), cascading into C2672 and C3536. Fully qualify it (with leading
:: so `using namespace winrt;` doesn't misroute it).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 11:46:31 +02:00
Jonas Bark
7b89e94b20 cleanup 2026-06-24 20:11:48 +02:00
Jonas Bark
6a557b3eaf fix(6.2): iOS broadcast stop via App Group stop-flag poll + heartbeat (Darwin as backup) 2026-06-24 19:35:24 +02:00
Jonas Bark
392e311fa2 fix(6.2): iOS broadcast stop — reuse existing App Group + register stop observer before container guard + diagnostics 2026-06-24 19:06:37 +02:00
Jonas Bark
bbe00f7193 docs(6.2): native backend setup + status (macОS/iOS/Windows manual steps) 2026-06-24 17:55:36 +02:00
Jonas Bark
081f4a113d feat(6.2): iOS screen recording backend (ReplayKit broadcast extension) [extension target needs Xcode wiring]
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 17:52:22 +02:00
Jonas Bark
a4ee87e85f feat(6.2): Windows screen recording backend (WGC + Media Foundation) [UNVERIFIED — needs Windows build]
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 17:42:15 +02:00
Jonas Bark
ccc577f7c2 fix(6.2): macOS capture at native (Retina) pixel resolution via CGDisplayMode 2026-06-24 17:35:38 +02:00
Jonas Bark
d417eb1796 fix(6.2): macOS capture robustness (native-res, finalize check, main-thread result, double-start guard, stream errors)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 17:33:11 +02:00
Jonas Bark
87642a9926 feat(6.2): macOS screen recording backend (ScreenCaptureKit)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 17:28:09 +02:00
Jonas Bark
c597d5ebc1 fix(6.2): screen_recorder plugin declares no native platforms yet (unblock macOS/Windows builds) + comment/semantics tidy
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 17:05:18 +02:00
Jonas Bark
0a2c3916ef chore(6.2): scaffold screen recording deps and in-repo plugin 2026-06-24 16:16:02 +02:00
Jonas Bark
46e5f11c06 build fix IOS 2026-05-13 08:23:19 +02:00
Jonas Bark
16c6fb59ac overlay/macos: register main messenger deterministically + safe close
Root cause for "buttons don't work / window won't close, but ONLY for
the auto-opened overlay" was timing inside the vendored plugin's
register(with:):

  if let mainFlutterWindow = NSApp.mainWindow, ... {
      let messenger = controller.engine.binaryMessenger
      messengers.append(messenger)
  }

For the MAIN engine, `register(with:)` runs from
`MainFlutterWindow.awakeFromNib` — BEFORE the window is shown and
promoted to NSApp.mainWindow. The guard fails, main's messenger is
never appended to the static broadcast list, and any sub-window
broadcasting back through `notifyAllWindows` only echoes to itself.

The bug stayed hidden when the overlay was opened manually from the
settings page (the user did this minutes after launch, so by the time
the SUB engine register fired it could read NSApp.mainWindow and
add main's messenger as a side effect). It surfaced the moment we
added auto-show — BLE reconnects fast on a paired trainer, so the
sub-engine register fires while NSApp.mainWindow is still being set up.

Fix the register to append `registrar.messenger` directly (the
registrar already gives you exactly the right messenger for the
engine being registered), guarded by a contains-check to stay
idempotent. The NSApp.mainWindow path now only wires the window
delegate when it does happen to be set.

Also: `registerMessenger` no longer short-circuits when the
messenger is already in the list — it still calls
`setupChannelHandler` so the per-controller closure that handles
`notifyUiReady` -> `makeKeyAndOrderFront(nil)` is wired for the
sub-window. Skipping it would leave the auto-opened sub-window
invisible because no one would bring it forward.

Plus the closeWindow handler in the same file: I had it call
`self.closeWindow(window)` for each secondary, but
`window.close()` synchronously fires the `windowWillClose`
delegate, which calls `self.closeWindow(window)` again — the inner
call removes the entry and the outer call's
`secondaryWindowControllers.remove(at: index)` crashes on a stale
index. Now it just calls `window.close()` and lets the delegate
path do the one-pass cleanup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:57:46 +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
edc9b8a1b0 overlay/macos: drop title bar from overlay NSPanel entirely
Replace [.titled, .closable, .resizable, .nonactivatingPanel,
.utilityWindow] with [.borderless, .resizable, .nonactivatingPanel].
The Flutter content fills the panel and handles dragging via
window_manager.startDragging(); a system title bar adds nothing.

Also enables isMovableByWindowBackground as a fallback drag affordance
and removes the now-redundant standardWindowButton hiding.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:27:06 +02:00
Jonas Bark
af9e54f443 overlay/macos: hide standard window buttons on overlay NSPanel
The trainer overlay is dismissed by toggling the setting in the
main app, not by the panel's own close button. Hide the close,
miniaturize, and zoom buttons via `standardWindowButton(...)`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:25:22 +02:00
Jonas Bark
7cfd3b98c0 overlay/macos: rebase vendored multi_window_native on GitHub master (1.0.5)
The previous commit vendored the pub.dev 1.0.4 release. The
GitHub repo (https://github.com/Swatimishra8/multi_window_native)
is ahead of pub.dev at 1.0.5 and contains improvements that
matter for the trainer-overlay use case:

- `windowDidBecomeKey` delegate to resume Flutter's render
  pipeline on focus — fixes sub-windows freezing after the
  main app regains focus.
- `applicationShouldHandleReopen` for dock-icon restore.
- Delayed (0.1s) cleanup of secondary windows in `closeWindow`
  so Flutter's onWindowClose callbacks finish executing.
- `generateUniqueTitle`/`registerWindowTitle`/`unregisterWindowTitle`
  bridge methods.
- Native Windows implementation in the package itself
  (we still use our own runner/main.cpp wiring; the package's
  Windows code is unused but harmless).

Re-applied the NSPanel substitution in `createNewWindow`:
.nonactivatingPanel + .utilityWindow style, level .screenSaver,
collectionBehavior including .fullScreenAuxiliary, initial size
220x140 / minSize 160x80 — so the sub-window sits above
fullscreened trainer apps from the moment it's shown.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:21:47 +02:00
Jonas Bark
29a267eba4 overlay/macos: vendor multi_window_native and make sub-windows NSPanels
Forked the upstream package
(https://github.com/Swatimishra8/multi_window_native) into
packages/multi_window_native and pinned pubspec to the path dep.

Key macOS change in the vendored plugin's createNewWindow:
- NSPanel instead of NSWindow with styleMask = [.titled, .closable,
  .resizable, .nonactivatingPanel, .utilityWindow].
- isFloatingPanel = true, becomesKeyOnlyIfNeeded = true,
  hidesOnDeactivate = false.
- level = .screenSaver (highest standard user-space level).
- collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary,
  .stationary, .ignoresCycle].
- Initial size dropped from 1440x900 / minSize 800x900 to 220x140 /
  minSize 160x80 (closer to what the trainer overlay needs).

With those properties set at construction time, the sub-window sits
above fullscreened trainer apps from the moment it's shown — no more
retry loop chasing the window after the fact.

MainFlutterWindow.swift's onEngineCreatedCallback no longer needs the
elevation retry; it just calls RegisterGeneratedPlugins on the new
engine and leaves the window-level work to the plugin.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:18:58 +02:00