Commit Graph

7 Commits

Author SHA1 Message Date
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