From f7848a78e1ff929a171872d72e78bfb6cdbe5f59 Mon Sep 17 00:00:00 2001 From: Airyzz <36567925+Airyzz@users.noreply.github.com> Date: Sat, 7 Nov 2026 12:47:31 +1030 Subject: [PATCH] fix unified push --- commet/android/gradle.properties | 6 ++- .../android/unified_push_notifier.dart | 15 +++--- commet/lib/main.dart | 5 ++ .../pages/setup/menus/unified_push_setup.dart | 51 ++++++++++++------- .../database/multiple_database_server.dart | 29 ++++++----- 5 files changed, 69 insertions(+), 37 deletions(-) diff --git a/commet/android/gradle.properties b/commet/android/gradle.properties index 69b9df9f3..a0c603945 100644 --- a/commet/android/gradle.properties +++ b/commet/android/gradle.properties @@ -1,4 +1,8 @@ org.gradle.jvmargs=-Xmx4608m android.useAndroidX=true android.enableJetifier=true -org.gradle.java.installations.fromEnv=JAVA_8_HOME,JAVA_17_HOME \ No newline at end of file +org.gradle.java.installations.fromEnv=JAVA_8_HOME,JAVA_17_HOME +# This builtInKotlin flag was added automatically by Flutter migrator +android.builtInKotlin=false +# This newDsl flag was added automatically by Flutter migrator +android.newDsl=false diff --git a/commet/lib/client/components/push_notification/android/unified_push_notifier.dart b/commet/lib/client/components/push_notification/android/unified_push_notifier.dart index 7e891ed9f..aeda150dc 100644 --- a/commet/lib/client/components/push_notification/android/unified_push_notifier.dart +++ b/commet/lib/client/components/push_notification/android/unified_push_notifier.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:typed_data'; import 'package:commet/client/client.dart'; import 'package:commet/client/components/push_notification/android/android_notifier.dart'; @@ -56,7 +55,7 @@ class UnifiedPushNotifier implements Notifier { await notifier.init(); Log.i("Initializing unified push"); - // UnifiedPush.initialize(onMessage: onMessage, onNewEndpoint: onNewEndpoint); + UnifiedPush.initialize(onMessage: onMessage, onNewEndpoint: onNewEndpoint); isInit = true; } @@ -80,11 +79,11 @@ class UnifiedPushNotifier implements Notifier { return notifier.requestPermission(); } - void onNewEndpoint(String endpoint, String instance) async { + void onNewEndpoint(PushEndpoint endpoint, String instance) async { print("Got new endpoint: $instance"); - await preferences.unifiedPushEndpoint.set(endpoint); + await preferences.unifiedPushEndpoint.set(endpoint.url); await PushNotificationComponent.updateAllPushers(); - onEndpointChanged.add(endpoint); + onEndpointChanged.add(endpoint.url); } Future onBackgroundMessage(Map message) async { @@ -120,9 +119,9 @@ class UnifiedPushNotifier implements Notifier { } } - void onMessage(Uint8List message, String instance) async { + void onMessage(PushMessage message, String instance) async { Log.i("Received unified push message! $instance"); - var data = utf8.decode(message); + var data = utf8.decode(message.content); EventBus.onReceivedPushNotificationData.add(data); @@ -186,4 +185,6 @@ class UnifiedPushNotifier implements Notifier { // TODO: implement enableBadges throw UnimplementedError(); } + + } diff --git a/commet/lib/main.dart b/commet/lib/main.dart index 4827ad67b..786d05a1d 100644 --- a/commet/lib/main.dart +++ b/commet/lib/main.dart @@ -135,6 +135,11 @@ void main(List args) async { commandLineArgs = args; print(args); + if(args.contains("--unifiedpush-bg")) { + unifiedPushEntry(); + return; + } + if (runWebViewTitleBarWidget(args)) { return; } diff --git a/commet/lib/ui/pages/setup/menus/unified_push_setup.dart b/commet/lib/ui/pages/setup/menus/unified_push_setup.dart index c5eaac431..be7c5eea3 100644 --- a/commet/lib/ui/pages/setup/menus/unified_push_setup.dart +++ b/commet/lib/ui/pages/setup/menus/unified_push_setup.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:commet/client/components/push_notification/android/unified_push_notifier.dart'; import 'package:commet/client/components/push_notification/notification_manager.dart'; +import 'package:commet/debug/log.dart'; import 'package:commet/main.dart'; import 'package:commet/ui/pages/setup/setup_menu.dart'; import 'package:flutter/material.dart'; @@ -51,27 +52,34 @@ class UnifiedPushSetupViewState extends State { String? endpoint; - String get unifiedPushExplainer => Intl.message(""" + String get unifiedPushExplainer => Intl.message( + """ # Unified Push This version of Commet was built without Google Play Services. In order to receive push notifications, you will need to use [Unified Push](https://unifiedpush.org/). If you already have a Unified Push compatible distributor app installed, you can configure it below """, - name: "unifiedPushExplainer", - desc: "Explains the need for unified push. Supports markdown"); - - String get labelEnableUnifiedPush => Intl.message("Enable Unified Push", - name: "labelEnableUnifiedPush", - desc: "Label for the toggle to enable Unified Push"); - - String get labelEnableUnifiedPushEndpoint => Intl.message("Endpoint", - name: "labelEnableUnifiedPushEndpoint", - desc: "Label for the Unified Push endpoint"); + name: "unifiedPushExplainer", + desc: "Explains the need for unified push. Supports markdown", + ); + + String get labelEnableUnifiedPush => Intl.message( + "Enable Unified Push", + name: "labelEnableUnifiedPush", + desc: "Label for the toggle to enable Unified Push", + ); + + String get labelEnableUnifiedPushEndpoint => Intl.message( + "Endpoint", + name: "labelEnableUnifiedPushEndpoint", + desc: "Label for the Unified Push endpoint", + ); String get labelUnifiedPushNoEndpointFound => Intl.message( - "No endpoint found, something went wrong :(", - name: "labelUnifiedPushNoEndpointFound", - desc: "Message for when a unified push endpoint could not be registered"); + "No endpoint found, something went wrong :(", + name: "labelUnifiedPushNoEndpointFound", + desc: "Message for when a unified push endpoint could not be registered", + ); @override void initState() { @@ -128,7 +136,9 @@ If you already have a Unified Push compatible distributor app installed, you can ), if (unifiedPushEnabled) Align( - alignment: Alignment.centerLeft, child: buildUnifiedPushDetails()) + alignment: Alignment.centerLeft, + child: buildUnifiedPushDetails(), + ), ], ); } @@ -145,7 +155,8 @@ If you already have a Unified Push compatible distributor app installed, you can children: [ tiamat.Text.label(labelEnableUnifiedPushEndpoint + ":"), tiamat.Text.labelLow( - endpoint == null ? labelUnifiedPushNoEndpointFound : endpoint!), + endpoint == null ? labelUnifiedPushNoEndpointFound : endpoint!, + ), ], ), ); @@ -162,7 +173,13 @@ If you already have a Unified Push compatible distributor app installed, you can await notifier?.init(); if (mounted) { - // UnifiedPush.registerAppWithDialog(context); + UnifiedPush.tryUseCurrentOrDefaultDistributor().then((success) { + if(success) { + UnifiedPush.register(); + } else { + Log.w("Failed to register unified push"); + } + }); } setState(() { diff --git a/commet/lib/utils/database/multiple_database_server.dart b/commet/lib/utils/database/multiple_database_server.dart index 1bc02a2e2..2ef4cd3b9 100644 --- a/commet/lib/utils/database/multiple_database_server.dart +++ b/commet/lib/utils/database/multiple_database_server.dart @@ -4,6 +4,7 @@ import 'dart:ui'; import 'package:commet/client/matrix/database/matrix_database_io.dart'; import 'package:commet/debug/log.dart'; +import 'package:commet/main.dart'; import 'package:drift/drift.dart'; import 'package:drift/isolate.dart'; @@ -37,15 +38,13 @@ final class MultiDatabaseServer { return; } - final isolate = _activeIsolates.putIfAbsent( - name, - () { - return DriftIsolate.inCurrent( - serialize: true, - // obviously you can pass a path instead of a name and use that to open the right NativeDatabase - () => setupNativeDatabase(File(name), readOnly: readOnly)); - }, - ); + final isolate = _activeIsolates.putIfAbsent(name, () { + return DriftIsolate.inCurrent( + serialize: true, + // obviously you can pass a path instead of a name and use that to open the right NativeDatabase + () => setupNativeDatabase(File(name), readOnly: readOnly), + ); + }); port.send(isolate.connectPort); }); @@ -55,9 +54,13 @@ final class MultiDatabaseServer { class DatabaseIsolate { static final receiveConnectPort = ReceivePort(); static SendPort? connectToServer; - static const isolateName = "chat.commet.commetapp.database_isolate"; + static String get isolateName => isHeadless + ? "chat.commet.commetapp.database_isolate.background_worker" + : "chat.commet.commetapp.database_isolate"; static Future start() async { + Log.i("Starting database server: $isolateName"); + connectToServer = IsolateNameServer.lookupPortByName(isolateName); if (connectToServer == null) { Isolate.spawn( @@ -74,8 +77,10 @@ class DatabaseIsolate { } } - static Future connect(String databaseName, - {bool readOnly = false}) async { + static Future connect( + String databaseName, { + bool readOnly = false, + }) async { if (connectToServer == null) { await start(); }