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:io";
import "dart:isolate";
@ -156,18 +157,15 @@ class ClientController extends AsyncNotifier<int> {
throw Exception("GomuksStart returned error code $errorCode");
}
Future<dynamic> _sendCommand(
String command, [
Map<String, dynamic> data = const {},
]) async {
Future<dynamic> callGomuksMethod(
Map<String, dynamic> data,
FutureOr<GomuksResponse> 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<Char>(),
bufferPointer.ref,
),
() => callback(handle, bufferPointer.ref),
);
calloc.free(bufferPointer);
@ -180,6 +178,22 @@ class ClientController extends AsyncNotifier<int> {
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) =>
_sendCommand("redact_event", report.toJson());

View file

@ -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<bool> {
@override
Future<bool> 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<bool> {
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<bool> {
);
},
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";
},
);

View file

@ -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;
}

View file

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