From 20b956f68775955821e445603a74ca87cbfb1fa9 Mon Sep 17 00:00:00 2001 From: Ben Hagen Date: Tue, 24 Jan 2023 18:13:07 +0100 Subject: [PATCH] macOS: Implement isMaximizable and setMaximizable fixes #289 --- README.md | 2 +- .../integration_test/window_manager_test.dart | 2 +- macos/Classes/WindowManager.swift | 20 ++++++++++++++++++- macos/Classes/WindowManagerPlugin.swift | 7 +++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c83d93e4..0996be87 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ English | [简体中文](./README-ZH.md) - [isMinimizable `macos` `windows`](#isminimizable--macos--windows) - [setMinimizable `macos` `windows`](#setminimizable--macos--windows) - [isClosable `windows`](#isclosable--windows) - - [isMaximizable `windows`](#ismaximizable--windows) + - [isMaximizable `macos` `windows`](#ismaximizable--macos--windows) - [setMaximizable](#setmaximizable) - [setClosable `macos` `windows`](#setclosable--macos--windows) - [isAlwaysOnTop](#isalwaysontop) diff --git a/example/integration_test/window_manager_test.dart b/example/integration_test/window_manager_test.dart index 764fc5fb..01c51041 100644 --- a/example/integration_test/window_manager_test.dart +++ b/example/integration_test/window_manager_test.dart @@ -50,7 +50,7 @@ Future main() async { testWidgets('isMaximizable', (tester) async { expect(await windowManager.isMaximizable(), isTrue); - }, skip: Platform.isMacOS); + }); testWidgets('isMaximized', (tester) async { expect(await windowManager.isMaximized(), isFalse); diff --git a/macos/Classes/WindowManager.swift b/macos/Classes/WindowManager.swift index 205a6fd9..6bd5e641 100644 --- a/macos/Classes/WindowManager.swift +++ b/macos/Classes/WindowManager.swift @@ -51,7 +51,8 @@ public class WindowManager: NSObject, NSWindowDelegate { private var _isPreventClose: Bool = false private var _isMaximized: Bool = false - + private var _isMaximizable: Bool = true + override public init() { super.init() } @@ -88,6 +89,14 @@ public class WindowManager: NSObject, NSWindowDelegate { public func setPreventClose(_ args: [String: Any]) { _isPreventClose = args["isPreventClose"] as! Bool } + + public func isMaximizable() -> Bool { + return _isMaximizable; + } + + public func setIsMaximizable(_ args: [String: Any]) { + _isMaximizable = args["isMaximizable"] as! Bool + } public func focus() { NSApp.activate(ignoringOtherApps: false) @@ -458,6 +467,15 @@ public class WindowManager: NSObject, NSWindowDelegate { } return true; } + + public func windowShouldZoom(_ window: NSWindow, toFrame newFrame: NSRect) -> Bool { + _emitEvent("maximize") + if (isMaximizable()) { + return true + } + return false; + } + public func windowDidResize(_ notification: Notification) { _emitEvent("resize") diff --git a/macos/Classes/WindowManagerPlugin.swift b/macos/Classes/WindowManagerPlugin.swift index 80a3b2ad..eb40549e 100644 --- a/macos/Classes/WindowManagerPlugin.swift +++ b/macos/Classes/WindowManagerPlugin.swift @@ -107,6 +107,13 @@ public class WindowManagerPlugin: NSObject, FlutterPlugin { case "isMinimized": result(windowManager.isMinimized()) break + case "isMaximizable": + result(windowManager.isMaximizable()) + break + case "setMaximizable": + windowManager.setIsMaximizable(args) + result(true) + break case "minimize": windowManager.minimize() result(true)