|
|
|
@ -59,25 +59,35 @@ typedef GetJsonBlobFromStrStrStrFn = Pointer<Utf8> Function(Pointer<Utf8>, int,
|
|
|
|
|
typedef appbus_events_function = Pointer<Utf8> Function();
|
|
|
|
|
typedef AppbusEventsFn = Pointer<Utf8> Function();
|
|
|
|
|
|
|
|
|
|
const String UNSUPPORTED_OS = "unsupported-os";
|
|
|
|
|
|
|
|
|
|
class CwtchFfi implements Cwtch {
|
|
|
|
|
late DynamicLibrary library;
|
|
|
|
|
late CwtchNotifier cwtchNotifier;
|
|
|
|
|
late Isolate cwtchIsolate;
|
|
|
|
|
ReceivePort _receivePort = ReceivePort();
|
|
|
|
|
|
|
|
|
|
CwtchFfi(CwtchNotifier _cwtchNotifier) {
|
|
|
|
|
static String getLibraryPath() {
|
|
|
|
|
if (Platform.isWindows) {
|
|
|
|
|
library = DynamicLibrary.open("libCwtch.dll");
|
|
|
|
|
return "libCwtch.dll";
|
|
|
|
|
} else if (Platform.isLinux) {
|
|
|
|
|
library = DynamicLibrary.open("libCwtch.so");
|
|
|
|
|
return "libCwtch.so";
|
|
|
|
|
} else if (Platform.isMacOS) {
|
|
|
|
|
print(dirname(Platform.script.path));
|
|
|
|
|
library = DynamicLibrary.open("libCwtch.dylib");
|
|
|
|
|
return "libCwtch.dylib";
|
|
|
|
|
} else {
|
|
|
|
|
return UNSUPPORTED_OS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CwtchFfi(CwtchNotifier _cwtchNotifier) {
|
|
|
|
|
String library_path = getLibraryPath();
|
|
|
|
|
if (library_path == UNSUPPORTED_OS) {
|
|
|
|
|
print("OS ${Platform.operatingSystem} not supported by cwtch/ffi");
|
|
|
|
|
// emergency, ideally the app stays on splash and just posts the error till user closes
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
library = DynamicLibrary.open(library_path);
|
|
|
|
|
cwtchNotifier = _cwtchNotifier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -150,12 +160,7 @@ class CwtchFfi implements Cwtch {
|
|
|
|
|
|
|
|
|
|
// Steam of appbus events. Call blocks in libcwtch-go GetAppbusEvent. Static so the isolate can use it
|
|
|
|
|
static Stream<String> pollAppbusEvents() async* {
|
|
|
|
|
late DynamicLibrary library;
|
|
|
|
|
if (Platform.isWindows) {
|
|
|
|
|
library = DynamicLibrary.open("libCwtch.dll");
|
|
|
|
|
} else if (Platform.isLinux) {
|
|
|
|
|
library = DynamicLibrary.open("libCwtch.so");
|
|
|
|
|
}
|
|
|
|
|
late DynamicLibrary library = DynamicLibrary.open(getLibraryPath());
|
|
|
|
|
|
|
|
|
|
var getAppbusEventC = library.lookup<NativeFunction<appbus_events_function>>("c_GetAppBusEvent");
|
|
|
|
|
// ignore: non_constant_identifier_names
|
|
|
|
|