opt.: cancel sftp mission

This commit is contained in:
lollipopkit
2023-07-29 18:24:22 +08:00
parent e13c5910ec
commit 0f83d10bfa
12 changed files with 277 additions and 230 deletions

View File

@@ -24,6 +24,8 @@ class PathWithPrefix {
_path = pathJoin(_path, newPath);
}
bool get canBack => path != '$_prefixPath/';
bool undo() {
if (_prePath == null || _path == _prePath) {
return false;

View File

@@ -94,7 +94,7 @@ Future<void> _download(
return;
}
// Read 10m each time
const defaultChunkSize = 1024 * 1024 * 10;
const defaultChunkSize = 1024 * 1024;
final chunkSize = size > defaultChunkSize ? defaultChunkSize : size;
mainSendPort.send(size);
mainSendPort.send(SftpWorkerStatus.downloading);

View File

@@ -8,21 +8,8 @@ class SftpProvider extends ProviderBase {
final List<SftpReqStatus> _status = [];
List<SftpReqStatus> get status => _status;
Iterable<SftpReqStatus> gets({int? id, String? fileName}) {
Iterable<SftpReqStatus> found = [];
if (id != null) {
found = _status.where((e) => e.id == id);
}
if (fileName != null) {
found = found.where((e) => e.req.localPath.split('/').last == fileName);
}
return found;
}
SftpReqStatus? get({int? id, String? name}) {
final found = gets(id: id, fileName: name);
if (found.isEmpty) return null;
return found.first;
SftpReqStatus? get(int id) {
return _status.singleWhere((element) => element.id == id);
}
void add(SftpReq req, {Completer? completer}) {
@@ -32,4 +19,19 @@ class SftpProvider extends ProviderBase {
req: req,
));
}
@override
void dispose() {
for (final item in _status) {
item.worker.dispose();
}
super.dispose();
}
void cancel(int id) {
final idx = _status.indexWhere((element) => element.id == id);
_status[idx].worker.dispose();
_status.removeAt(idx);
notifyListeners();
}
}