diff --git a/lib/controllers/client.dart b/lib/controllers/client.dart index 782e4a7..20a3954 100644 --- a/lib/controllers/client.dart +++ b/lib/controllers/client.dart @@ -1,3 +1,4 @@ +import "dart:async"; import "dart:ffi"; import "dart:io"; import "dart:isolate"; @@ -156,18 +157,15 @@ class ClientController extends AsyncNotifier { throw Exception("GomuksStart returned error code $errorCode"); } - Future _sendCommand( - String command, [ - Map data = const {}, - ]) async { + Future callGomuksMethod( + Map data, + FutureOr Function(int handle, GomuksBorrowedBuffer data) + callback, + ) async { final bufferPointer = data.toGomuksBufferPtr(); final handle = await future; final response = await Isolate.run( - () => GomuksSubmitCommand( - handle, - command.toNativeUtf8().cast(), - bufferPointer.ref, - ), + () => callback(handle, bufferPointer.ref), ); calloc.free(bufferPointer); @@ -180,6 +178,22 @@ class ClientController extends AsyncNotifier { return json; } + Future handlePush(Map data) async => .fromJson( + await callGomuksMethod( + data, + (handle, data) async => GomuksHandlePush(handle, data), + ), + ); + + Future _sendCommand( + String command, [ + Map data = const {}, + ]) => callGomuksMethod( + data, + (handle, data) async => + GomuksSubmitCommand(handle, command.toNativeUtf8().cast(), data), + ); + Future redactEvent(RedactEventRequest report) => _sendCommand("redact_event", report.toJson()); diff --git a/lib/controllers/unified_push.dart b/lib/controllers/unified_push.dart index 0e7d1aa..bfa0ad1 100644 --- a/lib/controllers/unified_push.dart +++ b/lib/controllers/unified_push.dart @@ -1,3 +1,4 @@ +import "dart:convert"; import "dart:io"; import "package:flutter_riverpod/flutter_riverpod.dart"; @@ -12,6 +13,7 @@ import "package:unifiedpush_storage_shared_preferences/storage.dart"; class UnifiedPushController extends AsyncNotifier { @override Future build() async { + final client = ref.watch(ClientController.provider.notifier); final registered = await UnifiedPush.initialize( linuxOptions: .new( dbusName: "nexus.federated.nexus.UnifiedPush", @@ -19,7 +21,6 @@ class UnifiedPushController extends AsyncNotifier { background: isInBackground, ), onNewEndpoint: (endpoint, instance) async { - final client = ref.watch(ClientController.provider.notifier); await client.registerPusher( .new( appDisplayName: "Nexus", @@ -37,16 +38,16 @@ class UnifiedPushController extends AsyncNotifier { ); }, onMessage: (message, instance) async { - print(message); - // TODO: Handle incoming message + final e = await client.handlePush( + json.decode(String.fromCharCodes(message.content)), + ); + print(e); }, onRegistrationFailed: (e, r) { throw "e"; }, - onUnregistered: (_) { - throw "r"; - }, - onTempUnavailable: (_) { + onUnregistered: (instance) => ref.invalidateSelf(), + onTempUnavailable: (instance) { throw "t"; }, ); diff --git a/lib/main.dart b/lib/main.dart index 7b2aa63..2221151 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -47,6 +47,7 @@ void showError(Object error, [StackTrace? stackTrace]) { error.toString().contains("Invalid source") || error.toString().contains("UTF-16") || error.toString().contains("HTTP request failed") || + error.toString().contains("'_nextFrame != null': is not true.") || error.toString().contains("Invalid image data")) { return; } diff --git a/pubspec.lock b/pubspec.lock index 2c6ba10..ff25956 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1734,7 +1734,7 @@ packages: source: hosted version: "3.0.3" webcrypto: - dependency: "direct main" + dependency: "direct dev" description: name: webcrypto sha256: "6b43001c4110856ff7fa5e5e65e7b2d44bec1d8b54a4d84d5fa2c7622267c5c1"