run GomuksStart on an isolate

This commit is contained in:
Henry Hiles 2026-10-15 14:25:45 -04:00
commit f082a75d9c
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -1,5 +1,6 @@
import "dart:async"; import "dart:async";
import "dart:ffi"; import "dart:ffi";
import "dart:isolate";
import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter/foundation.dart"; import "package:flutter/foundation.dart";
@ -112,12 +113,20 @@ class GomuksListenerController extends AsyncNotifier<void> {
ref.onDispose(callable.close); ref.onDispose(callable.close);
final errorCode = GomuksStart(handle, callable.nativeFunction); final errorCode = await _start(handle, callable.nativeFunction);
if (errorCode != 0) { if (errorCode != 0) {
throw Exception("GomuksStart returned error code $errorCode"); throw Exception("GomuksStart returned error code $errorCode");
} }
} }
static Future<int> _start(
int handle,
Pointer<
NativeFunction<Void Function(Pointer<Char>, Int64, GomuksOwnedBuffer)>
>
callback,
) => Isolate.run(() => GomuksStart(handle, callback));
static final provider = AsyncNotifierProvider<GomuksListenerController, void>( static final provider = AsyncNotifierProvider<GomuksListenerController, void>(
GomuksListenerController.new, GomuksListenerController.new,
); );