Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: Implement isMaximizable and setMaximizable #290

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion example/integration_test/window_manager_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Future<void> main() async {

testWidgets('isMaximizable', (tester) async {
expect(await windowManager.isMaximizable(), isTrue);
}, skip: Platform.isMacOS);
});

testWidgets('isMaximized', (tester) async {
expect(await windowManager.isMaximized(), isFalse);
Expand Down
20 changes: 19 additions & 1 deletion macos/Classes/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions macos/Classes/WindowManagerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down