mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 12:34:45 +08:00
引入 Rust \\TODO 使用 rust 实现的下载器
This commit is contained in:
34
lib/common/rust/bridge_definitions.dart
Normal file
34
lib/common/rust/bridge_definitions.dart
Normal file
@ -0,0 +1,34 @@
|
||||
// AUTO GENERATED FILE, DO NOT EDIT.
|
||||
// Generated by `flutter_rust_bridge`@ 1.82.3.
|
||||
// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:async';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
abstract class Rust {
|
||||
Future<Platform> platform({dynamic hint});
|
||||
|
||||
FlutterRustBridgeTaskConstMeta get kPlatformConstMeta;
|
||||
|
||||
Future<int> add({required int left, required int right, dynamic hint});
|
||||
|
||||
FlutterRustBridgeTaskConstMeta get kAddConstMeta;
|
||||
|
||||
Future<bool> rustReleaseMode({dynamic hint});
|
||||
|
||||
FlutterRustBridgeTaskConstMeta get kRustReleaseModeConstMeta;
|
||||
}
|
||||
|
||||
enum Platform {
|
||||
Unknown,
|
||||
Android,
|
||||
Ios,
|
||||
Windows,
|
||||
Unix,
|
||||
MacIntel,
|
||||
MacApple,
|
||||
Wasm,
|
||||
}
|
282
lib/common/rust/bridge_generated.dart
Normal file
282
lib/common/rust/bridge_generated.dart
Normal file
@ -0,0 +1,282 @@
|
||||
// AUTO GENERATED FILE, DO NOT EDIT.
|
||||
// Generated by `flutter_rust_bridge`@ 1.82.3.
|
||||
// ignore_for_file: non_constant_identifier_names, unused_element, duplicate_ignore, directives_ordering, curly_braces_in_flow_control_structures, unnecessary_lambdas, slash_for_doc_comments, prefer_const_literals_to_create_immutables, implicit_dynamic_list_literal, duplicate_import, unused_import, unnecessary_import, prefer_single_quotes, prefer_const_constructors, use_super_parameters, always_use_package_imports, annotate_overrides, invalid_use_of_protected_member, constant_identifier_names, invalid_use_of_internal_member, prefer_is_empty, unnecessary_const
|
||||
|
||||
import "bridge_definitions.dart";
|
||||
import 'dart:convert';
|
||||
import 'dart:async';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:async';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'dart:ffi' as ffi;
|
||||
|
||||
class RustImpl implements Rust {
|
||||
final RustPlatform _platform;
|
||||
factory RustImpl(ExternalLibrary dylib) => RustImpl.raw(RustPlatform(dylib));
|
||||
|
||||
/// Only valid on web/WASM platforms.
|
||||
factory RustImpl.wasm(FutureOr<WasmModule> module) =>
|
||||
RustImpl(module as ExternalLibrary);
|
||||
RustImpl.raw(this._platform);
|
||||
Future<Platform> platform({dynamic hint}) {
|
||||
return _platform.executeNormal(FlutterRustBridgeTask(
|
||||
callFfi: (port_) => _platform.inner.wire_platform(port_),
|
||||
parseSuccessData: _wire2api_platform,
|
||||
parseErrorData: null,
|
||||
constMeta: kPlatformConstMeta,
|
||||
argValues: [],
|
||||
hint: hint,
|
||||
));
|
||||
}
|
||||
|
||||
FlutterRustBridgeTaskConstMeta get kPlatformConstMeta =>
|
||||
const FlutterRustBridgeTaskConstMeta(
|
||||
debugName: "platform",
|
||||
argNames: [],
|
||||
);
|
||||
|
||||
Future<int> add({required int left, required int right, dynamic hint}) {
|
||||
var arg0 = api2wire_usize(left);
|
||||
var arg1 = api2wire_usize(right);
|
||||
return _platform.executeNormal(FlutterRustBridgeTask(
|
||||
callFfi: (port_) => _platform.inner.wire_add(port_, arg0, arg1),
|
||||
parseSuccessData: _wire2api_usize,
|
||||
parseErrorData: null,
|
||||
constMeta: kAddConstMeta,
|
||||
argValues: [left, right],
|
||||
hint: hint,
|
||||
));
|
||||
}
|
||||
|
||||
FlutterRustBridgeTaskConstMeta get kAddConstMeta =>
|
||||
const FlutterRustBridgeTaskConstMeta(
|
||||
debugName: "add",
|
||||
argNames: ["left", "right"],
|
||||
);
|
||||
|
||||
Future<bool> rustReleaseMode({dynamic hint}) {
|
||||
return _platform.executeNormal(FlutterRustBridgeTask(
|
||||
callFfi: (port_) => _platform.inner.wire_rust_release_mode(port_),
|
||||
parseSuccessData: _wire2api_bool,
|
||||
parseErrorData: null,
|
||||
constMeta: kRustReleaseModeConstMeta,
|
||||
argValues: [],
|
||||
hint: hint,
|
||||
));
|
||||
}
|
||||
|
||||
FlutterRustBridgeTaskConstMeta get kRustReleaseModeConstMeta =>
|
||||
const FlutterRustBridgeTaskConstMeta(
|
||||
debugName: "rust_release_mode",
|
||||
argNames: [],
|
||||
);
|
||||
|
||||
void dispose() {
|
||||
_platform.dispose();
|
||||
}
|
||||
// Section: wire2api
|
||||
|
||||
bool _wire2api_bool(dynamic raw) {
|
||||
return raw as bool;
|
||||
}
|
||||
|
||||
int _wire2api_i32(dynamic raw) {
|
||||
return raw as int;
|
||||
}
|
||||
|
||||
Platform _wire2api_platform(dynamic raw) {
|
||||
return Platform.values[raw as int];
|
||||
}
|
||||
|
||||
int _wire2api_usize(dynamic raw) {
|
||||
return castInt(raw);
|
||||
}
|
||||
}
|
||||
|
||||
// Section: api2wire
|
||||
|
||||
@protected
|
||||
int api2wire_usize(int raw) {
|
||||
return raw;
|
||||
}
|
||||
// Section: finalizer
|
||||
|
||||
class RustPlatform extends FlutterRustBridgeBase<RustWire> {
|
||||
RustPlatform(ffi.DynamicLibrary dylib) : super(RustWire(dylib));
|
||||
|
||||
// Section: api2wire
|
||||
|
||||
// Section: finalizer
|
||||
|
||||
// Section: api_fill_to_wire
|
||||
}
|
||||
|
||||
// ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names
|
||||
|
||||
// AUTO GENERATED FILE, DO NOT EDIT.
|
||||
//
|
||||
// Generated by `package:ffigen`.
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
/// generated by flutter_rust_bridge
|
||||
class RustWire implements FlutterRustBridgeWireBase {
|
||||
@internal
|
||||
late final dartApi = DartApiDl(init_frb_dart_api_dl);
|
||||
|
||||
/// Holds the symbol lookup function.
|
||||
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||
_lookup;
|
||||
|
||||
/// The symbols are looked up in [dynamicLibrary].
|
||||
RustWire(ffi.DynamicLibrary dynamicLibrary) : _lookup = dynamicLibrary.lookup;
|
||||
|
||||
/// The symbols are looked up with [lookup].
|
||||
RustWire.fromLookup(
|
||||
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||
lookup)
|
||||
: _lookup = lookup;
|
||||
|
||||
void store_dart_post_cobject(
|
||||
DartPostCObjectFnType ptr,
|
||||
) {
|
||||
return _store_dart_post_cobject(
|
||||
ptr,
|
||||
);
|
||||
}
|
||||
|
||||
late final _store_dart_post_cobjectPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(DartPostCObjectFnType)>>(
|
||||
'store_dart_post_cobject');
|
||||
late final _store_dart_post_cobject = _store_dart_post_cobjectPtr
|
||||
.asFunction<void Function(DartPostCObjectFnType)>();
|
||||
|
||||
Object get_dart_object(
|
||||
int ptr,
|
||||
) {
|
||||
return _get_dart_object(
|
||||
ptr,
|
||||
);
|
||||
}
|
||||
|
||||
late final _get_dart_objectPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Handle Function(ffi.UintPtr)>>(
|
||||
'get_dart_object');
|
||||
late final _get_dart_object =
|
||||
_get_dart_objectPtr.asFunction<Object Function(int)>();
|
||||
|
||||
void drop_dart_object(
|
||||
int ptr,
|
||||
) {
|
||||
return _drop_dart_object(
|
||||
ptr,
|
||||
);
|
||||
}
|
||||
|
||||
late final _drop_dart_objectPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.UintPtr)>>(
|
||||
'drop_dart_object');
|
||||
late final _drop_dart_object =
|
||||
_drop_dart_objectPtr.asFunction<void Function(int)>();
|
||||
|
||||
int new_dart_opaque(
|
||||
Object handle,
|
||||
) {
|
||||
return _new_dart_opaque(
|
||||
handle,
|
||||
);
|
||||
}
|
||||
|
||||
late final _new_dart_opaquePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.UintPtr Function(ffi.Handle)>>(
|
||||
'new_dart_opaque');
|
||||
late final _new_dart_opaque =
|
||||
_new_dart_opaquePtr.asFunction<int Function(Object)>();
|
||||
|
||||
int init_frb_dart_api_dl(
|
||||
ffi.Pointer<ffi.Void> obj,
|
||||
) {
|
||||
return _init_frb_dart_api_dl(
|
||||
obj,
|
||||
);
|
||||
}
|
||||
|
||||
late final _init_frb_dart_api_dlPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.IntPtr Function(ffi.Pointer<ffi.Void>)>>(
|
||||
'init_frb_dart_api_dl');
|
||||
late final _init_frb_dart_api_dl = _init_frb_dart_api_dlPtr
|
||||
.asFunction<int Function(ffi.Pointer<ffi.Void>)>();
|
||||
|
||||
void wire_platform(
|
||||
int port_,
|
||||
) {
|
||||
return _wire_platform(
|
||||
port_,
|
||||
);
|
||||
}
|
||||
|
||||
late final _wire_platformPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
|
||||
'wire_platform');
|
||||
late final _wire_platform =
|
||||
_wire_platformPtr.asFunction<void Function(int)>();
|
||||
|
||||
void wire_add(
|
||||
int port_,
|
||||
int left,
|
||||
int right,
|
||||
) {
|
||||
return _wire_add(
|
||||
port_,
|
||||
left,
|
||||
right,
|
||||
);
|
||||
}
|
||||
|
||||
late final _wire_addPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Int64, ffi.UintPtr, ffi.UintPtr)>>('wire_add');
|
||||
late final _wire_add =
|
||||
_wire_addPtr.asFunction<void Function(int, int, int)>();
|
||||
|
||||
void wire_rust_release_mode(
|
||||
int port_,
|
||||
) {
|
||||
return _wire_rust_release_mode(
|
||||
port_,
|
||||
);
|
||||
}
|
||||
|
||||
late final _wire_rust_release_modePtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
|
||||
'wire_rust_release_mode');
|
||||
late final _wire_rust_release_mode =
|
||||
_wire_rust_release_modePtr.asFunction<void Function(int)>();
|
||||
|
||||
void free_WireSyncReturn(
|
||||
WireSyncReturn ptr,
|
||||
) {
|
||||
return _free_WireSyncReturn(
|
||||
ptr,
|
||||
);
|
||||
}
|
||||
|
||||
late final _free_WireSyncReturnPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(WireSyncReturn)>>(
|
||||
'free_WireSyncReturn');
|
||||
late final _free_WireSyncReturn =
|
||||
_free_WireSyncReturnPtr.asFunction<void Function(WireSyncReturn)>();
|
||||
}
|
||||
|
||||
final class _Dart_Handle extends ffi.Opaque {}
|
||||
|
||||
typedef DartPostCObjectFnType = ffi.Pointer<
|
||||
ffi.NativeFunction<
|
||||
ffi.Bool Function(DartPort port_id, ffi.Pointer<ffi.Void> message)>>;
|
||||
typedef DartPort = ffi.Int64;
|
23
lib/common/rust/ffi.dart
Normal file
23
lib/common/rust/ffi.dart
Normal file
@ -0,0 +1,23 @@
|
||||
// This file initializes the dynamic library and connects it with the stub
|
||||
// generated by flutter_rust_bridge_codegen.
|
||||
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'bridge_generated.dart';
|
||||
import 'bridge_definitions.dart';
|
||||
export 'bridge_definitions.dart';
|
||||
|
||||
// Re-export the bridge so it is only necessary to import this file.
|
||||
export 'bridge_generated.dart';
|
||||
import 'dart:io' as io;
|
||||
|
||||
|
||||
const _base = 'rust';
|
||||
|
||||
// On MacOS, the dynamic library is not bundled with the binary,
|
||||
// but rather directly **linked** against the binary.
|
||||
final _dylib = io.Platform.isWindows ? '$_base.dll' : 'lib$_base.so';
|
||||
|
||||
final Rust rustFii = RustImpl(io.Platform.isIOS || io.Platform.isMacOS
|
||||
? DynamicLibrary.executable()
|
||||
: DynamicLibrary.open(_dylib));
|
@ -2,6 +2,7 @@ import 'package:desktop_webview_window/desktop_webview_window.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/conf.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/ffi.dart';
|
||||
import 'package:starcitizen_doctor/ui/index_ui_model.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
@ -9,6 +10,9 @@ import 'global_ui_model.dart';
|
||||
import 'ui/index_ui.dart';
|
||||
|
||||
void main(List<String> args) async {
|
||||
|
||||
dPrint("rust ffi ${await rustFii.platform()}");
|
||||
|
||||
if (runWebViewTitleBarWidget(args,
|
||||
backgroundColor: const Color.fromRGBO(19, 36, 49, 1),
|
||||
builder: _defaultWebviewTitleBar)) {
|
||||
|
Reference in New Issue
Block a user