Skip to content

Commit 775846b

Browse files
authored
[desktop_multi_window] Added the resizable function (macOS only) (MixinNetwork#130)
* [desktop_multi_window] first pass at `resizable` flag * [desktop_multi_window] fix typo in example * [desktop_multi_window] Working resizable function Fixes an error I made where the insert/remove functions were in the wrong blocks of the condition * [desktop_multi_window] Improve docs * Improves `resizable` docs * Fix grammar for `setFrameAutosaveName` * [desktop_multi_window] Make it clear that `resizable` is only for macOS * [desktop_multi_window] Update version & changelog
1 parent 2e1c1d5 commit 775846b

File tree

11 files changed

+57
-8
lines changed

11 files changed

+57
-8
lines changed

packages/desktop_multi_window/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0
2+
* Added the ability to determine whether a created window will be resizable or not
3+
([#101](https://github.com/MixinNetwork/flutter-plugins/issues/101) and [#130](https://github.com/MixinNetwork/flutter-plugins/pull/130))
4+
15
## 0.1.0
26

37
* [BREAK CHANGE] upgrade min flutter version to 3.0.0

packages/desktop_multi_window/example/lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ class _ExampleMainWindowState extends State<_ExampleMainWindow> {
4545
'args1': 'Sub window',
4646
'args2': 100,
4747
'args3': true,
48-
'bussiness': 'bussiness_test',
48+
'business': 'business_test',
4949
}));
5050
window
5151
..setFrame(const Offset(0, 0) & const Size(1280, 720))
5252
..center()
5353
..setTitle('Another window')
54+
..resizable(false)
5455
..show();
5556
},
5657
child: const Text('Create a new World!'),

packages/desktop_multi_window/example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ packages:
6363
path: ".."
6464
relative: true
6565
source: path
66-
version: "0.0.2"
66+
version: "0.2.0"
6767
fake_async:
6868
dependency: transitive
6969
description:

packages/desktop_multi_window/lib/desktop_multi_window.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DesktopMultiWindow {
2727
/// NOTE: [createWindow] will only create a new window, you need to call
2828
/// [WindowController.show] to show the window.
2929
static Future<WindowController> createWindow([String? arguments]) async {
30-
final windowId = await miltiWindowChannel.invokeMethod<int>(
30+
final windowId = await multiWindowChannel.invokeMethod<int>(
3131
'createWindow',
3232
arguments,
3333
);
@@ -73,7 +73,7 @@ class DesktopMultiWindow {
7373

7474
/// Get all sub window id.
7575
static Future<List<int>> getAllSubWindowIds() async {
76-
final result = await miltiWindowChannel
76+
final result = await multiWindowChannel
7777
.invokeMethod<List<dynamic>>('getAllSubWindowIds');
7878
final ids = result?.cast<int>() ?? const [];
7979
assert(!ids.contains(0), 'ids must not contains main window id');

packages/desktop_multi_window/lib/src/channels.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/services.dart';
22

3-
const miltiWindowChannel = MethodChannel('mixin.one/flutter_multi_window');
3+
const multiWindowChannel = MethodChannel('mixin.one/flutter_multi_window');
44

55
const windowEventChannel = MethodChannel(
66
'mixin.one/flutter_multi_window_channel',

packages/desktop_multi_window/lib/src/window_controller.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ abstract class WindowController {
3636
/// Set the window's title.
3737
Future<void> setTitle(String title);
3838

39-
/// available only on macOS.
39+
/// Whether the window can be resized. Available only on macOS.
40+
///
41+
/// Most useful for ensuring windows *cannot* be resized. Windows are
42+
/// resizable by default, so there is no need to explicitly define a window
43+
/// as resizable by calling this function.
44+
Future<void> resizable(bool resizable);
45+
46+
/// Available only on macOS.
4047
Future<void> setFrameAutosaveName(String name);
4148
}

packages/desktop_multi_window/lib/src/window_controller_impl.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:io';
12
import 'dart:ui';
23

34
import 'package:flutter/services.dart';
@@ -6,7 +7,7 @@ import 'channels.dart';
67
import 'window_controller.dart';
78

89
class WindowControllerMainImpl extends WindowController {
9-
final MethodChannel _channel = miltiWindowChannel;
10+
final MethodChannel _channel = multiWindowChannel;
1011

1112
// the id of this window
1213
final int _id;
@@ -55,6 +56,20 @@ class WindowControllerMainImpl extends WindowController {
5556
});
5657
}
5758

59+
@override
60+
Future<void> resizable(bool resizable) {
61+
if (Platform.isMacOS) {
62+
return _channel.invokeMethod('resizable', <String, dynamic>{
63+
'windowId': _id,
64+
'resizable': resizable,
65+
});
66+
} else {
67+
throw MissingPluginException(
68+
'This functionality is only available on macOS',
69+
);
70+
}
71+
}
72+
5873
@override
5974
Future<void> setFrameAutosaveName(String name) {
6075
return _channel.invokeMethod('setFrameAutosaveName', <String, dynamic>{

packages/desktop_multi_window/macos/Classes/FlutterMultiWindowPlugin.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ public class FlutterMultiWindowPlugin: NSObject, FlutterPlugin {
6767
let title = arguments["title"] as! String
6868
MultiWindowManager.shared.setTitle(windowId: windowId, title: title)
6969
result(nil)
70+
case "resizable":
71+
let arguments = call.arguments as! [String: Any?]
72+
let windowId = arguments["windowId"] as! Int64
73+
let resizable = arguments["resizable"] as! Bool
74+
MultiWindowManager.shared.resizable(windowId: windowId, resizable: resizable)
75+
result(nil)
7076
case "setFrameAutosaveName":
7177
let arguments = call.arguments as! [String: Any?]
7278
let windowId = arguments["windowId"] as! Int64

packages/desktop_multi_window/macos/Classes/FlutterWindow.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ class BaseFlutterWindow: NSObject {
3939
window.title = title
4040
}
4141

42+
func resizable(resizable: Bool) {
43+
if (resizable) {
44+
window.styleMask.insert(.resizable)
45+
} else {
46+
window.styleMask.remove(.resizable)
47+
}
48+
}
49+
4250
func close() {
4351
window.close()
4452
}

packages/desktop_multi_window/macos/Classes/MultiWindowManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ class MultiWindowManager {
9494
window.setTitle(title: title)
9595
}
9696

97+
func resizable(windowId: Int64, resizable: Bool) {
98+
guard let window = windows[windowId] else {
99+
debugPrint("window \(windowId) not exists.")
100+
return
101+
}
102+
window.resizable(resizable: resizable)
103+
}
104+
97105
func setFrameAutosaveName(windowId: Int64, name: String) {
98106
guard let window = windows[windowId] else {
99107
debugPrint("window \(windowId) not exists.")

0 commit comments

Comments
 (0)