mirror of
https://github.com/simon-ding/polaris.git
synced 2026-04-22 11:47:30 +08:00
feat: windows desktop app complete
This commit is contained in:
17
ui/lib/ffi/entry/libpolaris_boot_browser.dart
Normal file
17
ui/lib/ffi/entry/libpolaris_boot_browser.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:ui/ffi/lib_polaris_boot.dart';
|
||||
|
||||
LibPolarisBoot create() {
|
||||
return LibpolarisBootBrowser();
|
||||
}
|
||||
|
||||
class LibpolarisBootBrowser implements LibPolarisBoot {
|
||||
@override
|
||||
Future<int> start(String cfg) async{
|
||||
throw 0;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> stop() async{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:quiver/strings.dart';
|
||||
import 'package:ui/ffi/lib_polaris_boot.dart';
|
||||
|
||||
LibPolarisBoot create() => LibpolarisBootNative();
|
||||
|
||||
class FFIBackend {
|
||||
class LibpolarisBootNative implements LibPolarisBoot {
|
||||
final lib = DynamicLibrary.open(libname());
|
||||
|
||||
static String libname() {
|
||||
@@ -25,17 +28,31 @@ class FFIBackend {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> start() async {
|
||||
@override
|
||||
Future<int> start(String cfg) async {
|
||||
var s = lib
|
||||
.lookup<NativeFunction<Void Function()>>('Start')
|
||||
.asFunction<void Function()>();
|
||||
|
||||
return Isolate.run(s);
|
||||
.lookupFunction<StartFunc, StartFunc>('Start')
|
||||
;
|
||||
var r = s(cfg.toNativeUtf8());
|
||||
if (isNotBlank(r.r1.toDartString())) {
|
||||
throw Exception(r.r1.toDartString());
|
||||
}
|
||||
return r.r0;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> stop() async {
|
||||
var s = lib
|
||||
var s = lib
|
||||
.lookup<NativeFunction<Void Function()>>('Stop')
|
||||
.asFunction<void Function()>();
|
||||
return s();
|
||||
}
|
||||
}
|
||||
|
||||
typedef StartFunc = StartReturn Function(Pointer<Utf8> cfg);
|
||||
|
||||
final class StartReturn extends Struct {
|
||||
@Int32()
|
||||
external int r0;
|
||||
external Pointer<Utf8> r1;
|
||||
}
|
||||
18
ui/lib/ffi/lib_polaris_boot.dart
Normal file
18
ui/lib/ffi/lib_polaris_boot.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:ui/ffi/lib_polaris_boot_stub.dart'
|
||||
if (dart.library.html) 'package:ui/ffi/entry/libpolaris_boot_browser.dart'
|
||||
if (dart.library.io) 'package:ui/ffi/entry/libpolaris_boot_native.dart';
|
||||
|
||||
abstract class LibPolarisBoot {
|
||||
static LibPolarisBoot? _instance;
|
||||
|
||||
static LibPolarisBoot get instance {
|
||||
_instance ??= LibPolarisBoot();
|
||||
return _instance!;
|
||||
}
|
||||
|
||||
factory LibPolarisBoot() => create();
|
||||
|
||||
Future<int> start(String cfg);
|
||||
|
||||
Future<void> stop();
|
||||
}
|
||||
5
ui/lib/ffi/lib_polaris_boot_stub.dart
Normal file
5
ui/lib/ffi/lib_polaris_boot_stub.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
import 'package:ui/ffi/lib_polaris_boot.dart';
|
||||
|
||||
LibPolarisBoot create() => throw UnimplementedError();
|
||||
Reference in New Issue
Block a user