Closed yuanhoujun closed 6 months ago
The WindowManipulator
’s initialize
method has a named parameter called enableWindowDelegate
. If it is set to false, macos_window_utils will not use the NSWindowDelegate
.
Adding a return value to the Dart code is impossible due to the asynchronous nature of the platform channels, however, it’d be possible to override the return value of the windowShouldClose
method of the FlutterWindowDelegate
.
I’ll assign myself.
I know this method, but in macos_ui
, When initializing the window using the following code:
const config = MacosWindowUtilsConfig();
await config.apply();
Future<void> apply() async {
WidgetsFlutterBinding.ensureInitialized();
// Here is true
await WindowManipulator.initialize(enableWindowDelegate: true);
await WindowManipulator.setMaterial(
NSVisualEffectViewMaterial.windowBackground,
);
if (enableFullSizeContentView) {
await WindowManipulator.enableFullSizeContentView();
}
if (makeTitlebarTransparent) {
await WindowManipulator.makeTitlebarTransparent();
}
if (hideTitle) {
await WindowManipulator.hideTitle();
}
await WindowManipulator.addToolbar();
await WindowManipulator.setToolbarStyle(
toolbarStyle: toolbarStyle,
);
if (removeMenubarInFullScreenMode) {
final delegate = _FlutterWindowDelegate();
WindowManipulator.addNSWindowDelegate(delegate);
}
if (autoHideToolbarAndMenuBarInFullScreenMode) {
final options = NSAppPresentationOptions.from({
NSAppPresentationOption.fullScreen,
NSAppPresentationOption.autoHideToolbar,
NSAppPresentationOption.autoHideMenuBar,
NSAppPresentationOption.autoHideDock,
});
options.applyAsFullScreenPresentationOptions();
}
}
It has actually set the parameter to true and relies on this parameter. I cannot modify it and may produce unpredictable behavior, such as the toolbar not being removed correctly, etc.
Do you have any idea to handle this ?
If what you are trying to achieve is preventing the window from being closed by the user, then there is currently no way to do that, however, I could implement such a feature in a future version of macos_window_utils, which is what I have assigned myself to this issue for.
macos_window_utils 1.5.0 now provides the following methods:
preventWindowClosure
allowWindowClosure
isWindowClosureAllowed
closeWindow
performClose
These will allow you to prevent the window from being closable by the user as well as close the window programmatically.
Can this interface add a boolean return value? Used to control whether the window needs to be closed