Skip to content

Commit 5031b18

Browse files
committed
refactor: use window_manager for close handling on Linux
A fix was merged that makes it work on Linux. See: leanflutter/window_manager#343
1 parent 0df782a commit 5031b18

5 files changed

Lines changed: 15 additions & 38 deletions

File tree

lib/app.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class _AppState extends State<App> with TrayListener, WindowListener {
3636

3737
@override
3838
void onWindowClose() {
39-
/// Only working on Windows for some reason.
40-
/// Linux will use `flutter_window_close` instead.
4139
if (settingsCubit.state.closeToTray) {
4240
AppWindow.instance.hide();
4341
return;

lib/main.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ Future<void> main(List<String> args) async {
5959
exit(0);
6060
} else {}
6161

62-
final appWindow = AppWindow(storage);
63-
6462
final hotkeyService = HotkeyService(activeWindow);
6563

64+
final appWindow = AppWindow(storage);
65+
appWindow.initialize();
66+
6667
final settingsCubit = await SettingsCubit.init(
6768
autostartService: AutostartService(),
6869
hotkeyService: hotkeyService,
@@ -107,8 +108,4 @@ Future<void> main(List<String> args) async {
107108
child: const App(),
108109
),
109110
);
110-
111-
final bool? startHiddenInTray = await storage.getValue('startHiddenInTray');
112-
113-
if (startHiddenInTray != true) await appWindow.show();
114111
}

lib/window/app_window.dart

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import 'dart:io';
22
import 'dart:ui';
33

4-
import 'package:flutter_window_close/flutter_window_close.dart';
54
import 'package:window_manager/window_manager.dart';
65

76
import '../core/helpers/json_converters.dart';
87
import '../logs/logs.dart';
9-
import '../settings/settings.dart';
108
import '../storage/storage_repository.dart';
119

1210
/// Represents the main window of the app.
@@ -17,23 +15,16 @@ class AppWindow {
1715

1816
AppWindow(this._storage) {
1917
instance = this;
20-
_listenForWindowClose();
2118
}
2219

23-
void _listenForWindowClose() {
24-
if (!Platform.isLinux) return;
20+
void initialize() {
21+
windowManager.waitUntilReadyToShow().then((_) async {
22+
final bool? startHiddenInTray =
23+
await _storage.getValue('startHiddenInTray');
2524

26-
/// For now using `flutter_window_close` on Linux, because the
27-
/// `onWindowClose` from `window_manager` is only working on Windows for
28-
/// some reason. Probably best to switch to only using `window_manager` if
29-
/// it starts also working on Linux in the future.
30-
FlutterWindowClose.setWindowShouldCloseHandler(() async {
31-
await hide();
32-
final shouldExitProgram = (settingsCubit.state.closeToTray) //
33-
? false
34-
: true;
35-
36-
return shouldExitProgram;
25+
if (startHiddenInTray != true) {
26+
await show();
27+
}
3728
});
3829
}
3930

pubspec.lock

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,10 @@ packages:
293293
dependency: "direct main"
294294
description:
295295
name: flutter_markdown
296-
sha256: "9e0202b5339cd88ac0f109abae8502681bfab0b13a8e02a0e7158124610b5d98"
296+
sha256: "86b76dbf30496024d6c816bdc13b97de9449dce1f035a73ee7b4ab7f67eab70b"
297297
url: "https://pub.dev"
298298
source: hosted
299-
version: "0.6.15+1"
299+
version: "0.6.16"
300300
flutter_svg:
301301
dependency: transitive
302302
description:
@@ -315,14 +315,6 @@ packages:
315315
description: flutter
316316
source: sdk
317317
version: "0.0.0"
318-
flutter_window_close:
319-
dependency: "direct main"
320-
description:
321-
name: flutter_window_close
322-
sha256: "63f5846efbf0974ec233e6b5f468aa604a4857157f4c6c44fd482621804a0464"
323-
url: "https://pub.dev"
324-
source: hosted
325-
version: "0.2.2"
326318
freezed:
327319
dependency: "direct dev"
328320
description:
@@ -1152,10 +1144,10 @@ packages:
11521144
dependency: "direct main"
11531145
description:
11541146
name: window_manager
1155-
sha256: "95096fede562cbb65f30d38b62d819a458f59ba9fe4a317f6cee669710f6676b"
1147+
sha256: "9eef00e393e7f9308309ce9a8b2398c9ee3ca78b50c96e8b4f9873945693ac88"
11561148
url: "https://pub.dev"
11571149
source: hosted
1158-
version: "0.3.4"
1150+
version: "0.3.5"
11591151
window_size:
11601152
dependency: "direct main"
11611153
description:

pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ dependencies:
1616
flutter_localizations:
1717
sdk: flutter
1818
flutter_markdown: ^0.6.9+1
19-
flutter_window_close: ^0.2.2
2019
freezed_annotation: ^2.2.0
2120
helpers:
2221
git:
@@ -43,7 +42,7 @@ dependencies:
4342
url_launcher: ^6.0.4
4443
win32: ^5.0.5
4544
win32_suspend_process: ^1.1.0
46-
window_manager: ^0.3.0
45+
window_manager: ^0.3.5
4746
window_size:
4847
git:
4948
url: https://github.com/google/flutter-desktop-embedding.git

0 commit comments

Comments
 (0)