Skip to content

Commit e0427b9

Browse files
committed
[macos] Implement close method #56
1 parent d78b0a3 commit e0427b9

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

example/lib/pages/home.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class _HomePageState extends State<HomePage> with WindowListener {
6565
PreferenceListSection(
6666
title: Text('METHODS'),
6767
children: [
68+
PreferenceListItem(
69+
title: Text('close'),
70+
onTap: () async {
71+
await windowManager.close();
72+
await Future.delayed(Duration(seconds: 2));
73+
await windowManager.show();
74+
},
75+
),
6876
PreferenceListItem(
6977
title: Text('focus / blur'),
7078
onTap: () async {

lib/src/window_manager.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,20 @@ class WindowManager {
8888
await _channel.invokeMethod('waitUntilReadyToShow');
8989
}
9090

91+
/// Try to close the window.
92+
Future<void> close() async {
93+
await _channel.invokeMethod('close');
94+
}
95+
9196
/// Focuses on the window.
92-
Future<void> focus({bool inactive = false}) async {
97+
Future<void> focus() async {
9398
await _channel.invokeMethod('focus');
9499
}
95100

96101
/// Removes focus from the window.
97102
///
98103
/// @platforms macos,windows
99-
Future<void> blur({bool inactive = false}) async {
104+
Future<void> blur() async {
100105
await _channel.invokeMethod('blur');
101106
}
102107

macos/Classes/WindowManagerPlugin.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public class WindowManagerPlugin: NSObject, FlutterPlugin {
5656
windowManager.setAsFrameless()
5757
result(true)
5858
break
59+
case "close":
60+
windowManager.close()
61+
result(true)
62+
break
5963
case "focus":
6064
windowManager.focus()
6165
result(true)

0 commit comments

Comments
 (0)