Files
swiftcontrol/packages/multi_window_native/lib/multi_window_native.dart
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

72 lines
2.0 KiB
Dart

import 'package:flutter/services.dart';
import 'package:multi_window_native/multi_window_native_method_channel.dart';
import 'multi_window_native_platform_interface.dart';
typedef MethodCallHandler = Future<dynamic> Function(MethodCall call);
class MultiWindowNative {
factory MultiWindowNative() {
return instance;
}
MultiWindowNative._internal();
static final MultiWindowNative instance = MultiWindowNative._internal();
// Future<String?> getPlatformVersion() {
// return MultiWindowNativePlatform.instance.getPlatformVersion();
// }
static void init(int windowId) {
MethodChannelMultiWindowNative.init(windowId);
}
static String registerListener(String methodName, MethodCallHandler handler) {
return MethodChannelMultiWindowNative.registerListener(methodName, handler);
}
static void unregisterListener({
required String methodName,
required String id,
}) {
MethodChannelMultiWindowNative.unregisterListener(
methodName: methodName,
id: id,
);
}
static Future<dynamic> handleMethodCall(MethodCall call) async {
return MethodChannelMultiWindowNative.handleMethodCall(call);
}
static Future<void> createWindow(List<String> args) {
return MultiWindowNativePlatform.instance.createAndRegisterWindow(
routeName: args[0],
theme: args[2],
argsJson: args[1],
);
}
static Future<void> closeWindow({required bool isMainWindow, required String windowId}) {
return MultiWindowNativePlatform.instance.notifyWindowClose(isMainWindow: isMainWindow, windowId: windowId);
}
static Future<int> windowCount() {
return MultiWindowNativePlatform.instance.getMessengerCount();
}
static Future<bool> notifyUiRendered() {
return MultiWindowNativePlatform.instance.notifyUiReady();
}
static Future<void> notifyAllWindows(String method, dynamic arguments) async {
return MultiWindowNativePlatform.instance.notifyAllWindows(
method,
arguments,
);
}
// Add other methods as needed
}