feat: build windows dll and call dll in flutter

This commit is contained in:
Simon Ding
2025-04-10 14:24:46 +08:00
parent 5ab347845a
commit 6371139607
14 changed files with 95 additions and 11 deletions

41
ui/lib/ffi/backend.dart Normal file
View File

@@ -0,0 +1,41 @@
import 'dart:ffi';
import 'dart:io';
import 'dart:isolate';
import 'package:ui/widgets/utils.dart' as Utils;
class FFIBackend {
final lib = DynamicLibrary.open(libname());
static String libname() {
if (Utils.isDesktop()) {
if (Platform.isWindows) {
return 'libpolaris.dll';
} else if (Platform.isLinux) {
return 'libpolaris.so';
} else if (Platform.isMacOS) {
return 'libpolaris.dylib';
} else {
throw UnsupportedError(
'Unsupported platform: ${Platform.operatingSystem}');
}
} else {
return "";
}
}
Future<void> start() async {
var s = lib
.lookup<NativeFunction<Void Function()>>('Start')
.asFunction<void Function()>();
return Isolate.run(s);
}
Future<void> stop() async {
var s = lib
.lookup<NativeFunction<Void Function()>>('Stop')
.asFunction<void Function()>();
return s();
}
}