feat: downloader update

This commit is contained in:
xkeyC
2025-12-05 17:12:40 +08:00
parent 4315e36cbe
commit 289691896d
23 changed files with 1001 additions and 118 deletions

View File

@@ -6,12 +6,27 @@
import '../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
// These functions are ignored because they are not marked as `pub`: `get_task_status`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `clone`, `fmt`, `fmt`, `fmt`
// These functions are ignored because they are not marked as `pub`: `get_session`, `get_task_status`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `clone`, `eq`, `fmt`, `fmt`, `fmt`
/// Initialize the download manager session
void downloaderInit({required String downloadDir}) => RustLib.instance.api
.crateApiDownloaderApiDownloaderInit(downloadDir: downloadDir);
/// Initialize the download manager session with persistence enabled
///
/// Parameters:
/// - working_dir: The directory to store session data (persistence, DHT, etc.)
/// - default_download_dir: The default directory to store downloads
/// - upload_limit_bps: Upload speed limit in bytes per second (0 = unlimited)
/// - download_limit_bps: Download speed limit in bytes per second (0 = unlimited)
void downloaderInit({
required String workingDir,
required String defaultDownloadDir,
int? uploadLimitBps,
int? downloadLimitBps,
}) => RustLib.instance.api.crateApiDownloaderApiDownloaderInit(
workingDir: workingDir,
defaultDownloadDir: defaultDownloadDir,
uploadLimitBps: uploadLimitBps,
downloadLimitBps: downloadLimitBps,
);
/// Check if the downloader is initialized
bool downloaderIsInitialized() =>
@@ -95,10 +110,34 @@ Future<void> downloaderPauseAll() =>
Future<void> downloaderResumeAll() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderResumeAll();
/// Stop the downloader session
/// Stop the downloader session (pauses all tasks but keeps session)
Future<void> downloaderStop() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderStop();
/// Shutdown the downloader session completely (allows restart with new settings)
Future<void> downloaderShutdown() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderShutdown();
/// Update global speed limits
/// Note: rqbit Session doesn't support runtime limit changes,
/// this function is a placeholder that returns an error.
/// Speed limits should be set during downloader_init.
Future<void> downloaderUpdateSpeedLimits({
int? uploadLimitBps,
int? downloadLimitBps,
}) => RustLib.instance.api.crateApiDownloaderApiDownloaderUpdateSpeedLimits(
uploadLimitBps: uploadLimitBps,
downloadLimitBps: downloadLimitBps,
);
/// Remove all completed tasks (equivalent to aria2's --seed-time=0 behavior)
Future<int> downloaderRemoveCompletedTasks() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderRemoveCompletedTasks();
/// Check if there are any active (non-completed) tasks
Future<bool> downloaderHasActiveTasks() =>
RustLib.instance.api.crateApiDownloaderApiDownloaderHasActiveTasks();
/// Global statistics
class DownloadGlobalStat {
final BigInt downloadSpeed;

View File

@@ -72,7 +72,7 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
String get codegenVersion => '2.11.1';
@override
int get rustContentHash => -1465039096;
int get rustContentHash => -641930410;
static const kDefaultExternalLibraryLoaderConfig =
ExternalLibraryLoaderConfig(
@@ -126,7 +126,14 @@ abstract class RustLibApi extends BaseApi {
required BigInt taskId,
});
void crateApiDownloaderApiDownloaderInit({required String downloadDir});
Future<bool> crateApiDownloaderApiDownloaderHasActiveTasks();
void crateApiDownloaderApiDownloaderInit({
required String workingDir,
required String defaultDownloadDir,
int? uploadLimitBps,
int? downloadLimitBps,
});
bool crateApiDownloaderApiDownloaderIsInitialized();
@@ -143,12 +150,21 @@ abstract class RustLibApi extends BaseApi {
required bool deleteFiles,
});
Future<int> crateApiDownloaderApiDownloaderRemoveCompletedTasks();
Future<void> crateApiDownloaderApiDownloaderResume({required BigInt taskId});
Future<void> crateApiDownloaderApiDownloaderResumeAll();
Future<void> crateApiDownloaderApiDownloaderShutdown();
Future<void> crateApiDownloaderApiDownloaderStop();
Future<void> crateApiDownloaderApiDownloaderUpdateSpeedLimits({
int? uploadLimitBps,
int? downloadLimitBps,
});
Future<RustHttpResponse> crateApiHttpApiFetch({
required MyMethod method,
required String url,
@@ -700,19 +716,64 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
);
@override
void crateApiDownloaderApiDownloaderInit({required String downloadDir}) {
Future<bool> crateApiDownloaderApiDownloaderHasActiveTasks() {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
return wire
.wire__crate__api__downloader_api__downloader_has_active_tasks(
port_,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_bool,
decodeErrorData: null,
),
constMeta: kCrateApiDownloaderApiDownloaderHasActiveTasksConstMeta,
argValues: [],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiDownloaderApiDownloaderHasActiveTasksConstMeta =>
const TaskConstMeta(
debugName: "downloader_has_active_tasks",
argNames: [],
);
@override
void crateApiDownloaderApiDownloaderInit({
required String workingDir,
required String defaultDownloadDir,
int? uploadLimitBps,
int? downloadLimitBps,
}) {
return handler.executeSync(
SyncTask(
callFfi: () {
var arg0 = cst_encode_String(downloadDir);
return wire.wire__crate__api__downloader_api__downloader_init(arg0);
var arg0 = cst_encode_String(workingDir);
var arg1 = cst_encode_String(defaultDownloadDir);
var arg2 = cst_encode_opt_box_autoadd_u_32(uploadLimitBps);
var arg3 = cst_encode_opt_box_autoadd_u_32(downloadLimitBps);
return wire.wire__crate__api__downloader_api__downloader_init(
arg0,
arg1,
arg2,
arg3,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_AnyhowException,
),
constMeta: kCrateApiDownloaderApiDownloaderInitConstMeta,
argValues: [downloadDir],
argValues: [
workingDir,
defaultDownloadDir,
uploadLimitBps,
downloadLimitBps,
],
apiImpl: this,
),
);
@@ -721,7 +782,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
TaskConstMeta get kCrateApiDownloaderApiDownloaderInitConstMeta =>
const TaskConstMeta(
debugName: "downloader_init",
argNames: ["downloadDir"],
argNames: [
"workingDir",
"defaultDownloadDir",
"uploadLimitBps",
"downloadLimitBps",
],
);
@override
@@ -858,6 +924,35 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
argNames: ["taskId", "deleteFiles"],
);
@override
Future<int> crateApiDownloaderApiDownloaderRemoveCompletedTasks() {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
return wire
.wire__crate__api__downloader_api__downloader_remove_completed_tasks(
port_,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_u_32,
decodeErrorData: dco_decode_AnyhowException,
),
constMeta:
kCrateApiDownloaderApiDownloaderRemoveCompletedTasksConstMeta,
argValues: [],
apiImpl: this,
),
);
}
TaskConstMeta
get kCrateApiDownloaderApiDownloaderRemoveCompletedTasksConstMeta =>
const TaskConstMeta(
debugName: "downloader_remove_completed_tasks",
argNames: [],
);
@override
Future<void> crateApiDownloaderApiDownloaderResume({required BigInt taskId}) {
return handler.executeNormal(
@@ -906,6 +1001,29 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
TaskConstMeta get kCrateApiDownloaderApiDownloaderResumeAllConstMeta =>
const TaskConstMeta(debugName: "downloader_resume_all", argNames: []);
@override
Future<void> crateApiDownloaderApiDownloaderShutdown() {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
return wire.wire__crate__api__downloader_api__downloader_shutdown(
port_,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_AnyhowException,
),
constMeta: kCrateApiDownloaderApiDownloaderShutdownConstMeta,
argValues: [],
apiImpl: this,
),
);
}
TaskConstMeta get kCrateApiDownloaderApiDownloaderShutdownConstMeta =>
const TaskConstMeta(debugName: "downloader_shutdown", argNames: []);
@override
Future<void> crateApiDownloaderApiDownloaderStop() {
return handler.executeNormal(
@@ -927,6 +1045,41 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
TaskConstMeta get kCrateApiDownloaderApiDownloaderStopConstMeta =>
const TaskConstMeta(debugName: "downloader_stop", argNames: []);
@override
Future<void> crateApiDownloaderApiDownloaderUpdateSpeedLimits({
int? uploadLimitBps,
int? downloadLimitBps,
}) {
return handler.executeNormal(
NormalTask(
callFfi: (port_) {
var arg0 = cst_encode_opt_box_autoadd_u_32(uploadLimitBps);
var arg1 = cst_encode_opt_box_autoadd_u_32(downloadLimitBps);
return wire
.wire__crate__api__downloader_api__downloader_update_speed_limits(
port_,
arg0,
arg1,
);
},
codec: DcoCodec(
decodeSuccessData: dco_decode_unit,
decodeErrorData: dco_decode_AnyhowException,
),
constMeta: kCrateApiDownloaderApiDownloaderUpdateSpeedLimitsConstMeta,
argValues: [uploadLimitBps, downloadLimitBps],
apiImpl: this,
),
);
}
TaskConstMeta
get kCrateApiDownloaderApiDownloaderUpdateSpeedLimitsConstMeta =>
const TaskConstMeta(
debugName: "downloader_update_speed_limits",
argNames: ["uploadLimitBps", "downloadLimitBps"],
);
@override
Future<RustHttpResponse> crateApiHttpApiFetch({
required MyMethod method,
@@ -2386,6 +2539,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return dco_decode_rsi_launcher_asar_data(raw);
}
@protected
int dco_decode_box_autoadd_u_32(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return raw as int;
}
@protected
BigInt dco_decode_box_autoadd_u_64(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -2537,6 +2696,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return raw == null ? null : dco_decode_box_autoadd_bool(raw);
}
@protected
int? dco_decode_opt_box_autoadd_u_32(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
return raw == null ? null : dco_decode_box_autoadd_u_32(raw);
}
@protected
BigInt? dco_decode_opt_box_autoadd_u_64(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
@@ -2797,6 +2962,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return (sse_decode_rsi_launcher_asar_data(deserializer));
}
@protected
int sse_decode_box_autoadd_u_32(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
return (sse_decode_u_32(deserializer));
}
@protected
BigInt sse_decode_box_autoadd_u_64(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -3027,6 +3198,17 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
@protected
int? sse_decode_opt_box_autoadd_u_32(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
if (sse_decode_bool(deserializer)) {
return (sse_decode_box_autoadd_u_32(deserializer));
} else {
return null;
}
}
@protected
BigInt? sse_decode_opt_box_autoadd_u_64(SseDeserializer deserializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -3407,6 +3589,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
sse_encode_rsi_launcher_asar_data(self, serializer);
}
@protected
void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_u_32(self, serializer);
}
@protected
void sse_encode_box_autoadd_u_64(BigInt self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
@@ -3619,6 +3807,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
}
}
@protected
void sse_encode_opt_box_autoadd_u_32(int? self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs
sse_encode_bool(self != null, serializer);
if (self != null) {
sse_encode_box_autoadd_u_32(self, serializer);
}
}
@protected
void sse_encode_opt_box_autoadd_u_64(BigInt? self, SseSerializer serializer) {
// Codec=Sse (Serialization based), see doc to use other codecs

View File

@@ -50,6 +50,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
dynamic raw,
);
@protected
int dco_decode_box_autoadd_u_32(dynamic raw);
@protected
BigInt dco_decode_box_autoadd_u_64(dynamic raw);
@@ -115,6 +118,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
bool? dco_decode_opt_box_autoadd_bool(dynamic raw);
@protected
int? dco_decode_opt_box_autoadd_u_32(dynamic raw);
@protected
BigInt? dco_decode_opt_box_autoadd_u_64(dynamic raw);
@@ -203,6 +209,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
SseDeserializer deserializer,
);
@protected
int sse_decode_box_autoadd_u_32(SseDeserializer deserializer);
@protected
BigInt sse_decode_box_autoadd_u_64(SseDeserializer deserializer);
@@ -282,6 +291,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
bool? sse_decode_opt_box_autoadd_bool(SseDeserializer deserializer);
@protected
int? sse_decode_opt_box_autoadd_u_32(SseDeserializer deserializer);
@protected
BigInt? sse_decode_opt_box_autoadd_u_64(SseDeserializer deserializer);
@@ -408,6 +420,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
return ptr;
}
@protected
ffi.Pointer<ffi.Uint32> cst_encode_box_autoadd_u_32(int raw) {
// Codec=Cst (C-struct based), see doc to use other codecs
return wire.cst_new_box_autoadd_u_32(cst_encode_u_32(raw));
}
@protected
ffi.Pointer<ffi.Uint64> cst_encode_box_autoadd_u_64(BigInt raw) {
// Codec=Cst (C-struct based), see doc to use other codecs
@@ -538,6 +556,12 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
return raw == null ? ffi.nullptr : cst_encode_box_autoadd_bool(raw);
}
@protected
ffi.Pointer<ffi.Uint32> cst_encode_opt_box_autoadd_u_32(int? raw) {
// Codec=Cst (C-struct based), see doc to use other codecs
return raw == null ? ffi.nullptr : cst_encode_box_autoadd_u_32(raw);
}
@protected
ffi.Pointer<ffi.Uint64> cst_encode_opt_box_autoadd_u_64(BigInt? raw) {
// Codec=Cst (C-struct based), see doc to use other codecs
@@ -829,6 +853,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
SseSerializer serializer,
);
@protected
void sse_encode_box_autoadd_u_32(int self, SseSerializer serializer);
@protected
void sse_encode_box_autoadd_u_64(BigInt self, SseSerializer serializer);
@@ -925,6 +952,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
void sse_encode_opt_box_autoadd_bool(bool? self, SseSerializer serializer);
@protected
void sse_encode_opt_box_autoadd_u_32(int? self, SseSerializer serializer);
@protected
void sse_encode_opt_box_autoadd_u_64(BigInt? self, SseSerializer serializer);
@@ -1337,10 +1367,34 @@ class RustLibWire implements BaseWire {
_wire__crate__api__downloader_api__downloader_get_task_infoPtr
.asFunction<void Function(int, int)>();
WireSyncRust2DartDco wire__crate__api__downloader_api__downloader_init(
ffi.Pointer<wire_cst_list_prim_u_8_strict> download_dir,
void wire__crate__api__downloader_api__downloader_has_active_tasks(
int port_,
) {
return _wire__crate__api__downloader_api__downloader_init(download_dir);
return _wire__crate__api__downloader_api__downloader_has_active_tasks(
port_,
);
}
late final _wire__crate__api__downloader_api__downloader_has_active_tasksPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
'frbgen_starcitizen_doctor_wire__crate__api__downloader_api__downloader_has_active_tasks',
);
late final _wire__crate__api__downloader_api__downloader_has_active_tasks =
_wire__crate__api__downloader_api__downloader_has_active_tasksPtr
.asFunction<void Function(int)>();
WireSyncRust2DartDco wire__crate__api__downloader_api__downloader_init(
ffi.Pointer<wire_cst_list_prim_u_8_strict> working_dir,
ffi.Pointer<wire_cst_list_prim_u_8_strict> default_download_dir,
ffi.Pointer<ffi.Uint32> upload_limit_bps,
ffi.Pointer<ffi.Uint32> download_limit_bps,
) {
return _wire__crate__api__downloader_api__downloader_init(
working_dir,
default_download_dir,
upload_limit_bps,
download_limit_bps,
);
}
late final _wire__crate__api__downloader_api__downloader_initPtr =
@@ -1348,6 +1402,9 @@ class RustLibWire implements BaseWire {
ffi.NativeFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<ffi.Uint32>,
ffi.Pointer<ffi.Uint32>,
)
>
>(
@@ -1358,6 +1415,9 @@ class RustLibWire implements BaseWire {
.asFunction<
WireSyncRust2DartDco Function(
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<wire_cst_list_prim_u_8_strict>,
ffi.Pointer<ffi.Uint32>,
ffi.Pointer<ffi.Uint32>,
)
>();
@@ -1450,6 +1510,22 @@ class RustLibWire implements BaseWire {
_wire__crate__api__downloader_api__downloader_removePtr
.asFunction<void Function(int, int, bool)>();
void wire__crate__api__downloader_api__downloader_remove_completed_tasks(
int port_,
) {
return _wire__crate__api__downloader_api__downloader_remove_completed_tasks(
port_,
);
}
late final _wire__crate__api__downloader_api__downloader_remove_completed_tasksPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
'frbgen_starcitizen_doctor_wire__crate__api__downloader_api__downloader_remove_completed_tasks',
);
late final _wire__crate__api__downloader_api__downloader_remove_completed_tasks =
_wire__crate__api__downloader_api__downloader_remove_completed_tasksPtr
.asFunction<void Function(int)>();
void wire__crate__api__downloader_api__downloader_resume(
int port_,
int task_id,
@@ -1477,6 +1553,18 @@ class RustLibWire implements BaseWire {
_wire__crate__api__downloader_api__downloader_resume_allPtr
.asFunction<void Function(int)>();
void wire__crate__api__downloader_api__downloader_shutdown(int port_) {
return _wire__crate__api__downloader_api__downloader_shutdown(port_);
}
late final _wire__crate__api__downloader_api__downloader_shutdownPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
'frbgen_starcitizen_doctor_wire__crate__api__downloader_api__downloader_shutdown',
);
late final _wire__crate__api__downloader_api__downloader_shutdown =
_wire__crate__api__downloader_api__downloader_shutdownPtr
.asFunction<void Function(int)>();
void wire__crate__api__downloader_api__downloader_stop(int port_) {
return _wire__crate__api__downloader_api__downloader_stop(port_);
}
@@ -1489,6 +1577,36 @@ class RustLibWire implements BaseWire {
_wire__crate__api__downloader_api__downloader_stopPtr
.asFunction<void Function(int)>();
void wire__crate__api__downloader_api__downloader_update_speed_limits(
int port_,
ffi.Pointer<ffi.Uint32> _upload_limit_bps,
ffi.Pointer<ffi.Uint32> _download_limit_bps,
) {
return _wire__crate__api__downloader_api__downloader_update_speed_limits(
port_,
_upload_limit_bps,
_download_limit_bps,
);
}
late final _wire__crate__api__downloader_api__downloader_update_speed_limitsPtr =
_lookup<
ffi.NativeFunction<
ffi.Void Function(
ffi.Int64,
ffi.Pointer<ffi.Uint32>,
ffi.Pointer<ffi.Uint32>,
)
>
>(
'frbgen_starcitizen_doctor_wire__crate__api__downloader_api__downloader_update_speed_limits',
);
late final _wire__crate__api__downloader_api__downloader_update_speed_limits =
_wire__crate__api__downloader_api__downloader_update_speed_limitsPtr
.asFunction<
void Function(int, ffi.Pointer<ffi.Uint32>, ffi.Pointer<ffi.Uint32>)
>();
void wire__crate__api__http_api__fetch(
int port_,
int method,
@@ -2755,6 +2873,17 @@ class RustLibWire implements BaseWire {
ffi.Pointer<wire_cst_rsi_launcher_asar_data> Function()
>();
ffi.Pointer<ffi.Uint32> cst_new_box_autoadd_u_32(int value) {
return _cst_new_box_autoadd_u_32(value);
}
late final _cst_new_box_autoadd_u_32Ptr =
_lookup<ffi.NativeFunction<ffi.Pointer<ffi.Uint32> Function(ffi.Uint32)>>(
'frbgen_starcitizen_doctor_cst_new_box_autoadd_u_32',
);
late final _cst_new_box_autoadd_u_32 = _cst_new_box_autoadd_u_32Ptr
.asFunction<ffi.Pointer<ffi.Uint32> Function(int)>();
ffi.Pointer<ffi.Uint64> cst_new_box_autoadd_u_64(int value) {
return _cst_new_box_autoadd_u_64(value);
}