diff --git a/lib/app.dart b/lib/app.dart index e1838c6e..96eb557a 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -36,8 +36,6 @@ class _AppState extends State with TrayListener, WindowListener { @override void onWindowClose() { - /// Only working on Windows for some reason. - /// Linux will use `flutter_window_close` instead. if (settingsCubit.state.closeToTray) { AppWindow.instance.hide(); return; diff --git a/lib/main.dart b/lib/main.dart index f7f112d2..60291fd9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -59,10 +59,11 @@ Future main(List args) async { exit(0); } else {} - final appWindow = AppWindow(storage); - final hotkeyService = HotkeyService(activeWindow); + final appWindow = AppWindow(storage); + appWindow.initialize(); + final settingsCubit = await SettingsCubit.init( autostartService: AutostartService(), hotkeyService: hotkeyService, @@ -107,8 +108,4 @@ Future main(List args) async { child: const App(), ), ); - - final bool? startHiddenInTray = await storage.getValue('startHiddenInTray'); - - if (startHiddenInTray != true) await appWindow.show(); } diff --git a/lib/window/app_window.dart b/lib/window/app_window.dart index 2eb30b54..47920e3f 100644 --- a/lib/window/app_window.dart +++ b/lib/window/app_window.dart @@ -1,12 +1,10 @@ import 'dart:io'; import 'dart:ui'; -import 'package:flutter_window_close/flutter_window_close.dart'; import 'package:window_manager/window_manager.dart'; import '../core/helpers/json_converters.dart'; import '../logs/logs.dart'; -import '../settings/settings.dart'; import '../storage/storage_repository.dart'; /// Represents the main window of the app. @@ -17,23 +15,16 @@ class AppWindow { AppWindow(this._storage) { instance = this; - _listenForWindowClose(); } - void _listenForWindowClose() { - if (!Platform.isLinux) return; + void initialize() { + windowManager.waitUntilReadyToShow().then((_) async { + final bool? startHiddenInTray = + await _storage.getValue('startHiddenInTray'); - /// For now using `flutter_window_close` on Linux, because the - /// `onWindowClose` from `window_manager` is only working on Windows for - /// some reason. Probably best to switch to only using `window_manager` if - /// it starts also working on Linux in the future. - FlutterWindowClose.setWindowShouldCloseHandler(() async { - await hide(); - final shouldExitProgram = (settingsCubit.state.closeToTray) // - ? false - : true; - - return shouldExitProgram; + if (startHiddenInTray != true) { + await show(); + } }); } diff --git a/pubspec.lock b/pubspec.lock index ff518404..5176e0c9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -293,10 +293,10 @@ packages: dependency: "direct main" description: name: flutter_markdown - sha256: "9e0202b5339cd88ac0f109abae8502681bfab0b13a8e02a0e7158124610b5d98" + sha256: "86b76dbf30496024d6c816bdc13b97de9449dce1f035a73ee7b4ab7f67eab70b" url: "https://pub.dev" source: hosted - version: "0.6.15+1" + version: "0.6.16" flutter_svg: dependency: transitive description: @@ -315,14 +315,6 @@ packages: description: flutter source: sdk version: "0.0.0" - flutter_window_close: - dependency: "direct main" - description: - name: flutter_window_close - sha256: "63f5846efbf0974ec233e6b5f468aa604a4857157f4c6c44fd482621804a0464" - url: "https://pub.dev" - source: hosted - version: "0.2.2" freezed: dependency: "direct dev" description: @@ -1152,10 +1144,10 @@ packages: dependency: "direct main" description: name: window_manager - sha256: "95096fede562cbb65f30d38b62d819a458f59ba9fe4a317f6cee669710f6676b" + sha256: "9eef00e393e7f9308309ce9a8b2398c9ee3ca78b50c96e8b4f9873945693ac88" url: "https://pub.dev" source: hosted - version: "0.3.4" + version: "0.3.5" window_size: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 20b01450..eca732c4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,6 @@ dependencies: flutter_localizations: sdk: flutter flutter_markdown: ^0.6.9+1 - flutter_window_close: ^0.2.2 freezed_annotation: ^2.2.0 helpers: git: @@ -43,7 +42,7 @@ dependencies: url_launcher: ^6.0.4 win32: ^5.0.5 win32_suspend_process: ^1.1.0 - window_manager: ^0.3.0 + window_manager: ^0.3.5 window_size: git: url: https://github.com/google/flutter-desktop-embedding.git