From 2377098d015c07a8cabc61e71aee0f80de067d5d Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Fri, 25 Oct 2024 23:48:30 +0200 Subject: [PATCH] applied workaround for macos https://github.com/pichillilorenzo/window_manager_plus/issues/5 --- .gitignore | 2 ++ lib/main.dart | 23 +++++++++++++++++++++++ pubspec.lock | 4 ++-- pubspec.yaml | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 56d114e..5ffe38a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/lib/main.dart b/lib/main.dart index 60954ac..3914629 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,9 @@ +import 'dart:io'; + import 'package:context_menus/context_menus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; import 'package:flutter_browser/models/browser_model.dart'; import 'package:flutter_browser/models/webview_model.dart'; import 'package:flutter_browser/models/window_model.dart'; @@ -146,15 +149,35 @@ class FlutterBrowserApp extends StatefulWidget { class _FlutterBrowserAppState extends State with WindowListener { + + // https://github.com/pichillilorenzo/window_manager_plus/issues/5 + late final AppLifecycleListener? _appLifecycleListener; + @override void initState() { super.initState(); WindowManagerPlus.current.addListener(this); + + // https://github.com/pichillilorenzo/window_manager_plus/issues/5 + if (WindowManagerPlus.current.id > 0 && Platform.isMacOS) { + _appLifecycleListener = AppLifecycleListener( + onStateChange: _handleStateChange, + ); + } + } + + void _handleStateChange(AppLifecycleState state) { + // https://github.com/pichillilorenzo/window_manager_plus/issues/5 + if (WindowManagerPlus.current.id > 0 && Platform.isMacOS && state == AppLifecycleState.hidden) { + SchedulerBinding.instance.handleAppLifecycleStateChanged( + AppLifecycleState.inactive); + } } @override void dispose() { WindowManagerPlus.current.removeListener(this); + _appLifecycleListener?.dispose(); super.dispose(); } diff --git a/pubspec.lock b/pubspec.lock index 920c9dc..80b1d6f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -913,10 +913,10 @@ packages: dependency: "direct main" description: name: window_manager_plus - sha256: b090f178c6c4066a37415ec82eb24315280bf0ca0b3f53a500a66cd2897545d3 + sha256: c3a7e030fb7f61a0e04db8c49b24c43affaaf5fbff5da375d5bb822a7e01b9f0 url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "1.0.5" xdg_directories: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 85b4c61..a12580c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -64,7 +64,7 @@ dependencies: sqflite: ^2.3.3+2 sqflite_common_ffi: ^2.3.3+1 sqlite3_flutter_libs: ^0.5.24 - window_manager_plus: ^1.0.4 + window_manager_plus: ^1.0.5 path: any dev_dependencies: