@@ -64,9 +64,6 @@ class WindowOptions {
6464///
6565/// // Get the currently focused window
6666/// final currentWindow = windowManager.getCurrent();
67- ///
68- /// // Destroy a window
69- /// windowManager.destroy(windowId);
7067/// ```
7168class WindowManager with EventEmitter , CNativeApiBindingsMixin {
7269 static final WindowManager _instance = WindowManager ._();
@@ -76,25 +73,18 @@ class WindowManager with EventEmitter, CNativeApiBindingsMixin {
7673
7774 // Native callable for window event callbacks
7875 static late final NativeCallable <
79- Void Function (
80- Pointer <native_window_event_t>,
81- Pointer <Void >,
82- )> _eventCallback;
76+ Void Function (Pointer <native_window_event_t>, Pointer <Void >)
77+ >
78+ _eventCallback;
8379
8480 static bool _callbackInitialized = false ;
8581 static int ? _eventListenerId;
8682
8783 // Native callables for pre-show/hide hooks
88- static NativeCallable <
89- Void Function (
90- native_window_id_t,
91- Pointer <Void >,
92- )>? _willShowCallback;
93- static NativeCallable <
94- Void Function (
95- native_window_id_t,
96- Pointer <Void >,
97- )>? _willHideCallback;
84+ static NativeCallable <Void Function (native_window_id_t, Pointer <Void >)>?
85+ _willShowCallback;
86+ static NativeCallable <Void Function (native_window_id_t, Pointer <Void >)>?
87+ _willHideCallback;
9888
9989 // Dart-side hook handlers
10090 void Function (int windowId)? _onWillShowHook;
@@ -107,13 +97,10 @@ class WindowManager with EventEmitter, CNativeApiBindingsMixin {
10797 void startEventListening () {
10898 // Initialize callback once
10999 if (! _callbackInitialized) {
110- _eventCallback = NativeCallable <
111- Void Function (
112- Pointer <native_window_event_t>,
113- Pointer <Void >,
114- )>.listener (
115- _nativeOnWindowEvent,
116- );
100+ _eventCallback =
101+ NativeCallable <
102+ Void Function (Pointer <native_window_event_t>, Pointer <Void >)
103+ >.listener (_nativeOnWindowEvent);
117104 _callbackInitialized = true ;
118105 }
119106
@@ -194,10 +181,12 @@ class WindowManager with EventEmitter, CNativeApiBindingsMixin {
194181 WindowOptions (
195182 title: title,
196183 size: Size (width, height),
197- minimumSize:
198- minWidth != null && minHeight != null ? Size (minWidth, minHeight) : null ,
199- maximumSize:
200- maxWidth != null && maxHeight != null ? Size (maxWidth, maxHeight) : null ,
184+ minimumSize: minWidth != null && minHeight != null
185+ ? Size (minWidth, minHeight)
186+ : null ,
187+ maximumSize: maxWidth != null && maxHeight != null
188+ ? Size (maxWidth, maxHeight)
189+ : null ,
201190 centered: centered,
202191 ),
203192 );
@@ -289,13 +278,6 @@ class WindowManager with EventEmitter, CNativeApiBindingsMixin {
289278 return Window (nativeWindow);
290279 }
291280
292- /// Destroys a window by its ID.
293- ///
294- /// Returns true if the window was found and destroyed, false otherwise.
295- bool destroy (int windowId) {
296- return bindings.native_window_manager_destroy (windowId);
297- }
298-
299281 /// Shuts down the window manager and cleans up resources.
300282 ///
301283 /// This should typically be called when the application is exiting.
@@ -320,13 +302,13 @@ class WindowManager with EventEmitter, CNativeApiBindingsMixin {
320302 return ;
321303 }
322304
323- // (Re)create native callable and register
305+ // Use isolateLocal for synchronous execution on the same thread
306+ // This works because Flutter 3.22+ merges Dart isolate with platform thread
324307 _willShowCallback? .close ();
325- _willShowCallback = NativeCallable <
326- Void Function (
327- native_window_id_t,
328- Pointer <Void >,
329- )>.listener (_nativeOnWillShow);
308+ _willShowCallback =
309+ NativeCallable <
310+ Void Function (native_window_id_t, Pointer <Void >)
311+ >.listener (_nativeOnWillShow);
330312 bindings.native_window_manager_set_will_show_hook (
331313 _willShowCallback! .nativeFunction,
332314 nullptr,
@@ -345,12 +327,13 @@ class WindowManager with EventEmitter, CNativeApiBindingsMixin {
345327 return ;
346328 }
347329
330+ // Use isolateLocal for synchronous execution on the same thread
331+ // This works because Flutter 3.22+ merges Dart isolate with platform thread
348332 _willHideCallback? .close ();
349- _willHideCallback = NativeCallable <
350- Void Function (
351- native_window_id_t,
352- Pointer <Void >,
353- )>.listener (_nativeOnWillHide);
333+ _willHideCallback =
334+ NativeCallable <
335+ Void Function (native_window_id_t, Pointer <Void >)
336+ >.listener (_nativeOnWillHide);
354337 bindings.native_window_manager_set_will_hide_hook (
355338 _willHideCallback! .nativeFunction,
356339 nullptr,
@@ -379,4 +362,3 @@ class WindowManager with EventEmitter, CNativeApiBindingsMixin {
379362 }
380363 }
381364}
382-
0 commit comments