Skip to content

Commit

Permalink
applied workaround for macos pichillilorenzo/window_manager_plus#5
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Oct 25, 2024
1 parent 0a2c6c2 commit 2377098
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
Expand Down
23 changes: 23 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -146,15 +149,35 @@ class FlutterBrowserApp extends StatefulWidget {

class _FlutterBrowserAppState extends State<FlutterBrowserApp>
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();
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2377098

Please sign in to comment.