fix: Linux notification not showing when room is open but window in background

This commit is contained in:
Krille Fear 2022-02-18 20:33:36 +01:00
parent df98254640
commit 2a9fde6b35
7 changed files with 22 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:desktop_lifecycle/desktop_lifecycle.dart';
import 'package:desktop_notifications/desktop_notifications.dart'; import 'package:desktop_notifications/desktop_notifications.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
@ -17,7 +18,10 @@ import 'package:fluffychat/widgets/matrix.dart';
extension LocalNotificationsExtension on MatrixState { extension LocalNotificationsExtension on MatrixState {
void showLocalNotification(EventUpdate eventUpdate) async { void showLocalNotification(EventUpdate eventUpdate) async {
final roomId = eventUpdate.roomID; final roomId = eventUpdate.roomID;
if (webHasFocus && activeRoomId == roomId) return; if (activeRoomId == roomId) {
if (kIsWeb && webHasFocus) return;
if (Platform.isLinux && DesktopLifecycle.instance.isActive.value) return;
}
final room = client.getRoomById(roomId); final room = client.getRoomById(roomId);
if (room == null) { if (room == null) {
Logs().w('Can not display notification for unknown room $roomId'); Logs().w('Can not display notification for unknown room $roomId');

View File

@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <desktop_drop/desktop_drop_plugin.h> #include <desktop_drop/desktop_drop_plugin.h>
#include <desktop_lifecycle/desktop_lifecycle_plugin.h>
#include <file_selector_linux/file_selector_plugin.h> #include <file_selector_linux/file_selector_plugin.h>
#include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h> #include <flutter_secure_storage_linux/flutter_secure_storage_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h> #include <url_launcher_linux/url_launcher_plugin.h>
@ -15,6 +16,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) desktop_drop_registrar = g_autoptr(FlPluginRegistrar) desktop_drop_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopDropPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopDropPlugin");
desktop_drop_plugin_register_with_registrar(desktop_drop_registrar); 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) file_selector_linux_registrar = g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar); file_selector_plugin_register_with_registrar(file_selector_linux_registrar);

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
desktop_drop desktop_drop
desktop_lifecycle
file_selector_linux file_selector_linux
flutter_secure_storage_linux flutter_secure_storage_linux
url_launcher_linux url_launcher_linux

View File

@ -316,6 +316,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.3.2" version: "0.3.2"
desktop_lifecycle:
dependency: "direct main"
description:
name: desktop_lifecycle
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
desktop_notifications: desktop_notifications:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -20,6 +20,7 @@ dependencies:
connectivity_plus: ^2.2.0 connectivity_plus: ^2.2.0
cupertino_icons: any cupertino_icons: any
desktop_drop: ^0.3.2 desktop_drop: ^0.3.2
desktop_lifecycle: ^0.1.0
desktop_notifications: ^0.6.3 desktop_notifications: ^0.6.3
device_info_plus: ^3.2.1 device_info_plus: ^3.2.1
email_validator: ^2.0.1 email_validator: ^2.0.1

View File

@ -8,6 +8,7 @@
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h> #include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
#include <desktop_drop/desktop_drop_plugin.h> #include <desktop_drop/desktop_drop_plugin.h>
#include <desktop_lifecycle/desktop_lifecycle_plugin.h>
#include <file_selector_windows/file_selector_plugin.h> #include <file_selector_windows/file_selector_plugin.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h> #include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <flutter_webrtc/flutter_web_r_t_c_plugin.h> #include <flutter_webrtc/flutter_web_r_t_c_plugin.h>
@ -18,6 +19,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
DesktopDropPluginRegisterWithRegistrar( DesktopDropPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DesktopDropPlugin")); registry->GetRegistrarForPlugin("DesktopDropPlugin"));
DesktopLifecyclePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DesktopLifecyclePlugin"));
FileSelectorPluginRegisterWithRegistrar( FileSelectorPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorPlugin")); registry->GetRegistrarForPlugin("FileSelectorPlugin"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar( FlutterSecureStorageWindowsPluginRegisterWithRegistrar(

View File

@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus_windows connectivity_plus_windows
desktop_drop desktop_drop
desktop_lifecycle
file_selector_windows file_selector_windows
flutter_secure_storage_windows flutter_secure_storage_windows
flutter_webrtc flutter_webrtc