pass pushes to gomuks

This commit is contained in:
Henry Hiles 2026-08-25 19:51:43 -04:00
commit 02704e97ef
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
4 changed files with 33 additions and 17 deletions

View file

@ -1,3 +1,4 @@
import "dart:async";
import "dart:ffi"; import "dart:ffi";
import "dart:io"; import "dart:io";
import "dart:isolate"; import "dart:isolate";
@ -156,18 +157,15 @@ class ClientController extends AsyncNotifier<int> {
throw Exception("GomuksStart returned error code $errorCode"); throw Exception("GomuksStart returned error code $errorCode");
} }
Future<dynamic> _sendCommand( Future<dynamic> callGomuksMethod(
String command, [ Map<String, dynamic> data,
Map<String, dynamic> data = const {}, FutureOr<GomuksResponse> Function(int handle, GomuksBorrowedBuffer data)
]) async { callback,
) async {
final bufferPointer = data.toGomuksBufferPtr(); final bufferPointer = data.toGomuksBufferPtr();
final handle = await future; final handle = await future;
final response = await Isolate.run( final response = await Isolate.run(
() => GomuksSubmitCommand( () => callback(handle, bufferPointer.ref),
handle,
command.toNativeUtf8().cast<Char>(),
bufferPointer.ref,
),
); );
calloc.free(bufferPointer); calloc.free(bufferPointer);
@ -180,6 +178,22 @@ class ClientController extends AsyncNotifier<int> {
return json; return json;
} }
Future<Event> handlePush(Map<String, dynamic> data) async => .fromJson(
await callGomuksMethod(
data,
(handle, data) async => GomuksHandlePush(handle, data),
),
);
Future<dynamic> _sendCommand(
String command, [
Map<String, dynamic> data = const {},
]) => callGomuksMethod(
data,
(handle, data) async =>
GomuksSubmitCommand(handle, command.toNativeUtf8().cast<Char>(), data),
);
Future<void> redactEvent(RedactEventRequest report) => Future<void> redactEvent(RedactEventRequest report) =>
_sendCommand("redact_event", report.toJson()); _sendCommand("redact_event", report.toJson());

View file

@ -1,3 +1,4 @@
import "dart:convert";
import "dart:io"; import "dart:io";
import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:flutter_riverpod/flutter_riverpod.dart";
@ -12,6 +13,7 @@ import "package:unifiedpush_storage_shared_preferences/storage.dart";
class UnifiedPushController extends AsyncNotifier<bool> { class UnifiedPushController extends AsyncNotifier<bool> {
@override @override
Future<bool> build() async { Future<bool> build() async {
final client = ref.watch(ClientController.provider.notifier);
final registered = await UnifiedPush.initialize( final registered = await UnifiedPush.initialize(
linuxOptions: .new( linuxOptions: .new(
dbusName: "nexus.federated.nexus.UnifiedPush", dbusName: "nexus.federated.nexus.UnifiedPush",
@ -19,7 +21,6 @@ class UnifiedPushController extends AsyncNotifier<bool> {
background: isInBackground, background: isInBackground,
), ),
onNewEndpoint: (endpoint, instance) async { onNewEndpoint: (endpoint, instance) async {
final client = ref.watch(ClientController.provider.notifier);
await client.registerPusher( await client.registerPusher(
.new( .new(
appDisplayName: "Nexus", appDisplayName: "Nexus",
@ -37,16 +38,16 @@ class UnifiedPushController extends AsyncNotifier<bool> {
); );
}, },
onMessage: (message, instance) async { onMessage: (message, instance) async {
print(message); final e = await client.handlePush(
// TODO: Handle incoming message json.decode(String.fromCharCodes(message.content)),
);
print(e);
}, },
onRegistrationFailed: (e, r) { onRegistrationFailed: (e, r) {
throw "e"; throw "e";
}, },
onUnregistered: (_) { onUnregistered: (instance) => ref.invalidateSelf(),
throw "r"; onTempUnavailable: (instance) {
},
onTempUnavailable: (_) {
throw "t"; throw "t";
}, },
); );

View file

@ -47,6 +47,7 @@ void showError(Object error, [StackTrace? stackTrace]) {
error.toString().contains("Invalid source") || error.toString().contains("Invalid source") ||
error.toString().contains("UTF-16") || error.toString().contains("UTF-16") ||
error.toString().contains("HTTP request failed") || error.toString().contains("HTTP request failed") ||
error.toString().contains("'_nextFrame != null': is not true.") ||
error.toString().contains("Invalid image data")) { error.toString().contains("Invalid image data")) {
return; return;
} }

View file

@ -1734,7 +1734,7 @@ packages:
source: hosted source: hosted
version: "3.0.3" version: "3.0.3"
webcrypto: webcrypto:
dependency: "direct main" dependency: "direct dev"
description: description:
name: webcrypto name: webcrypto
sha256: "6b43001c4110856ff7fa5e5e65e7b2d44bec1d8b54a4d84d5fa2c7622267c5c1" sha256: "6b43001c4110856ff7fa5e5e65e7b2d44bec1d8b54a4d84d5fa2c7622267c5c1"