From c6007a3c3d5dc17e11b88f8f700a0358ad9952d1 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Mon, 27 Nov 2023 17:26:05 +0100 Subject: [PATCH] refactor: Check if app is in foreground on pushhelper --- lib/utils/push_helper.dart | 4 +--- lib/widgets/local_notifications_extension.dart | 5 +++-- linux/flutter/generated_plugin_registrant.cc | 4 ---- linux/flutter/generated_plugins.cmake | 1 - macos/Flutter/GeneratedPluginRegistrant.swift | 2 -- pubspec.lock | 8 -------- pubspec.yaml | 1 - windows/flutter/generated_plugin_registrant.cc | 3 --- windows/flutter/generated_plugins.cmake | 1 - 9 files changed, 4 insertions(+), 25 deletions(-) diff --git a/lib/utils/push_helper.dart b/lib/utils/push_helper.dart index e96a250d6..8fd50910c 100644 --- a/lib/utils/push_helper.dart +++ b/lib/utils/push_helper.dart @@ -81,10 +81,8 @@ Future _tryPushHelper( notification.toJson(), ); - if (!isBackgroundMessage && + if (notification.roomId != null && activeRoomId == notification.roomId && - activeRoomId != null && - client.syncPresence == null && WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed) { Logs().v('Room is in foreground. Stop push helper here.'); return; diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index 44754030c..c288f0530 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -2,8 +2,8 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; -import 'package:desktop_lifecycle/desktop_lifecycle.dart'; import 'package:desktop_notifications/desktop_notifications.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:go_router/go_router.dart'; import 'package:http/http.dart' as http; @@ -25,7 +25,8 @@ extension LocalNotificationsExtension on MatrixState { final roomId = eventUpdate.roomID; if (activeRoomId == roomId) { if (kIsWeb && webHasFocus) return; - if (PlatformInfos.isLinux && DesktopLifecycle.instance.isActive.value) { + if (PlatformInfos.isDesktop && + WidgetsBinding.instance.lifecycleState == AppLifecycleState.resumed) { return; } } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 6af12d051..85ffd18ff 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -7,7 +7,6 @@ #include "generated_plugin_registrant.h" #include -#include #include #include #include @@ -22,9 +21,6 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) desktop_drop_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopDropPlugin"); desktop_drop_plugin_register_with_registrar(desktop_drop_registrar); - g_autoptr(FlPluginRegistrar) desktop_lifecycle_registrar = - fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopLifecyclePlugin"); - desktop_lifecycle_plugin_register_with_registrar(desktop_lifecycle_registrar); g_autoptr(FlPluginRegistrar) dynamic_color_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin"); dynamic_color_plugin_register_with_registrar(dynamic_color_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index d24b1b225..e791eb7ae 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -4,7 +4,6 @@ list(APPEND FLUTTER_PLUGIN_LIST desktop_drop - desktop_lifecycle dynamic_color emoji_picker_flutter file_selector_linux diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index c82b30e88..a7420ec9a 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -8,7 +8,6 @@ import Foundation import appkit_ui_element_colors import audio_session import desktop_drop -import desktop_lifecycle import device_info_plus import dynamic_color import emoji_picker_flutter @@ -39,7 +38,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { AppkitUiElementColorsPlugin.register(with: registry.registrar(forPlugin: "AppkitUiElementColorsPlugin")) AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) DesktopDropPlugin.register(with: registry.registrar(forPlugin: "DesktopDropPlugin")) - DesktopLifecyclePlugin.register(with: registry.registrar(forPlugin: "DesktopLifecyclePlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin")) EmojiPickerFlutterPlugin.register(with: registry.registrar(forPlugin: "EmojiPickerFlutterPlugin")) diff --git a/pubspec.lock b/pubspec.lock index b7f793e18..896e4f0eb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -305,14 +305,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.4" - desktop_lifecycle: - dependency: "direct main" - description: - name: desktop_lifecycle - sha256: "221c0d1fd6582bbc28bd03f186983682d998459f3e8efde0105324a8ab350040" - url: "https://pub.dev" - source: hosted - version: "0.1.1" desktop_notifications: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 9bec4d6ae..d47744f2e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,6 @@ dependencies: collection: ^1.17.2 cupertino_icons: any desktop_drop: ^0.4.4 - desktop_lifecycle: ^0.1.0 desktop_notifications: ^0.6.3 device_info_plus: ^9.1.0 dynamic_color: ^1.6.8 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index c56ef092b..f3aa99546 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,7 +7,6 @@ #include "generated_plugin_registrant.h" #include -#include #include #include #include @@ -23,8 +22,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { DesktopDropPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("DesktopDropPlugin")); - DesktopLifecyclePluginRegisterWithRegistrar( - registry->GetRegistrarForPlugin("DesktopLifecyclePlugin")); DynamicColorPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("DynamicColorPluginCApi")); EmojiPickerFlutterPluginCApiRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 27cc5bc0d..69d3cc36e 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,7 +4,6 @@ list(APPEND FLUTTER_PLUGIN_LIST desktop_drop - desktop_lifecycle dynamic_color emoji_picker_flutter file_selector_windows