Commit Graph

39 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
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
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
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
Jonas Bark
60fd375a2d macos: bump overlay sub-window level from .statusBar to .screenSaver
`.statusBar` (level 25) plus `.fullScreenAuxiliary` wasn't enough to
keep the trainer overlay above fullscreened trainer apps. `.screenSaver`
(1000) is the highest standard user-space window level and reliably
sits above ordinary fullscreen NSWindow content.

The collection behaviour (canJoinAllSpaces + fullScreenAuxiliary +
stationary + ignoresCycle) is unchanged — the level was the missing
piece.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:11:51 +02:00
Jonas Bark
31bdfa74bb macos: pin main panel to .normal and orderFront sub-window after elevation
User reported the trainer overlay sub-window only appeared after
minimising and restoring the main window, and that it still wasn't
above fullscreened trainer apps. Both rooted in stacking:

- `NSPanel`'s default window level can be `.floating` (3) depending on
  style mask, which sits above the sub-window we just elevated to
  `.statusBar` (25)... unless the OS re-stacks. Pin self.level to
  `.normal` (0) so .statusBar unambiguously wins.

- `window.level = ...` doesn't re-stack the window inside its new level
  group. Without an explicit `orderFront(nil)`, the sub-window stays
  visually behind the main panel until something forces a restack
  (which is what minimising + restoring did). Order it to the front
  right after the level change.

Also logs via NSLog whether elevation found the sub-window so we can
confirm next test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:09:46 +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
08f6c5256e macos: let MainFlutterWindow (NSPanel) become the macOS main window
When MainFlutterWindow was changed from NSWindow to NSPanel, the panel
inherited NSPanel's defaults of canBecomeMain=false and canBecomeKey=false
(designed for utility palettes). As a result, NSApp.mainWindow stayed nil.

multi_window_native's macOS plugin registers the main app's messenger by
looking up `NSApp.mainWindow` in its register(with:) hook (plugin source
line 24). With nil, main's messenger never enters the plugin's static
broadcast list, so secondary-window broadcasts (button taps from the
trainer overlay) fan out to a list that doesn't include main. The Dart
listener on main never fires.

Override canBecomeMain and canBecomeKey so the panel participates as the
app's main window.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 12:04:19 +02:00
Jonas Bark
05fdcd819b macOS 2026-05-12 12:00:36 +02:00
Jonas Bark
3d5a2b5521 fix background 2026-05-12 11:56:48 +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
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
b71483f0f0 macos: float overlay sub-window above fullscreen trainer apps
window_manager's setVisibleOnAllWorkspaces+visibleOnFullScreen sets the
right collection-behavior bits but leaves the window at the default
(.normal) level, which Zwift / MyWhoosh on their own fullscreen Space
sit above. Set the sub-window's NSWindow.level to .statusBar and add
.fullScreenAuxiliary + .canJoinAllSpaces + .stationary collection
behavior so it floats above the fullscreen app and stays put across
Space switches.

Done in setOnWindowCreatedCallback (dispatched async since
controller.view.window is nil until the view is hosted), affecting only
sub-windows (currently only the trainer overlay).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 18:27:07 +02:00
Jonas Bark
12fc7eed87 deps: add desktop_multi_window 0.3.0 and wire macOS plugin callback
Add desktop_multi_window ^0.3.0 alongside window_manager. Update
macos/Runner/MainFlutterWindow.swift with the FlutterMultiWindowPlugin
window-created callback so sub-window engines register all generated
plugins automatically. Also includes flutter pub get generated changes to
linux/windows/macos plugin registrants.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 16:07:18 +02:00
Jonas Bark
5b94740220 macOS login 2026-02-16 17:17:52 +01:00
Jonas Bark
e1a7aac3e4 sign in with google, apple 2026-02-16 16:26:22 +01:00
Jonas Bark
60a61fd38d fix missing entitlements on release builds for macOS 2025-12-20 20:40:12 +01:00
Jonas Bark
b69d41ecb5 in app purchase implementation on macOS / iOS 2025-12-14 19:32:23 +01:00
Jonas Bark
5bf9c4df63 work on mDNS 2025-12-05 10:51:40 +01:00
copilot-swe-agent[bot]
fd1b82ed8b Rename app from SwiftControl to BikeControl and update GitHub repo references
Co-authored-by: jonasbark <1151304+jonasbark@users.noreply.github.com>
2025-11-21 18:07:48 +00:00
Jonas Bark
c72cadce62 MyWhoosh Link implementation #1 2025-10-21 22:43:02 +02:00
Jonas Bark
c08303bf80 fix issue #114 by adding missing entitlement 2025-10-17 20:42:26 +02:00
Jonas Bark
b939c36863 new icon, cleanup 2025-10-16 23:46:32 +02:00
Jonas Bark
6756772a04 integrate shorebird 2025-10-12 11:05:13 +02:00
Jonas Bark
5969e39cd0 rebuild 2025-10-09 12:52:28 +02:00
Jonas Bark
15723a9d4e - keep iOS app alive when in background
- keep app active on iOS to keep the remote control happy
- reconnect when this was ignored
2025-10-09 09:51:47 +02:00
Jonas Bark
53de365f70 use relative coordinates on iOS touch targets 2025-10-07 21:52:41 +02:00
Jonas Bark
1ac311ed76 make macOS work #7 2025-10-07 20:42:12 +02:00
Jonas Bark
0fe86c2c1b make macOS work #7 2025-10-07 20:08:46 +02:00
Jonas Bark
d83b9985ea version update check => internet permission is required 2025-03-31 20:58:27 +02:00
Jonas Bark
3fd2d4ccba fix #6 for real this time 2025-03-30 21:18:18 +02:00
Jonas Bark
0bb0b7f74d Android: allow user to adjust touch placements 2025-03-30 14:26:51 +02:00
Jonas Bark
9172642b6b try to notarize macOS app 2025-03-28 16:16:49 +01:00
Jonas Bark
6154f59015 web fixes, logo, github actions 2025-03-28 12:31:04 +01:00
Jonas Bark
d8367548a6 change app icon 2025-03-28 11:18:16 +01:00
Jonas Bark
ff8c92ad85 change icon 2025-03-27 20:11:43 +01:00
Jonas Bark
4071473e45 works on macOS, Web and Android 2025-03-26 19:39:00 +01:00
Jonas Bark
7ab8ca0a8d connection to click 2025-03-26 18:12:56 +01:00
Jonas Bark
793ed76100 initial commit 2025-03-26 15:41:06 +01:00