Commit Graph

8 Commits

Author SHA1 Message Date
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
15a04604ab windows: register only window_manager + desktop_multi_window on sub-engine
Confirmed: calling RegisterPlugins (every plugin) on the secondary
engine deadlocks its boot before Dart main() runs. With registration
skipped entirely, Dart runs and we get MissingPluginException on
window_manager.ensureInitialized() — which means the overlay can now
launch as soon as it has just the plugins it actually uses.

Register only:
- WindowManagerPlugin — needed for size, position, alwaysOnTop, etc.
- DesktopMultiWindowPlugin — needed for the WindowMethodChannel that
  carries state updates from the parent.

The other ~17 plugins (BLE, IAP, key hooks, accessibility, media,
URL launcher, share, screen capture, ...) stay registered on the
MAIN engine only. The overlay never needs them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 11:03:29 +02:00
Jonas Bark
3ea37b6c06 overlay/desktop: diagnose Windows white-window by skipping sub-engine plugins
Both desktop_multi_window and multi_window_native produce a white
empty sub-window on Windows, and no Dart prints reach the console.
Two-pronged diagnostic:

1. Liveness via file write. The sub-engine's stdout/stderr may not
   route to `flutter run`'s captured streams. Write a line to
   `%TEMP%/bikecontrol_dart_alive.log` as the FIRST thing in main();
   if the file appears after toggling the overlay, Dart is running
   and we just couldn't see its console output.

2. Skip RegisterPlugins on the desktop_multi_window sub-engine. The
   common factor between BOTH packages failing the same way is the
   ~20 Windows plugins in this app — several own process-singleton
   resources (windows_iap, smtc_windows, BLE, key hooks) already
   held by the main engine. Re-registering them on a second engine
   in the same process may not error but can deadlock the secondary
   engine's bring-up before Dart main runs. If skipping registration
   unblocks Dart, we'll add back the small handful the overlay
   actually needs (desktop_multi_window + window_manager).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 10:55:05 +02:00
Jonas Bark
20fc10395d overlay/desktop: use desktop_multi_window on Windows, keep multi_window_native on macOS
Add `desktop_multi_window: ^0.3.0` alongside `multi_window_native: ^1.0.4`.
On Windows the sub-window is now spawned via `WindowController.create` with a
JSON `role=trainer-overlay` argument (detected in `main()` before any heavy
bootstrap), and state/actions flow over `WindowMethodChannel(kOverlayChannel)`.
macOS continues using `MultiWindowNative.createWindow` / `notifyAllWindows` /
`registerListener` unchanged.

Windows runner reverts all `multi_window_native` plumbing:
`SecondaryWindowContext`, `CreateNewWindow`, `CloseWindow`,
`SetMainWindowMethodHandler`, and the plugin source compiled directly into the
runner are removed. `flutter_window.cpp` instead registers
`DesktopMultiWindowSetWindowCreatedCallback` so every sub-engine gets plugins.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:33:14 +02:00
Jonas Bark
596f851566 Windows adjustments 2026-05-12 09:11:19 +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
8fcca6a18c windows: register plugins on desktop_multi_window sub-window engines
Mirrors the macOS callback wired in MainFlutterWindow.swift. Without
this, the trainer-overlay sub-window's Flutter engine has no plugin
registrations, so WindowMethodChannel calls between parent and overlay
silently fail and the overlay never receives state updates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 16:13:54 +02:00
Jonas Bark
793ed76100 initial commit 2025-03-26 15:41:06 +01:00