Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion commet/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
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
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<void> onBackgroundMessage(Map<String, dynamic> message) async {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -186,4 +185,6 @@ class UnifiedPushNotifier implements Notifier {
// TODO: implement enableBadges
throw UnimplementedError();
}


}
5 changes: 5 additions & 0 deletions commet/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ void main(List<String> args) async {
commandLineArgs = args;
print(args);

if(args.contains("--unifiedpush-bg")) {
unifiedPushEntry();
return;
}

if (runWebViewTitleBarWidget(args)) {
return;
}
Expand Down
51 changes: 34 additions & 17 deletions commet/lib/ui/pages/setup/menus/unified_push_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,27 +52,34 @@ class UnifiedPushSetupViewState extends State<UnifiedPushSetupView> {

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() {
Expand Down Expand Up @@ -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(),
),
],
);
}
Expand All @@ -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!,
),
],
),
);
Expand All @@ -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(() {
Expand Down
29 changes: 17 additions & 12 deletions commet/lib/utils/database/multiple_database_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
});
Expand All @@ -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<void> start() async {
Log.i("Starting database server: $isolateName");

connectToServer = IsolateNameServer.lookupPortByName(isolateName);
if (connectToServer == null) {
Isolate.spawn(
Expand All @@ -74,8 +77,10 @@ class DatabaseIsolate {
}
}

static Future<DatabaseConnection> connect(String databaseName,
{bool readOnly = false}) async {
static Future<DatabaseConnection> connect(
String databaseName, {
bool readOnly = false,
}) async {
if (connectToServer == null) {
await start();
}
Expand Down
Loading