forked from Nexus/nexus
pass pushes to gomuks
This commit is contained in:
parent
adf3da8d77
commit
02704e97ef
4 changed files with 33 additions and 17 deletions
|
|
@ -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());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue