diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 9c4f4cd6..2844c542 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -59,25 +59,35 @@ typedef GetJsonBlobFromStrStrStrFn = Pointer Function(Pointer, int, typedef appbus_events_function = Pointer Function(); typedef AppbusEventsFn = Pointer 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 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>("c_GetAppBusEvent"); // ignore: non_constant_identifier_names diff --git a/macos/Runner/DebugProfile.entitlements b/macos/Runner/DebugProfile.entitlements index c946719a..78c36cf4 100644 --- a/macos/Runner/DebugProfile.entitlements +++ b/macos/Runner/DebugProfile.entitlements @@ -3,12 +3,12 @@ com.apple.security.app-sandbox - + com.apple.security.cs.allow-jit com.apple.security.network.server com.apple.security.network.client - + diff --git a/macos/Runner/Release.entitlements b/macos/Runner/Release.entitlements index ee95ab7e..08ba3a3f 100644 --- a/macos/Runner/Release.entitlements +++ b/macos/Runner/Release.entitlements @@ -3,7 +3,7 @@ com.apple.security.app-sandbox - + com.apple.security.network.client