mirror of
https://mirror.ghproxy.com/https://github.com/StarCitizenToolBox/app.git
synced 2024-12-22 14:03:44 +08:00
移除 rust 多线程下载器
This commit is contained in:
parent
02101db99d
commit
46808e96c5
@ -1,24 +0,0 @@
|
||||
// This file is automatically generated, so please do not edit it.
|
||||
// Generated by `flutter_rust_bridge`@ 2.0.0-dev.24.
|
||||
|
||||
// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import
|
||||
|
||||
import '../downloader.dart';
|
||||
import '../frb_generated.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
|
||||
|
||||
Stream<DownloadCallbackData> startDownload(
|
||||
{required String url,
|
||||
required String savePath,
|
||||
required String fileName,
|
||||
required int connectionCount,
|
||||
dynamic hint}) =>
|
||||
RustLib.instance.api.startDownload(
|
||||
url: url,
|
||||
savePath: savePath,
|
||||
fileName: fileName,
|
||||
connectionCount: connectionCount,
|
||||
hint: hint);
|
||||
|
||||
Future<void> cancelDownload({required String id, dynamic hint}) =>
|
||||
RustLib.instance.api.cancelDownload(id: id, hint: hint);
|
@ -3,11 +3,9 @@
|
||||
|
||||
// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field
|
||||
|
||||
import 'api/downloader_api.dart';
|
||||
import 'api/http_api.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'downloader.dart';
|
||||
import 'frb_generated.io.dart' if (dart.library.html) 'frb_generated.web.dart';
|
||||
import 'http_package.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
|
||||
@ -65,15 +63,6 @@ class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
|
||||
}
|
||||
|
||||
abstract class RustLibApi extends BaseApi {
|
||||
Future<void> cancelDownload({required String id, dynamic hint});
|
||||
|
||||
Stream<DownloadCallbackData> startDownload(
|
||||
{required String url,
|
||||
required String savePath,
|
||||
required String fileName,
|
||||
required int connectionCount,
|
||||
dynamic hint});
|
||||
|
||||
Future<List<String>> dnsLookupTxt({required String host, dynamic hint});
|
||||
|
||||
Future<RustHttpResponse> fetch(
|
||||
@ -104,64 +93,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
required super.portManager,
|
||||
});
|
||||
|
||||
@override
|
||||
Future<void> cancelDownload({required String id, dynamic hint}) {
|
||||
return handler.executeNormal(NormalTask(
|
||||
callFfi: (port_) {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_String(id, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 2, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_unit,
|
||||
decodeErrorData: null,
|
||||
),
|
||||
constMeta: kCancelDownloadConstMeta,
|
||||
argValues: [id],
|
||||
apiImpl: this,
|
||||
hint: hint,
|
||||
));
|
||||
}
|
||||
|
||||
TaskConstMeta get kCancelDownloadConstMeta => const TaskConstMeta(
|
||||
debugName: "cancel_download",
|
||||
argNames: ["id"],
|
||||
);
|
||||
|
||||
@override
|
||||
Stream<DownloadCallbackData> startDownload(
|
||||
{required String url,
|
||||
required String savePath,
|
||||
required String fileName,
|
||||
required int connectionCount,
|
||||
dynamic hint}) {
|
||||
return handler.executeStream(StreamTask(
|
||||
callFfi: (port_) {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_String(url, serializer);
|
||||
sse_encode_String(savePath, serializer);
|
||||
sse_encode_String(fileName, serializer);
|
||||
sse_encode_u_8(connectionCount, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 1, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_download_callback_data,
|
||||
decodeErrorData: null,
|
||||
),
|
||||
constMeta: kStartDownloadConstMeta,
|
||||
argValues: [url, savePath, fileName, connectionCount],
|
||||
apiImpl: this,
|
||||
hint: hint,
|
||||
));
|
||||
}
|
||||
|
||||
TaskConstMeta get kStartDownloadConstMeta => const TaskConstMeta(
|
||||
debugName: "start_download",
|
||||
argNames: ["url", "savePath", "fileName", "connectionCount"],
|
||||
);
|
||||
|
||||
@override
|
||||
Future<List<String>> dnsLookupTxt({required String host, dynamic hint}) {
|
||||
return handler.executeNormal(NormalTask(
|
||||
@ -169,7 +100,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_String(host, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 5, port: port_);
|
||||
funcId: 3, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_list_String,
|
||||
@ -202,7 +133,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
sse_encode_opt_Map_String_String(headers, serializer);
|
||||
sse_encode_opt_list_prim_u_8_strict(inputData, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 4, port: port_);
|
||||
funcId: 2, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_rust_http_response,
|
||||
@ -228,7 +159,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
final serializer = SseSerializer(generalizedFrbRustBinding);
|
||||
sse_encode_Map_String_String(headers, serializer);
|
||||
pdeCallFfi(generalizedFrbRustBinding, serializer,
|
||||
funcId: 3, port: port_);
|
||||
funcId: 1, port: port_);
|
||||
},
|
||||
codec: SseCodec(
|
||||
decodeSuccessData: sse_decode_unit,
|
||||
@ -295,21 +226,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return dco_decode_u_64(raw);
|
||||
}
|
||||
|
||||
@protected
|
||||
DownloadCallbackData dco_decode_download_callback_data(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
final arr = raw as List<dynamic>;
|
||||
if (arr.length != 5)
|
||||
throw Exception('unexpected arr length: expect 5 but see ${arr.length}');
|
||||
return DownloadCallbackData(
|
||||
id: dco_decode_String(arr[0]),
|
||||
total: dco_decode_u_64(arr[1]),
|
||||
progress: dco_decode_u_64(arr[2]),
|
||||
speed: dco_decode_u_64(arr[3]),
|
||||
status: dco_decode_my_downloader_status(arr[4]),
|
||||
);
|
||||
}
|
||||
|
||||
@protected
|
||||
int dco_decode_i_32(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
@ -334,42 +250,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return (raw as List<dynamic>).map(dco_decode_record_string_string).toList();
|
||||
}
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus dco_decode_my_downloader_status(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
switch (raw[0]) {
|
||||
case 0:
|
||||
return const MyDownloaderStatus_NoStart();
|
||||
case 1:
|
||||
return const MyDownloaderStatus_Running();
|
||||
case 2:
|
||||
return MyDownloaderStatus_Pending(
|
||||
dco_decode_my_network_item_pending_type(raw[1]),
|
||||
);
|
||||
case 3:
|
||||
return MyDownloaderStatus_Error(
|
||||
dco_decode_String(raw[1]),
|
||||
);
|
||||
case 4:
|
||||
return const MyDownloaderStatus_Finished();
|
||||
default:
|
||||
throw Exception("unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
MyMethod dco_decode_my_method(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
return MyMethod.values[raw as int];
|
||||
}
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType dco_decode_my_network_item_pending_type(
|
||||
dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
return MyNetworkItemPendingType.values[raw as int];
|
||||
}
|
||||
|
||||
@protected
|
||||
Map<String, String>? dco_decode_opt_Map_String_String(dynamic raw) {
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
@ -496,23 +382,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return (sse_decode_u_64(deserializer));
|
||||
}
|
||||
|
||||
@protected
|
||||
DownloadCallbackData sse_decode_download_callback_data(
|
||||
SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
var var_id = sse_decode_String(deserializer);
|
||||
var var_total = sse_decode_u_64(deserializer);
|
||||
var var_progress = sse_decode_u_64(deserializer);
|
||||
var var_speed = sse_decode_u_64(deserializer);
|
||||
var var_status = sse_decode_my_downloader_status(deserializer);
|
||||
return DownloadCallbackData(
|
||||
id: var_id,
|
||||
total: var_total,
|
||||
progress: var_progress,
|
||||
speed: var_speed,
|
||||
status: var_status);
|
||||
}
|
||||
|
||||
@protected
|
||||
int sse_decode_i_32(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@ -551,30 +420,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return ans_;
|
||||
}
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus sse_decode_my_downloader_status(
|
||||
SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
|
||||
var tag_ = sse_decode_i_32(deserializer);
|
||||
switch (tag_) {
|
||||
case 0:
|
||||
return const MyDownloaderStatus_NoStart();
|
||||
case 1:
|
||||
return const MyDownloaderStatus_Running();
|
||||
case 2:
|
||||
var var_field0 = sse_decode_my_network_item_pending_type(deserializer);
|
||||
return MyDownloaderStatus_Pending(var_field0);
|
||||
case 3:
|
||||
var var_field0 = sse_decode_String(deserializer);
|
||||
return MyDownloaderStatus_Error(var_field0);
|
||||
case 4:
|
||||
return const MyDownloaderStatus_Finished();
|
||||
default:
|
||||
throw UnimplementedError('');
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
MyMethod sse_decode_my_method(SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@ -582,14 +427,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
return MyMethod.values[inner];
|
||||
}
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType sse_decode_my_network_item_pending_type(
|
||||
SseDeserializer deserializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
var inner = sse_decode_i_32(deserializer);
|
||||
return MyNetworkItemPendingType.values[inner];
|
||||
}
|
||||
|
||||
@protected
|
||||
Map<String, String>? sse_decode_opt_Map_String_String(
|
||||
SseDeserializer deserializer) {
|
||||
@ -733,17 +570,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
sse_encode_u_64(self, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_download_callback_data(
|
||||
DownloadCallbackData self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_String(self.id, serializer);
|
||||
sse_encode_u_64(self.total, serializer);
|
||||
sse_encode_u_64(self.progress, serializer);
|
||||
sse_encode_u_64(self.speed, serializer);
|
||||
sse_encode_my_downloader_status(self.status, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_i_32(int self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
@ -777,39 +603,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_my_downloader_status(
|
||||
MyDownloaderStatus self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
switch (self) {
|
||||
case MyDownloaderStatus_NoStart():
|
||||
sse_encode_i_32(0, serializer);
|
||||
case MyDownloaderStatus_Running():
|
||||
sse_encode_i_32(1, serializer);
|
||||
case MyDownloaderStatus_Pending(field0: final field0):
|
||||
sse_encode_i_32(2, serializer);
|
||||
sse_encode_my_network_item_pending_type(field0, serializer);
|
||||
case MyDownloaderStatus_Error(field0: final field0):
|
||||
sse_encode_i_32(3, serializer);
|
||||
sse_encode_String(field0, serializer);
|
||||
case MyDownloaderStatus_Finished():
|
||||
sse_encode_i_32(4, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_my_method(MyMethod self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_i_32(self.index, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_my_network_item_pending_type(
|
||||
MyNetworkItemPendingType self, SseSerializer serializer) {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
sse_encode_i_32(self.index, serializer);
|
||||
}
|
||||
|
||||
@protected
|
||||
void sse_encode_opt_Map_String_String(
|
||||
Map<String, String>? self, SseSerializer serializer) {
|
||||
|
@ -3,12 +3,10 @@
|
||||
|
||||
// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field
|
||||
|
||||
import 'api/downloader_api.dart';
|
||||
import 'api/http_api.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi' as ffi;
|
||||
import 'downloader.dart';
|
||||
import 'frb_generated.dart';
|
||||
import 'http_package.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart';
|
||||
@ -47,9 +45,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
int dco_decode_box_autoadd_u_64(dynamic raw);
|
||||
|
||||
@protected
|
||||
DownloadCallbackData dco_decode_download_callback_data(dynamic raw);
|
||||
|
||||
@protected
|
||||
int dco_decode_i_32(dynamic raw);
|
||||
|
||||
@ -62,15 +57,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
List<(String, String)> dco_decode_list_record_string_string(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus dco_decode_my_downloader_status(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyMethod dco_decode_my_method(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType dco_decode_my_network_item_pending_type(dynamic raw);
|
||||
|
||||
@protected
|
||||
Map<String, String>? dco_decode_opt_Map_String_String(dynamic raw);
|
||||
|
||||
@ -124,10 +113,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
int sse_decode_box_autoadd_u_64(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
DownloadCallbackData sse_decode_download_callback_data(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
int sse_decode_i_32(SseDeserializer deserializer);
|
||||
|
||||
@ -141,17 +126,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
List<(String, String)> sse_decode_list_record_string_string(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus sse_decode_my_downloader_status(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyMethod sse_decode_my_method(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType sse_decode_my_network_item_pending_type(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
Map<String, String>? sse_decode_opt_Map_String_String(
|
||||
SseDeserializer deserializer);
|
||||
@ -211,10 +188,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
void sse_encode_box_autoadd_u_64(int self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_download_callback_data(
|
||||
DownloadCallbackData self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_i_32(int self, SseSerializer serializer);
|
||||
|
||||
@ -229,17 +202,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
void sse_encode_list_record_string_string(
|
||||
List<(String, String)> self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_downloader_status(
|
||||
MyDownloaderStatus self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_method(MyMethod self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_network_item_pending_type(
|
||||
MyNetworkItemPendingType self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_opt_Map_String_String(
|
||||
Map<String, String>? self, SseSerializer serializer);
|
||||
|
@ -3,11 +3,9 @@
|
||||
|
||||
// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field
|
||||
|
||||
import 'api/downloader_api.dart';
|
||||
import 'api/http_api.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'downloader.dart';
|
||||
import 'frb_generated.dart';
|
||||
import 'http_package.dart';
|
||||
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_web.dart';
|
||||
@ -46,9 +44,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
int dco_decode_box_autoadd_u_64(dynamic raw);
|
||||
|
||||
@protected
|
||||
DownloadCallbackData dco_decode_download_callback_data(dynamic raw);
|
||||
|
||||
@protected
|
||||
int dco_decode_i_32(dynamic raw);
|
||||
|
||||
@ -61,15 +56,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
List<(String, String)> dco_decode_list_record_string_string(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus dco_decode_my_downloader_status(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyMethod dco_decode_my_method(dynamic raw);
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType dco_decode_my_network_item_pending_type(dynamic raw);
|
||||
|
||||
@protected
|
||||
Map<String, String>? dco_decode_opt_Map_String_String(dynamic raw);
|
||||
|
||||
@ -123,10 +112,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
int sse_decode_box_autoadd_u_64(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
DownloadCallbackData sse_decode_download_callback_data(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
int sse_decode_i_32(SseDeserializer deserializer);
|
||||
|
||||
@ -140,17 +125,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
List<(String, String)> sse_decode_list_record_string_string(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyDownloaderStatus sse_decode_my_downloader_status(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyMethod sse_decode_my_method(SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
MyNetworkItemPendingType sse_decode_my_network_item_pending_type(
|
||||
SseDeserializer deserializer);
|
||||
|
||||
@protected
|
||||
Map<String, String>? sse_decode_opt_Map_String_String(
|
||||
SseDeserializer deserializer);
|
||||
@ -210,10 +187,6 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
@protected
|
||||
void sse_encode_box_autoadd_u_64(int self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_download_callback_data(
|
||||
DownloadCallbackData self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_i_32(int self, SseSerializer serializer);
|
||||
|
||||
@ -228,17 +201,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
|
||||
void sse_encode_list_record_string_string(
|
||||
List<(String, String)> self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_downloader_status(
|
||||
MyDownloaderStatus self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_method(MyMethod self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_my_network_item_pending_type(
|
||||
MyNetworkItemPendingType self, SseSerializer serializer);
|
||||
|
||||
@protected
|
||||
void sse_encode_opt_Map_String_String(
|
||||
Map<String, String>? self, SseSerializer serializer);
|
||||
|
@ -1,68 +0,0 @@
|
||||
import 'package:file_sizes/file_sizes.dart';
|
||||
import 'package:starcitizen_doctor/base/ui.dart';
|
||||
|
||||
import 'downloader_dialog_ui_model.dart';
|
||||
|
||||
class DownloaderDialogUI extends BaseUI<DownloaderDialogUIModel> {
|
||||
@override
|
||||
Widget? buildBody(BuildContext context, DownloaderDialogUIModel model) {
|
||||
return ContentDialog(
|
||||
constraints:
|
||||
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .54),
|
||||
title: const Text("文件下载..."),
|
||||
content: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text("文件名:${model.fileName}"),
|
||||
const SizedBox(height: 6),
|
||||
Text("保存位置:${model.savePath}"),
|
||||
const SizedBox(height: 6),
|
||||
Text("线程数:${model.threadCount}"),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
"文件大小: ${FileSize.getSize(model.count ?? 0)} / ${FileSize.getSize(model.total ?? 0)}"),
|
||||
const SizedBox(height: 6),
|
||||
Text("下载速度: ${FileSize.getSize(model.speed?.toInt() ?? 0)}/s"),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Text(getStatus(model)),
|
||||
const SizedBox(width: 24),
|
||||
Expanded(
|
||||
child: ProgressBar(
|
||||
value: model.progress == 100 ? null : model.progress,
|
||||
)),
|
||||
const SizedBox(width: 24),
|
||||
],
|
||||
),
|
||||
if (model.isP4kDownload) ...[
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
"提示:因网络波动,若下载进度长时间卡住或速度变慢,可尝试点击暂停下载,之后重新点击P4K分流下载。",
|
||||
style:
|
||||
TextStyle(fontSize: 13, color: Colors.white.withOpacity(.7)),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
FilledButton(
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(left: 8, right: 8, top: 2, bottom: 2),
|
||||
child: Text("暂停下载"),
|
||||
),
|
||||
onPressed: () => model.doCancel()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String getUITitle(BuildContext context, DownloaderDialogUIModel model) => "";
|
||||
|
||||
String getStatus(DownloaderDialogUIModel model) {
|
||||
if (model.progress == null && !model.isInMerging) return "准备中...";
|
||||
if (model.isInMerging) return "正在处理文件...";
|
||||
return "${model.progress?.toStringAsFixed(2) ?? "0"}% ";
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/rust/api/downloader_api.dart'
|
||||
as rust_downloader;
|
||||
import 'package:starcitizen_doctor/common/rust/downloader.dart';
|
||||
|
||||
class DownloaderDialogUIModel extends BaseUIModel {
|
||||
final String fileName;
|
||||
String savePath;
|
||||
final String downloadUrl;
|
||||
final bool showChangeSavePathDialog;
|
||||
final int threadCount;
|
||||
final bool isP4kDownload;
|
||||
|
||||
DownloaderDialogUIModel(this.fileName, this.savePath, this.downloadUrl,
|
||||
{this.showChangeSavePathDialog = false,
|
||||
this.threadCount = 1,
|
||||
this.isP4kDownload = false});
|
||||
|
||||
bool isInMerging = false;
|
||||
|
||||
String? downloadTaskId;
|
||||
|
||||
double? progress;
|
||||
int? speed;
|
||||
int? count;
|
||||
int? total;
|
||||
|
||||
@override
|
||||
void initModel() {
|
||||
super.initModel();
|
||||
_initDownload();
|
||||
}
|
||||
|
||||
_initDownload() async {
|
||||
if (showChangeSavePathDialog) {
|
||||
final userSelect = await FilePicker.platform.saveFile(
|
||||
initialDirectory: savePath,
|
||||
fileName: fileName,
|
||||
lockParentWindow: true);
|
||||
if (userSelect == null) {
|
||||
Navigator.pop(context!);
|
||||
return;
|
||||
}
|
||||
final f = File(userSelect);
|
||||
if (await f.exists()) {
|
||||
await f.delete();
|
||||
}
|
||||
savePath = userSelect;
|
||||
dPrint(savePath);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
if (savePath.endsWith("\\$fileName")) {
|
||||
savePath = savePath.substring(0, savePath.length - fileName.length - 1);
|
||||
}
|
||||
|
||||
if (isP4kDownload) {
|
||||
final box = await Hive.openBox("p4k_cache");
|
||||
await box.put(
|
||||
"last_save_dir",
|
||||
{"save_path": savePath, "file_name": fileName},
|
||||
);
|
||||
}
|
||||
|
||||
final downloaderSavePath = "$savePath//$fileName.downloading";
|
||||
try {
|
||||
rust_downloader
|
||||
.startDownload(
|
||||
url: downloadUrl,
|
||||
savePath: savePath,
|
||||
fileName: "$fileName.downloading",
|
||||
connectionCount: 10)
|
||||
.listen((event) async {
|
||||
dPrint(
|
||||
"id == ${event.id} p ==${event.progress} t==${event.total} s==${event.speed} st==${event.status}");
|
||||
|
||||
downloadTaskId = event.id;
|
||||
count = event.progress;
|
||||
if (event.total != 0) {
|
||||
total = event.total;
|
||||
}
|
||||
speed = event.speed;
|
||||
if (total != null && total != 0 && event.progress != 0) {
|
||||
progress = (event.progress / total!) * 100;
|
||||
}
|
||||
notifyListeners();
|
||||
|
||||
if (progress != null &&
|
||||
progress != 0 &&
|
||||
event.status == const MyDownloaderStatus.noStart()) {
|
||||
Navigator.pop(context!, "cancel");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.status == const MyDownloaderStatus.finished()) {
|
||||
count = total;
|
||||
isInMerging = true;
|
||||
notifyListeners();
|
||||
await File(downloaderSavePath)
|
||||
.rename(downloaderSavePath.replaceAll(".downloading", ""));
|
||||
final bsonFile = File("$downloaderSavePath.bson");
|
||||
if (await bsonFile.exists()) {
|
||||
bsonFile.delete();
|
||||
}
|
||||
Navigator.pop(context!, "$savePath\\$fileName");
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
Navigator.pop(context!, e);
|
||||
}
|
||||
}
|
||||
|
||||
doCancel() async {
|
||||
try {
|
||||
if (downloadTaskId != null) {
|
||||
await rust_downloader.cancelDownload(id: downloadTaskId!);
|
||||
downloadTaskId = null;
|
||||
} else {
|
||||
Navigator.pop(context!, "cancel");
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
@ -3,18 +3,11 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:starcitizen_doctor/api/analytics.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/conf/app_conf.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/log_helper.dart';
|
||||
import 'package:starcitizen_doctor/common/helper/system_helper.dart';
|
||||
import 'package:starcitizen_doctor/ui/tools/downloader/downloader_dialog_ui_model.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
import 'package:xml/xml.dart';
|
||||
|
||||
import 'downloader/downloader_dialog_ui.dart';
|
||||
|
||||
class ToolsUIModel extends BaseUIModel {
|
||||
bool _working = false;
|
||||
|
||||
@ -341,76 +334,76 @@ class ToolsUIModel extends BaseUIModel {
|
||||
}
|
||||
|
||||
Future<void> _downloadP4k() async {
|
||||
String savePath = scInstalledPath;
|
||||
String fileName = "Data.p4k";
|
||||
bool isResumeDownload = false;
|
||||
final box = await Hive.openBox("p4k_cache");
|
||||
var downloadUrl = AppConf.networkVersionData?.p4kDownloadUrl;
|
||||
if (downloadUrl == null || downloadUrl.isEmpty) {
|
||||
showToast(context!, "该功能维护中,请稍后再试!");
|
||||
return;
|
||||
}
|
||||
if ((await SystemHelper.getPID("\"RSI Launcher\"")).isNotEmpty) {
|
||||
showToast(context!, "RSI启动器正在运行,请先关闭启动器再使用此功能!",
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context!).size.width * .35));
|
||||
return;
|
||||
}
|
||||
final lastSavePath = (box.get("last_save_dir", defaultValue: {}) as Map);
|
||||
dPrint("lastSavePath === $lastSavePath");
|
||||
if (lastSavePath.isNotEmpty) {
|
||||
final s = lastSavePath["save_path"] ?? "";
|
||||
final f = lastSavePath["file_name"] ?? "";
|
||||
if ((await File("$s/$f.downloading").exists()) &&
|
||||
(await File("$s/$f.downloading.bson").exists())) {
|
||||
final ok = await showConfirmDialogs(context!, "是否恢复下载?",
|
||||
const Text("检测到未完成的下载,点击确认即可恢复下载,点击取消将会删除之前的临时文件,并开始一个新的下载。"));
|
||||
if (ok) {
|
||||
savePath = s;
|
||||
fileName = f;
|
||||
isResumeDownload = true;
|
||||
} else {
|
||||
// del last cache and del file
|
||||
await box.delete("last_save_dir");
|
||||
await File("$s/$f.downloading").delete();
|
||||
await File("$s/$f.downloading.bson").delete();
|
||||
}
|
||||
} else {
|
||||
// del last cache
|
||||
await box.delete("last_save_dir");
|
||||
}
|
||||
} else {
|
||||
await showToast(
|
||||
context!,
|
||||
"P4k 是星际公民的核心游戏文件,高达近 100GB,盒子提供的离线下载是为了帮助一些p4k文件下载超级慢的用户。"
|
||||
"\n\n接下来会弹窗询问您保存位置(可以选择星际公民文件夹也可以选择别处),下载完成后请确保 P4K 文件夹位于 LIVE 文件夹内,之后使用星际公民启动器校验更新即可。");
|
||||
AnalyticsApi.touch("p4k_download");
|
||||
}
|
||||
final r = await showDialog(
|
||||
context: context!,
|
||||
dismissWithEsc: false,
|
||||
builder: (context) {
|
||||
return BaseUIContainer(
|
||||
uiCreate: () => DownloaderDialogUI(),
|
||||
modelCreate: () => DownloaderDialogUIModel(
|
||||
fileName, savePath, downloadUrl,
|
||||
showChangeSavePathDialog: !isResumeDownload,
|
||||
threadCount: 10,
|
||||
isP4kDownload: true));
|
||||
});
|
||||
|
||||
if (r != null) {
|
||||
if (r == "cancel") {
|
||||
return showToast(context!, "下载进度已保留,您可以再次点击此功能恢复下载。");
|
||||
} else {
|
||||
final ok = await showConfirmDialogs(
|
||||
context!, "下载完毕!", Text("文件已保存到:$r\n\n是否查看P4K操作教程?"));
|
||||
if (ok == true) {
|
||||
launchUrlString(
|
||||
"https://citizenwiki.cn/SC%E6%B1%89%E5%8C%96%E7%9B%92%E5%AD%90#%E5%88%86%E6%B5%81%E4%B8%8B%E8%BD%BD%E6%95%99%E7%A8%8B");
|
||||
}
|
||||
}
|
||||
}
|
||||
// String savePath = scInstalledPath;
|
||||
// String fileName = "Data.p4k";
|
||||
// bool isResumeDownload = false;
|
||||
// final box = await Hive.openBox("p4k_cache");
|
||||
// var downloadUrl = AppConf.networkVersionData?.p4kDownloadUrl;
|
||||
// if (downloadUrl == null || downloadUrl.isEmpty) {
|
||||
// showToast(context!, "该功能维护中,请稍后再试!");
|
||||
// return;
|
||||
// }
|
||||
// if ((await SystemHelper.getPID("\"RSI Launcher\"")).isNotEmpty) {
|
||||
// showToast(context!, "RSI启动器正在运行,请先关闭启动器再使用此功能!",
|
||||
// constraints: BoxConstraints(
|
||||
// maxWidth: MediaQuery.of(context!).size.width * .35));
|
||||
// return;
|
||||
// }
|
||||
// final lastSavePath = (box.get("last_save_dir", defaultValue: {}) as Map);
|
||||
// dPrint("lastSavePath === $lastSavePath");
|
||||
// if (lastSavePath.isNotEmpty) {
|
||||
// final s = lastSavePath["save_path"] ?? "";
|
||||
// final f = lastSavePath["file_name"] ?? "";
|
||||
// if ((await File("$s/$f.downloading").exists()) &&
|
||||
// (await File("$s/$f.downloading.bson").exists())) {
|
||||
// final ok = await showConfirmDialogs(context!, "是否恢复下载?",
|
||||
// const Text("检测到未完成的下载,点击确认即可恢复下载,点击取消将会删除之前的临时文件,并开始一个新的下载。"));
|
||||
// if (ok) {
|
||||
// savePath = s;
|
||||
// fileName = f;
|
||||
// isResumeDownload = true;
|
||||
// } else {
|
||||
// // del last cache and del file
|
||||
// await box.delete("last_save_dir");
|
||||
// await File("$s/$f.downloading").delete();
|
||||
// await File("$s/$f.downloading.bson").delete();
|
||||
// }
|
||||
// } else {
|
||||
// // del last cache
|
||||
// await box.delete("last_save_dir");
|
||||
// }
|
||||
// } else {
|
||||
// await showToast(
|
||||
// context!,
|
||||
// "P4k 是星际公民的核心游戏文件,高达近 100GB,盒子提供的离线下载是为了帮助一些p4k文件下载超级慢的用户。"
|
||||
// "\n\n接下来会弹窗询问您保存位置(可以选择星际公民文件夹也可以选择别处),下载完成后请确保 P4K 文件夹位于 LIVE 文件夹内,之后使用星际公民启动器校验更新即可。");
|
||||
// AnalyticsApi.touch("p4k_download");
|
||||
// }
|
||||
// final r = await showDialog(
|
||||
// context: context!,
|
||||
// dismissWithEsc: false,
|
||||
// builder: (context) {
|
||||
// return BaseUIContainer(
|
||||
// uiCreate: () => DownloaderDialogUI(),
|
||||
// modelCreate: () => DownloaderDialogUIModel(
|
||||
// fileName, savePath, downloadUrl,
|
||||
// showChangeSavePathDialog: !isResumeDownload,
|
||||
// threadCount: 10,
|
||||
// isP4kDownload: true));
|
||||
// });
|
||||
//
|
||||
// if (r != null) {
|
||||
// if (r == "cancel") {
|
||||
// return showToast(context!, "下载进度已保留,您可以再次点击此功能恢复下载。");
|
||||
// } else {
|
||||
// final ok = await showConfirmDialogs(
|
||||
// context!, "下载完毕!", Text("文件已保存到:$r\n\n是否查看P4K操作教程?"));
|
||||
// if (ok == true) {
|
||||
// launchUrlString(
|
||||
// "https://citizenwiki.cn/SC%E6%B1%89%E5%8C%96%E7%9B%92%E5%AD%90#%E5%88%86%E6%B5%81%E4%B8%8B%E8%BD%BD%E6%95%99%E7%A8%8B");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Future<bool> _checkPhotographyStatus({bool? setMode}) async {
|
||||
|
@ -12,7 +12,6 @@ crate-type = ["cdylib", "staticlib"]
|
||||
|
||||
[dependencies]
|
||||
flutter_rust_bridge = "=2.0.0-dev.24"
|
||||
http-downloader = { version = "0.3.2", features = ["status-tracker", "speed-tracker", "breakpoint-resume", "bson-file-archiver"] }
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
|
||||
url = "2.5.0"
|
||||
uuid = { version = "1.7.0", features = ["v4", "fast-rng", "macro-diagnostics"] }
|
||||
|
@ -1,11 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
use crate::downloader::{do_cancel_download, do_start_download, DownloadCallbackData};
|
||||
use crate::frb_generated::StreamSink;
|
||||
|
||||
pub async fn start_download(url: String, save_path: String, file_name: String, connection_count: u8, sink: StreamSink<DownloadCallbackData>) {
|
||||
do_start_download(url, save_path, file_name, connection_count, Arc::new(sink)).await.unwrap();
|
||||
}
|
||||
|
||||
pub async fn cancel_download(id: String) {
|
||||
do_cancel_download(&id).await
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
//
|
||||
// Do not put code in `mod.rs`, but put in e.g. `simple.rs`.
|
||||
//
|
||||
|
||||
pub mod downloader_api;
|
||||
pub mod http_api;
|
||||
|
@ -1,180 +0,0 @@
|
||||
use std::collections::HashMap;
|
||||
use std::num::{NonZeroU8, NonZeroUsize};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use async_std::sync::Mutex;
|
||||
use flutter_rust_bridge::for_generated::lazy_static;
|
||||
use http_downloader::{breakpoint_resume::DownloadBreakpointResumeExtension, ExtendedHttpFileDownloader, HttpDownloaderBuilder, speed_tracker::DownloadSpeedTrackerExtension, status_tracker::DownloadStatusTrackerExtension};
|
||||
use http_downloader::bson_file_archiver::{ArchiveFilePath, BsonFileArchiverBuilder};
|
||||
use url::Url;
|
||||
use crate::frb_generated::StreamSink;
|
||||
use http_downloader::status_tracker::{DownloaderStatus, NetworkItemPendingType};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub enum MyNetworkItemPendingType {
|
||||
QueueUp,
|
||||
Starting,
|
||||
Stopping,
|
||||
Initializing,
|
||||
}
|
||||
|
||||
pub enum MyDownloaderStatus {
|
||||
NoStart,
|
||||
Running,
|
||||
Pending(MyNetworkItemPendingType),
|
||||
Error(String),
|
||||
Finished,
|
||||
}
|
||||
|
||||
pub struct DownloadCallbackData {
|
||||
pub id: String,
|
||||
pub total: u64,
|
||||
pub progress: u64,
|
||||
pub speed: u64,
|
||||
pub status: MyDownloaderStatus,
|
||||
}
|
||||
|
||||
impl DownloadCallbackData {
|
||||
pub fn new(id: String, total: u64) -> Self {
|
||||
DownloadCallbackData {
|
||||
id,
|
||||
total,
|
||||
progress: 0,
|
||||
speed: 0,
|
||||
status: MyDownloaderStatus::NoStart,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref DOWNLOADERS_MAP: Mutex<HashMap<String, Arc<ExtendedHttpFileDownloader>>> = {
|
||||
let map = HashMap::new();
|
||||
Mutex::new(map)
|
||||
};
|
||||
}
|
||||
|
||||
pub async fn do_cancel_download(id: &str) {
|
||||
let d = get_downloader(id).await;
|
||||
if d.is_none() {
|
||||
return;
|
||||
}
|
||||
d.unwrap().cancel().await
|
||||
}
|
||||
|
||||
pub async fn do_start_download(url: String, save_path: String, file_name: String, connection_count: u8, sink: Arc<StreamSink<DownloadCallbackData>>) -> anyhow::Result<()> {
|
||||
let save_dir = PathBuf::from(save_path);
|
||||
let test_url = Url::parse(&*url)?;
|
||||
|
||||
let (mut downloader, (status_state, speed_state, ..)) =
|
||||
|
||||
HttpDownloaderBuilder::new(test_url, save_dir)
|
||||
.chunk_size(NonZeroUsize::new(1024 * 1024 * 10).unwrap()) // 块大小
|
||||
.download_connection_count(NonZeroU8::new(connection_count).unwrap())
|
||||
.file_name(Option::from(file_name))
|
||||
.build((
|
||||
// 下载状态追踪扩展
|
||||
// by cargo feature "status-tracker" enable
|
||||
DownloadStatusTrackerExtension { log: true },
|
||||
// 下载速度追踪扩展
|
||||
// by cargo feature "speed-tracker" enable
|
||||
DownloadSpeedTrackerExtension { log: true },
|
||||
// 断点续传扩展,
|
||||
// by cargo feature "breakpoint-resume" enable
|
||||
DownloadBreakpointResumeExtension {
|
||||
// BsonFileArchiver by cargo feature "bson-file-archiver" enable
|
||||
download_archiver_builder: BsonFileArchiverBuilder::new(ArchiveFilePath::Suffix("bson".to_string()))
|
||||
}
|
||||
));
|
||||
|
||||
let status_state_arc = Arc::new(status_state);
|
||||
let status_state_clone = Arc::clone(&status_state_arc);
|
||||
|
||||
let id = Uuid::new_v4();
|
||||
// info!("Prepare download,准备下载");
|
||||
let download_future = downloader.prepare_download()?;
|
||||
let sink_clone = sink.clone();
|
||||
add_downloader(&id.to_string(), Arc::new(downloader)).await;
|
||||
|
||||
// 打印下载进度
|
||||
// Print download Progress
|
||||
tokio::spawn({
|
||||
let mut downloaded_len_receiver = get_downloader(&id.to_string()).await.unwrap().downloaded_len_receiver().clone();
|
||||
let total_size_future = get_downloader(&id.to_string()).await.unwrap().total_size_future();
|
||||
async move {
|
||||
let total_len = total_size_future.await;
|
||||
if let Some(total_len) = total_len {
|
||||
// info!("Total size: {:.2} Mb",total_len.get() as f64 / 1024_f64/ 1024_f64);
|
||||
sink_clone.add(DownloadCallbackData::new(id.to_string(), total_len.get())).unwrap();
|
||||
}
|
||||
|
||||
while downloaded_len_receiver.changed().await.is_ok() {
|
||||
let p = *downloaded_len_receiver.borrow();
|
||||
let _status = status_state_clone.status(); // get download status, 获取状态
|
||||
let _byte_per_second = speed_state.download_speed(); // get download speed,Byte per second,获取速度,字节每秒
|
||||
|
||||
if let Some(total_len) = total_len {
|
||||
sink_clone.add(DownloadCallbackData {
|
||||
id: id.to_string(),
|
||||
total: total_len.get(),
|
||||
progress: p,
|
||||
speed: _byte_per_second,
|
||||
status: get_my_status(_status),
|
||||
}).unwrap();
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
download_future.await?;
|
||||
let _status = status_state_arc.status();
|
||||
sink.add(DownloadCallbackData {
|
||||
id: id.to_string(),
|
||||
total: 0,
|
||||
progress: 0,
|
||||
speed: 0,
|
||||
status: get_my_status(_status),
|
||||
}).unwrap();
|
||||
remove_downloader(&id.to_string()).await;
|
||||
println!("rust downloader download complete");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_downloader(id: &str) {
|
||||
let mut downloader_map = DOWNLOADERS_MAP.lock().await;
|
||||
downloader_map.remove(id);
|
||||
}
|
||||
|
||||
async fn get_downloader(id: &str) -> Option<Arc<ExtendedHttpFileDownloader>> {
|
||||
let downloader_map = DOWNLOADERS_MAP.lock().await;
|
||||
return if let Some(downloader) = downloader_map.get(id) {
|
||||
Some(downloader.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
}
|
||||
|
||||
async fn add_downloader(id: &str, d: Arc<ExtendedHttpFileDownloader>) {
|
||||
let mut downloader_map = DOWNLOADERS_MAP.lock().await;
|
||||
downloader_map.insert(id.to_string(), d);
|
||||
}
|
||||
|
||||
fn get_my_status(_status: DownloaderStatus) -> MyDownloaderStatus {
|
||||
match _status {
|
||||
DownloaderStatus::NoStart => { MyDownloaderStatus::NoStart }
|
||||
DownloaderStatus::Running => { MyDownloaderStatus::Running }
|
||||
DownloaderStatus::Pending(n) => { MyDownloaderStatus::Pending(get_my_network_type(n)) }
|
||||
DownloaderStatus::Error(e) => { MyDownloaderStatus::Error(e) }
|
||||
DownloaderStatus::Finished => { MyDownloaderStatus::Finished }
|
||||
}
|
||||
}
|
||||
|
||||
fn get_my_network_type(n: NetworkItemPendingType) -> MyNetworkItemPendingType {
|
||||
match n {
|
||||
NetworkItemPendingType::QueueUp => { MyNetworkItemPendingType::QueueUp }
|
||||
NetworkItemPendingType::Starting => { MyNetworkItemPendingType::Starting }
|
||||
NetworkItemPendingType::Stopping => { MyNetworkItemPendingType::Stopping }
|
||||
NetworkItemPendingType::Initializing => { MyNetworkItemPendingType::Initializing }
|
||||
}
|
||||
}
|
@ -39,61 +39,6 @@ flutter_rust_bridge::frb_generated_default_handler!();
|
||||
|
||||
// Section: wire_funcs
|
||||
|
||||
fn wire_cancel_download_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
rust_vec_len_: i32,
|
||||
data_len_: i32,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::SseCodec, _, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "cancel_download",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let message = unsafe {
|
||||
flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(
|
||||
ptr_,
|
||||
rust_vec_len_,
|
||||
data_len_,
|
||||
)
|
||||
};
|
||||
let mut deserializer =
|
||||
flutter_rust_bridge::for_generated::SseDeserializer::new(message);
|
||||
let api_id = <String>::sse_decode(&mut deserializer);
|
||||
deserializer.end();
|
||||
move |context| async move {
|
||||
transform_result_sse(
|
||||
(move || async move {
|
||||
Result::<_, ()>::Ok(
|
||||
crate::api::downloader_api::cancel_download(api_id).await,
|
||||
)
|
||||
})()
|
||||
.await,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire_start_download_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
rust_vec_len_: i32,
|
||||
data_len_: i32,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::SseCodec,_,_,_>(flutter_rust_bridge::for_generated::TaskInfo{ debug_name: "start_download", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Stream }, move || {
|
||||
let message = unsafe { flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire(ptr_, rust_vec_len_, data_len_) };
|
||||
let mut deserializer = flutter_rust_bridge::for_generated::SseDeserializer::new(message);
|
||||
let api_url = <String>::sse_decode(&mut deserializer);
|
||||
let api_save_path = <String>::sse_decode(&mut deserializer);
|
||||
let api_file_name = <String>::sse_decode(&mut deserializer);
|
||||
let api_connection_count = <u8>::sse_decode(&mut deserializer);deserializer.end(); move |context| async move {
|
||||
transform_result_sse((move || async move {
|
||||
Result::<_,()>::Ok(crate::api::downloader_api::start_download(api_url, api_save_path, api_file_name, api_connection_count, StreamSink::new(context.rust2dart_context().stream_sink::<_,crate::downloader::DownloadCallbackData>())).await)
|
||||
})().await)
|
||||
} })
|
||||
}
|
||||
fn wire_dns_lookup_txt_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr,
|
||||
@ -257,24 +202,6 @@ impl SseDecode for String {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::downloader::DownloadCallbackData {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut var_id = <String>::sse_decode(deserializer);
|
||||
let mut var_total = <u64>::sse_decode(deserializer);
|
||||
let mut var_progress = <u64>::sse_decode(deserializer);
|
||||
let mut var_speed = <u64>::sse_decode(deserializer);
|
||||
let mut var_status = <crate::downloader::MyDownloaderStatus>::sse_decode(deserializer);
|
||||
return crate::downloader::DownloadCallbackData {
|
||||
id: var_id,
|
||||
total: var_total,
|
||||
progress: var_progress,
|
||||
speed: var_speed,
|
||||
status: var_status,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for i32 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -318,36 +245,6 @@ impl SseDecode for Vec<(String, String)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::downloader::MyDownloaderStatus {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut tag_ = <i32>::sse_decode(deserializer);
|
||||
match tag_ {
|
||||
0 => {
|
||||
return crate::downloader::MyDownloaderStatus::NoStart;
|
||||
}
|
||||
1 => {
|
||||
return crate::downloader::MyDownloaderStatus::Running;
|
||||
}
|
||||
2 => {
|
||||
let mut var_field0 =
|
||||
<crate::downloader::MyNetworkItemPendingType>::sse_decode(deserializer);
|
||||
return crate::downloader::MyDownloaderStatus::Pending(var_field0);
|
||||
}
|
||||
3 => {
|
||||
let mut var_field0 = <String>::sse_decode(deserializer);
|
||||
return crate::downloader::MyDownloaderStatus::Error(var_field0);
|
||||
}
|
||||
4 => {
|
||||
return crate::downloader::MyDownloaderStatus::Finished;
|
||||
}
|
||||
_ => {
|
||||
unimplemented!("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::api::http_api::MyMethod {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -367,20 +264,6 @@ impl SseDecode for crate::api::http_api::MyMethod {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::downloader::MyNetworkItemPendingType {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut inner = <i32>::sse_decode(deserializer);
|
||||
return match inner {
|
||||
0 => crate::downloader::MyNetworkItemPendingType::QueueUp,
|
||||
1 => crate::downloader::MyNetworkItemPendingType::Starting,
|
||||
2 => crate::downloader::MyNetworkItemPendingType::Stopping,
|
||||
3 => crate::downloader::MyNetworkItemPendingType::Initializing,
|
||||
_ => unreachable!("Invalid variant for MyNetworkItemPendingType: {}", inner),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for Option<std::collections::HashMap<String, String>> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -429,7 +312,7 @@ impl SseDecode for crate::http_package::RustHttpResponse {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut var_statusCode = <u16>::sse_decode(deserializer);
|
||||
let mut var_headers = <HashMap<String, String>>::sse_decode(deserializer);
|
||||
let mut var_headers = <std::collections::HashMap<String, String>>::sse_decode(deserializer);
|
||||
let mut var_url = <String>::sse_decode(deserializer);
|
||||
let mut var_contentLength = <Option<u64>>::sse_decode(deserializer);
|
||||
let mut var_version = <reqwest::Version>::sse_decode(deserializer);
|
||||
@ -496,11 +379,9 @@ fn pde_ffi_dispatcher_primary_impl(
|
||||
) {
|
||||
// Codec=Pde (Serialization + dispatch), see doc to use other codecs
|
||||
match func_id {
|
||||
2 => wire_cancel_download_impl(port, ptr, rust_vec_len, data_len),
|
||||
1 => wire_start_download_impl(port, ptr, rust_vec_len, data_len),
|
||||
5 => wire_dns_lookup_txt_impl(port, ptr, rust_vec_len, data_len),
|
||||
4 => wire_fetch_impl(port, ptr, rust_vec_len, data_len),
|
||||
3 => wire_set_default_header_impl(port, ptr, rust_vec_len, data_len),
|
||||
3 => wire_dns_lookup_txt_impl(port, ptr, rust_vec_len, data_len),
|
||||
2 => wire_fetch_impl(port, ptr, rust_vec_len, data_len),
|
||||
1 => wire_set_default_header_impl(port, ptr, rust_vec_len, data_len),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@ -550,57 +431,6 @@ impl
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::downloader::DownloadCallbackData {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
self.id.into_into_dart().into_dart(),
|
||||
self.total.into_into_dart().into_dart(),
|
||||
self.progress.into_into_dart().into_dart(),
|
||||
self.speed.into_into_dart().into_dart(),
|
||||
self.status.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::downloader::DownloadCallbackData
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::downloader::DownloadCallbackData>
|
||||
for crate::downloader::DownloadCallbackData
|
||||
{
|
||||
fn into_into_dart(self) -> crate::downloader::DownloadCallbackData {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::downloader::MyDownloaderStatus {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
match self {
|
||||
crate::downloader::MyDownloaderStatus::NoStart => [0.into_dart()].into_dart(),
|
||||
crate::downloader::MyDownloaderStatus::Running => [1.into_dart()].into_dart(),
|
||||
crate::downloader::MyDownloaderStatus::Pending(field0) => {
|
||||
[2.into_dart(), field0.into_into_dart().into_dart()].into_dart()
|
||||
}
|
||||
crate::downloader::MyDownloaderStatus::Error(field0) => {
|
||||
[3.into_dart(), field0.into_into_dart().into_dart()].into_dart()
|
||||
}
|
||||
crate::downloader::MyDownloaderStatus::Finished => [4.into_dart()].into_dart(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::downloader::MyDownloaderStatus
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::downloader::MyDownloaderStatus>
|
||||
for crate::downloader::MyDownloaderStatus
|
||||
{
|
||||
fn into_into_dart(self) -> crate::downloader::MyDownloaderStatus {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::api::http_api::MyMethod {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
match self {
|
||||
@ -628,28 +458,6 @@ impl flutter_rust_bridge::IntoIntoDart<crate::api::http_api::MyMethod>
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::downloader::MyNetworkItemPendingType {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
match self {
|
||||
Self::QueueUp => 0.into_dart(),
|
||||
Self::Starting => 1.into_dart(),
|
||||
Self::Stopping => 2.into_dart(),
|
||||
Self::Initializing => 3.into_dart(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::downloader::MyNetworkItemPendingType
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::downloader::MyNetworkItemPendingType>
|
||||
for crate::downloader::MyNetworkItemPendingType
|
||||
{
|
||||
fn into_into_dart(self) -> crate::downloader::MyNetworkItemPendingType {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::http_package::RustHttpResponse {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
@ -715,17 +523,6 @@ impl SseEncode for String {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::downloader::DownloadCallbackData {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<String>::sse_encode(self.id, serializer);
|
||||
<u64>::sse_encode(self.total, serializer);
|
||||
<u64>::sse_encode(self.progress, serializer);
|
||||
<u64>::sse_encode(self.speed, serializer);
|
||||
<crate::downloader::MyDownloaderStatus>::sse_encode(self.status, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for i32 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@ -763,31 +560,6 @@ impl SseEncode for Vec<(String, String)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::downloader::MyDownloaderStatus {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
match self {
|
||||
crate::downloader::MyDownloaderStatus::NoStart => {
|
||||
<i32>::sse_encode(0, serializer);
|
||||
}
|
||||
crate::downloader::MyDownloaderStatus::Running => {
|
||||
<i32>::sse_encode(1, serializer);
|
||||
}
|
||||
crate::downloader::MyDownloaderStatus::Pending(field0) => {
|
||||
<i32>::sse_encode(2, serializer);
|
||||
<crate::downloader::MyNetworkItemPendingType>::sse_encode(field0, serializer);
|
||||
}
|
||||
crate::downloader::MyDownloaderStatus::Error(field0) => {
|
||||
<i32>::sse_encode(3, serializer);
|
||||
<String>::sse_encode(field0, serializer);
|
||||
}
|
||||
crate::downloader::MyDownloaderStatus::Finished => {
|
||||
<i32>::sse_encode(4, serializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::api::http_api::MyMethod {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@ -811,24 +583,6 @@ impl SseEncode for crate::api::http_api::MyMethod {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::downloader::MyNetworkItemPendingType {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<i32>::sse_encode(
|
||||
match self {
|
||||
crate::downloader::MyNetworkItemPendingType::QueueUp => 0,
|
||||
crate::downloader::MyNetworkItemPendingType::Starting => 1,
|
||||
crate::downloader::MyNetworkItemPendingType::Stopping => 2,
|
||||
crate::downloader::MyNetworkItemPendingType::Initializing => 3,
|
||||
_ => {
|
||||
unimplemented!("");
|
||||
}
|
||||
},
|
||||
serializer,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for Option<std::collections::HashMap<String, String>> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
|
@ -28,6 +28,7 @@ lazy_static! {
|
||||
.use_rustls_tls()
|
||||
.connect_timeout(Duration::from_secs(10))
|
||||
.gzip(true)
|
||||
.no_proxy()
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
|
@ -1,4 +1,3 @@
|
||||
mod frb_generated;
|
||||
mod api;
|
||||
mod downloader;
|
||||
mod http_package;
|
||||
|
Loading…
Reference in New Issue
Block a user