turn off macos sandbox mode; ffi refactor to get library path so isolate polling appbus events always gets new platform updates

This commit is contained in:
Dan Ballard 2021-08-18 20:40:25 -04:00
parent ca83033997
commit d461bf879c
3 changed files with 18 additions and 13 deletions

View File

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

View File

@ -3,12 +3,12 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>com.apple.security.app-sandbox</key> <key>com.apple.security.app-sandbox</key>
<true/> <false/>
<key>com.apple.security.cs.allow-jit</key> <key>com.apple.security.cs.allow-jit</key>
<true/> <true/>
<key>com.apple.security.network.server</key> <key>com.apple.security.network.server</key>
<true/> <true/>
<key>com.apple.security.network.client</key> <key>com.apple.security.network.client</key>
<true/> <true/>
</dict> </dict>
</plist> </plist>

View File

@ -3,7 +3,7 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>com.apple.security.app-sandbox</key> <key>com.apple.security.app-sandbox</key>
<true/> <false/>
<key>com.apple.security.network.client</key> <key>com.apple.security.network.client</key>
<true/> <true/>
</dict> </dict>