Skip to content

Commit 0348957

Browse files
committed
0.1.6
1 parent ec990b6 commit 0348957

File tree

10 files changed

+207
-19
lines changed

10 files changed

+207
-19
lines changed

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
"type_traits": "cpp",
1010
"xlocmon": "cpp",
1111
"xlocnum": "cpp",
12-
"xtr1common": "cpp"
12+
"xtr1common": "cpp",
13+
"__locale": "cpp",
14+
"__string": "cpp",
15+
"string": "cpp",
16+
"string_view": "cpp"
1317
}
1418
}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.1.6
2+
3+
- Implement `isPreventClose` & `setPreventClose` methods #69
4+
- Implement `close` event
5+
- [macos & windows] Reimplement `close` method
6+
- [windows] Fix Horizontal resizing not working on secondary display. #71
7+
- [macos] Implement `isFocused` method
8+
- Implement `setAlignment` method #52
9+
110
## 0.1.5
211

312
- Implement `close` method #56

README-ZH.md

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [关闭时退出](#关闭时退出)
2929
- [macOS](#macos)
3030
- [Windows](#windows)
31+
- [关闭前确认](#关闭前确认)
3132
- [在启动时隐藏](#在启动时隐藏)
3233
- [macOS](#macos-1)
3334
- [Windows](#windows-1)
@@ -36,9 +37,11 @@
3637
- [WindowManager](#windowmanager)
3738
- [Methods](#methods)
3839
- [close](#close)
40+
- [isPreventClose](#ispreventclose)
41+
- [setPreventClose](#setpreventclose)
3942
- [focus](#focus)
4043
- [blur `macos` `windows`](#blur--macos--windows)
41-
- [isFocused `windows`](#isfocused--windows)
44+
- [isFocused `macos` `windows`](#isfocused--macos--windows)
4245
- [show](#show)
4346
- [hide](#hide)
4447
- [isVisible](#isvisible)
@@ -84,6 +87,7 @@
8487
- [startDragging](#startdragging)
8588
- [WindowListener](#windowlistener)
8689
- [Methods](#methods-1)
90+
- [onWindowClose](#onwindowclose)
8791
- [onWindowFocus](#onwindowfocus)
8892
- [onWindowBlur](#onwindowblur)
8993
- [onWindowMaximize](#onwindowmaximize)
@@ -113,7 +117,7 @@
113117

114118
```yaml
115119
dependencies:
116-
window_manager: ^0.1.5
120+
window_manager: ^0.1.6
117121
```
118122
119123
@@ -188,6 +192,11 @@ class _HomePageState extends State<HomePage> with WindowListener {
188192
print('[WindowManager] onWindowEvent: $eventName');
189193
}
190194
195+
@override
196+
void onWindowClose() {
197+
// do something
198+
}
199+
191200
@override
192201
void onWindowFocus() {
193202
// do something
@@ -279,6 +288,72 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
279288
}
280289
```
281290

291+
### 关闭前确认
292+
293+
```dart
294+
import 'package:flutter/cupertino.dart';
295+
import 'package:window_manager/window_manager.dart';
296+
297+
class HomePage extends StatefulWidget {
298+
@override
299+
_HomePageState createState() => _HomePageState();
300+
}
301+
302+
class _HomePageState extends State<HomePage> with WindowListener {
303+
@override
304+
void initState() {
305+
windowManager.addListener(this);
306+
super.initState();
307+
}
308+
309+
void _init() async {
310+
await windowManager.setPreventClose(true);
311+
setState(() {});
312+
}
313+
314+
@override
315+
void dispose() {
316+
windowManager.removeListener(this);
317+
super.dispose();
318+
}
319+
320+
@override
321+
Widget build(BuildContext context) {
322+
// ...
323+
}
324+
325+
@override
326+
void onWindowClose() async {
327+
bool _isPreventClose = await windowManager.isPreventClose();
328+
if (_isPreventClose) {
329+
showDialog(
330+
context: context,
331+
builder: (_) {
332+
return AlertDialog(
333+
title: Text('Are you sure you want to close this window?'),
334+
actions: [
335+
TextButton(
336+
child: Text('No'),
337+
onPressed: () {
338+
Navigator.of(context).pop();
339+
},
340+
),
341+
TextButton(
342+
child: Text('Yes'),
343+
onPressed: () {
344+
Navigator.of(context).pop();
345+
exit(0);
346+
},
347+
),
348+
],
349+
);
350+
},
351+
);
352+
}
353+
}
354+
}
355+
```
356+
282357
#### 在启动时隐藏
283358

284359
##### macOS
@@ -386,6 +461,15 @@ class _HomePageState extends State<HomePage> with WindowListener {
386461

387462
Try to close the window.
388463

464+
##### isPreventClose
465+
466+
Check if is intercepting the native close signal.
467+
468+
##### setPreventClose
469+
470+
Set if intercept the native close signal. May useful when combine with the onclose event listener.
471+
This will also prevent the manually triggered close event.
472+
389473
##### focus
390474

391475
Focuses on the window.
@@ -395,7 +479,7 @@ Focuses on the window.
395479
Removes focus from the window.
396480

397481

398-
##### isFocused `windows`
482+
##### isFocused `macos` `windows`
399483

400484
Returns `bool` - Whether window is focused.
401485

@@ -589,6 +673,10 @@ Starts a window drag based on the specified mouse-down event.
589673

590674
#### Methods
591675

676+
##### onWindowClose
677+
678+
Emitted when the window is going to be closed.
679+
592680
##### onWindowFocus
593681

594682
Emitted when the window gains focus.

README.md

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ English | [简体中文](./README-ZH.md)
2828
- [Quit on close](#quit-on-close)
2929
- [macOS](#macos)
3030
- [Windows](#windows)
31+
- [Confirm before closing](#confirm-before-closing)
3132
- [Hidden at launch](#hidden-at-launch)
3233
- [macOS](#macos-1)
3334
- [Windows](#windows-1)
@@ -36,9 +37,11 @@ English | [简体中文](./README-ZH.md)
3637
- [WindowManager](#windowmanager)
3738
- [Methods](#methods)
3839
- [close](#close)
40+
- [isPreventClose](#ispreventclose)
41+
- [setPreventClose](#setpreventclose)
3942
- [focus](#focus)
4043
- [blur `macos` `windows`](#blur--macos--windows)
41-
- [isFocused `windows`](#isfocused--windows)
44+
- [isFocused `macos` `windows`](#isfocused--macos--windows)
4245
- [show](#show)
4346
- [hide](#hide)
4447
- [isVisible](#isvisible)
@@ -84,6 +87,7 @@ English | [简体中文](./README-ZH.md)
8487
- [startDragging](#startdragging)
8588
- [WindowListener](#windowlistener)
8689
- [Methods](#methods-1)
90+
- [onWindowClose](#onwindowclose)
8791
- [onWindowFocus](#onwindowfocus)
8892
- [onWindowBlur](#onwindowblur)
8993
- [onWindowMaximize](#onwindowmaximize)
@@ -113,7 +117,7 @@ Add this to your package's `pubspec.yaml` file:
113117

114118
```yaml
115119
dependencies:
116-
window_manager: ^0.1.5
120+
window_manager: ^0.1.6
117121
```
118122
119123
Or
@@ -188,6 +192,11 @@ class _HomePageState extends State<HomePage> with WindowListener {
188192
print('[WindowManager] onWindowEvent: $eventName');
189193
}
190194
195+
@override
196+
void onWindowClose() {
197+
// do something
198+
}
199+
191200
@override
192201
void onWindowFocus() {
193202
// do something
@@ -279,6 +288,72 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
279288
}
280289
```
281290

291+
### Confirm before closing
292+
293+
```dart
294+
import 'package:flutter/cupertino.dart';
295+
import 'package:window_manager/window_manager.dart';
296+
297+
class HomePage extends StatefulWidget {
298+
@override
299+
_HomePageState createState() => _HomePageState();
300+
}
301+
302+
class _HomePageState extends State<HomePage> with WindowListener {
303+
@override
304+
void initState() {
305+
windowManager.addListener(this);
306+
super.initState();
307+
}
308+
309+
void _init() async {
310+
await windowManager.setPreventClose(true);
311+
setState(() {});
312+
}
313+
314+
@override
315+
void dispose() {
316+
windowManager.removeListener(this);
317+
super.dispose();
318+
}
319+
320+
@override
321+
Widget build(BuildContext context) {
322+
// ...
323+
}
324+
325+
@override
326+
void onWindowClose() async {
327+
bool _isPreventClose = await windowManager.isPreventClose();
328+
if (_isPreventClose) {
329+
showDialog(
330+
context: context,
331+
builder: (_) {
332+
return AlertDialog(
333+
title: Text('Are you sure you want to close this window?'),
334+
actions: [
335+
TextButton(
336+
child: Text('No'),
337+
onPressed: () {
338+
Navigator.of(context).pop();
339+
},
340+
),
341+
TextButton(
342+
child: Text('Yes'),
343+
onPressed: () {
344+
Navigator.of(context).pop();
345+
exit(0);
346+
},
347+
),
348+
],
349+
);
350+
},
351+
);
352+
}
353+
}
354+
}
355+
```
356+
282357
#### Hidden at launch
283358

284359
##### macOS
@@ -386,6 +461,15 @@ class _HomePageState extends State<HomePage> with WindowListener {
386461

387462
Try to close the window.
388463

464+
##### isPreventClose
465+
466+
Check if is intercepting the native close signal.
467+
468+
##### setPreventClose
469+
470+
Set if intercept the native close signal. May useful when combine with the onclose event listener.
471+
This will also prevent the manually triggered close event.
472+
389473
##### focus
390474

391475
Focuses on the window.
@@ -395,7 +479,7 @@ Focuses on the window.
395479
Removes focus from the window.
396480

397481

398-
##### isFocused `windows`
482+
##### isFocused `macos` `windows`
399483

400484
Returns `bool` - Whether window is focused.
401485

@@ -589,6 +673,10 @@ Starts a window drag based on the specified mouse-down event.
589673

590674
#### Methods
591675

676+
##### onWindowClose
677+
678+
Emitted when the window is going to be closed.
679+
592680
##### onWindowFocus
593681

594682
Emitted when the window gains focus.

example/lib/pages/home.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'dart:io';
2-
import 'dart:ui';
32

43
import 'package:bot_toast/bot_toast.dart';
54
import 'package:flutter/cupertino.dart';

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ packages:
176176
path: ".."
177177
relative: true
178178
source: path
179-
version: "0.1.5"
179+
version: "0.1.6"
180180
sdks:
181181
dart: ">=2.14.0 <3.0.0"
182182
flutter: ">=1.20.0"

lib/src/window_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class WindowManager {
124124

125125
/// Returns `bool` - Whether window is focused.
126126
///
127-
/// @platforms windows
127+
/// @platforms macos,windows
128128
Future<bool> isFocused() async {
129129
return await _channel.invokeMethod('isFocused');
130130
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: window_manager
22
description: This plugin allows Flutter desktop apps to resizing and repositioning the window.
3-
version: 0.1.5
3+
version: 0.1.6
44
homepage: https://github.com/leanflutter/window_manager
55

66
environment:

0 commit comments

Comments
 (0)