Skip to content

Commit

Permalink
0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Feb 19, 2022
1 parent ec990b6 commit 0348957
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"type_traits": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xtr1common": "cpp"
"xtr1common": "cpp",
"__locale": "cpp",
"__string": "cpp",
"string": "cpp",
"string_view": "cpp"
}
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.1.6

- Implement `isPreventClose` & `setPreventClose` methods #69
- Implement `close` event
- [macos & windows] Reimplement `close` method
- [windows] Fix Horizontal resizing not working on secondary display. #71
- [macos] Implement `isFocused` method
- Implement `setAlignment` method #52

## 0.1.5

- Implement `close` method #56
Expand Down
94 changes: 91 additions & 3 deletions README-ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [关闭时退出](#关闭时退出)
- [macOS](#macos)
- [Windows](#windows)
- [关闭前确认](#关闭前确认)
- [在启动时隐藏](#在启动时隐藏)
- [macOS](#macos-1)
- [Windows](#windows-1)
Expand All @@ -36,9 +37,11 @@
- [WindowManager](#windowmanager)
- [Methods](#methods)
- [close](#close)
- [isPreventClose](#ispreventclose)
- [setPreventClose](#setpreventclose)
- [focus](#focus)
- [blur `macos` `windows`](#blur--macos--windows)
- [isFocused `windows`](#isfocused--windows)
- [isFocused `macos` `windows`](#isfocused--macos--windows)
- [show](#show)
- [hide](#hide)
- [isVisible](#isvisible)
Expand Down Expand Up @@ -84,6 +87,7 @@
- [startDragging](#startdragging)
- [WindowListener](#windowlistener)
- [Methods](#methods-1)
- [onWindowClose](#onwindowclose)
- [onWindowFocus](#onwindowfocus)
- [onWindowBlur](#onwindowblur)
- [onWindowMaximize](#onwindowmaximize)
Expand Down Expand Up @@ -113,7 +117,7 @@

```yaml
dependencies:
window_manager: ^0.1.5
window_manager: ^0.1.6
```
Expand Down Expand Up @@ -188,6 +192,11 @@ class _HomePageState extends State<HomePage> with WindowListener {
print('[WindowManager] onWindowEvent: $eventName');
}
@override
void onWindowClose() {
// do something
}
@override
void onWindowFocus() {
// do something
Expand Down Expand Up @@ -279,6 +288,72 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
}
```

### 关闭前确认

```dart
import 'package:flutter/cupertino.dart';
import 'package:window_manager/window_manager.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with WindowListener {
@override
void initState() {
windowManager.addListener(this);
super.initState();
}
void _init() async {
await windowManager.setPreventClose(true);
setState(() {});
}
@override
void dispose() {
windowManager.removeListener(this);
super.dispose();
}
@override
Widget build(BuildContext context) {
// ...
}
@override
void onWindowClose() async {
bool _isPreventClose = await windowManager.isPreventClose();
if (_isPreventClose) {
showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Text('Are you sure you want to close this window?'),
actions: [
TextButton(
child: Text('No'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text('Yes'),
onPressed: () {
Navigator.of(context).pop();
exit(0);
},
),
],
);
},
);
}
}
}
```

#### 在启动时隐藏

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

Try to close the window.

##### isPreventClose

Check if is intercepting the native close signal.

##### setPreventClose

Set if intercept the native close signal. May useful when combine with the onclose event listener.
This will also prevent the manually triggered close event.

##### focus

Focuses on the window.
Expand All @@ -395,7 +479,7 @@ Focuses on the window.
Removes focus from the window.


##### isFocused `windows`
##### isFocused `macos` `windows`

Returns `bool` - Whether window is focused.

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

#### Methods

##### onWindowClose

Emitted when the window is going to be closed.

##### onWindowFocus

Emitted when the window gains focus.
Expand Down
94 changes: 91 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ English | [简体中文](./README-ZH.md)
- [Quit on close](#quit-on-close)
- [macOS](#macos)
- [Windows](#windows)
- [Confirm before closing](#confirm-before-closing)
- [Hidden at launch](#hidden-at-launch)
- [macOS](#macos-1)
- [Windows](#windows-1)
Expand All @@ -36,9 +37,11 @@ English | [简体中文](./README-ZH.md)
- [WindowManager](#windowmanager)
- [Methods](#methods)
- [close](#close)
- [isPreventClose](#ispreventclose)
- [setPreventClose](#setpreventclose)
- [focus](#focus)
- [blur `macos` `windows`](#blur--macos--windows)
- [isFocused `windows`](#isfocused--windows)
- [isFocused `macos` `windows`](#isfocused--macos--windows)
- [show](#show)
- [hide](#hide)
- [isVisible](#isvisible)
Expand Down Expand Up @@ -84,6 +87,7 @@ English | [简体中文](./README-ZH.md)
- [startDragging](#startdragging)
- [WindowListener](#windowlistener)
- [Methods](#methods-1)
- [onWindowClose](#onwindowclose)
- [onWindowFocus](#onwindowfocus)
- [onWindowBlur](#onwindowblur)
- [onWindowMaximize](#onwindowmaximize)
Expand Down Expand Up @@ -113,7 +117,7 @@ Add this to your package's `pubspec.yaml` file:

```yaml
dependencies:
window_manager: ^0.1.5
window_manager: ^0.1.6
```
Or
Expand Down Expand Up @@ -188,6 +192,11 @@ class _HomePageState extends State<HomePage> with WindowListener {
print('[WindowManager] onWindowEvent: $eventName');
}
@override
void onWindowClose() {
// do something
}
@override
void onWindowFocus() {
// do something
Expand Down Expand Up @@ -279,6 +288,72 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
}
```

### Confirm before closing

```dart
import 'package:flutter/cupertino.dart';
import 'package:window_manager/window_manager.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with WindowListener {
@override
void initState() {
windowManager.addListener(this);
super.initState();
}
void _init() async {
await windowManager.setPreventClose(true);
setState(() {});
}
@override
void dispose() {
windowManager.removeListener(this);
super.dispose();
}
@override
Widget build(BuildContext context) {
// ...
}
@override
void onWindowClose() async {
bool _isPreventClose = await windowManager.isPreventClose();
if (_isPreventClose) {
showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Text('Are you sure you want to close this window?'),
actions: [
TextButton(
child: Text('No'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text('Yes'),
onPressed: () {
Navigator.of(context).pop();
exit(0);
},
),
],
);
},
);
}
}
}
```

#### Hidden at launch

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

Try to close the window.

##### isPreventClose

Check if is intercepting the native close signal.

##### setPreventClose

Set if intercept the native close signal. May useful when combine with the onclose event listener.
This will also prevent the manually triggered close event.

##### focus

Focuses on the window.
Expand All @@ -395,7 +479,7 @@ Focuses on the window.
Removes focus from the window.


##### isFocused `windows`
##### isFocused `macos` `windows`

Returns `bool` - Whether window is focused.

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

#### Methods

##### onWindowClose

Emitted when the window is going to be closed.

##### onWindowFocus

Emitted when the window gains focus.
Expand Down
1 change: 0 additions & 1 deletion example/lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';
import 'dart:ui';

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/cupertino.dart';
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.5"
version: "0.1.6"
sdks:
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.20.0"
2 changes: 1 addition & 1 deletion lib/src/window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class WindowManager {

/// Returns `bool` - Whether window is focused.
///
/// @platforms windows
/// @platforms macos,windows
Future<bool> isFocused() async {
return await _channel.invokeMethod('isFocused');
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: window_manager
description: This plugin allows Flutter desktop apps to resizing and repositioning the window.
version: 0.1.5
version: 0.1.6
homepage: https://github.com/leanflutter/window_manager

environment:
Expand Down
Loading

0 comments on commit 0348957

Please sign in to comment.