dev
dart 42 lines 1.3 KB
Raw
1 import 'dart:io';
2
3 import 'package:cw_core/utils/print_verbose.dart';
4 import 'package:flutter/services.dart';
5
6 const MethodChannel _channel = MethodChannel('com.cake_wallet/native_utils');
7
8 Future<void> setDefaultMinimumWindowSize() async {
9 if (!Platform.isMacOS) return;
10
11 try {
12 // A small delay to confirm that our native platform channels are ready
13 await Future.delayed(const Duration(milliseconds: 200));
14
15 final result = await _channel.invokeMethod(
16 'setMinWindowSize',
17 {'width': 500, 'height': 700},
18 ) as bool;
19
20 if (!result) {
21 printV("Failed to set minimum window size.");
22 }
23 } on PlatformException catch (e) {
24 printV("Failed to set minimum window size: '${e.message}'.");
25 } on MissingPluginException catch (e) {
26 printV("Native utils plugin not available yet: '${e.message}'. Retrying...");
27 // We give it a longer delay this time around, and then retry
28 await Future.delayed(const Duration(milliseconds: 500));
29 try {
30 final result = await _channel.invokeMethod(
31 'setMinWindowSize',
32 {'width': 500, 'height': 700},
33 ) as bool;
34
35 if (!result) {
36 printV("Failed to set minimum window size on retry.");
37 }
38 } catch (retryError) {
39 printV("Failed to set minimum window size after retry: '$retryError'.");
40 }
41 }
42 }