mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
full remove action & create folder action
This commit is contained in:
parent
5aba802c80
commit
281acf7474
@ -45,14 +45,14 @@ backToHome() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef DialogBuilder = CustomAlertDialog Function(
|
typedef DialogBuilder = CustomAlertDialog Function(
|
||||||
StateSetter setState, VoidCallback close);
|
StateSetter setState, Function([dynamic]) close);
|
||||||
|
|
||||||
class DialogManager {
|
class DialogManager {
|
||||||
static BuildContext? _dialogContext;
|
static BuildContext? _dialogContext;
|
||||||
|
|
||||||
static void reset() {
|
static void reset([result]) {
|
||||||
if (_dialogContext != null) {
|
if (_dialogContext != null) {
|
||||||
Navigator.pop(_dialogContext!);
|
Navigator.pop(_dialogContext!,result);
|
||||||
}
|
}
|
||||||
_dialogContext = null;
|
_dialogContext = null;
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ class DialogManager {
|
|||||||
builder: (context) {
|
builder: (context) {
|
||||||
DialogManager.register(context);
|
DialogManager.register(context);
|
||||||
return StatefulBuilder(
|
return StatefulBuilder(
|
||||||
builder: (_, setState) => builder(setState, DialogManager.reset));
|
builder: (_, setState) => builder(setState,DialogManager.reset));
|
||||||
});
|
});
|
||||||
DialogManager.drop();
|
DialogManager.drop();
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
|
import 'package:flutter_hbb/common.dart';
|
||||||
import 'package:flutter_hbb/pages/file_manager_page.dart';
|
import 'package:flutter_hbb/pages/file_manager_page.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -16,18 +19,19 @@ enum SortBy { name, type, date, size }
|
|||||||
// FileLink = 5,
|
// FileLink = 5,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
class RemoveCompleter {}
|
||||||
|
|
||||||
typedef OnJobStateChange = void Function(JobState state, JobProgress jp);
|
typedef OnJobStateChange = void Function(JobState state, JobProgress jp);
|
||||||
|
|
||||||
// TODO 每个fd设置操作系统属性,不同的操作系统 有不同的文件连字符 封装各类Path功能
|
|
||||||
|
|
||||||
class FileModel extends ChangeNotifier {
|
class FileModel extends ChangeNotifier {
|
||||||
|
// TODO 添加 dispose 退出页面的时候清理数据以及尚未完成的任务和对话框
|
||||||
var _isLocal = false;
|
var _isLocal = false;
|
||||||
var _selectMode = false;
|
var _selectMode = false;
|
||||||
|
|
||||||
/// 每一个选择的文件或文件夹占用一个 _jobId,file_num是文件夹中的单独文件id
|
/// 每一个选择的文件或文件夹占用一个 _jobId,file_num是文件夹中的单独文件id
|
||||||
/// 如
|
/// 如
|
||||||
/// 发送单独一个文件 file_num = 0;
|
/// 发送单独一个文件 file_num = 0;
|
||||||
/// 发送一个文件夹,若文件夹下有3个文件 file_num = 2;
|
/// 发送一个文件夹,若文件夹下有3个文件 最后一个文件的 file_num = 2;
|
||||||
var _jobId = 0;
|
var _jobId = 0;
|
||||||
|
|
||||||
var _jobProgress = JobProgress(); // from rust update
|
var _jobProgress = JobProgress(); // from rust update
|
||||||
@ -54,6 +58,10 @@ class FileModel extends ChangeNotifier {
|
|||||||
|
|
||||||
FileDirectory get currentDir => _isLocal ? currentLocalDir : currentRemoteDir;
|
FileDirectory get currentDir => _isLocal ? currentLocalDir : currentRemoteDir;
|
||||||
|
|
||||||
|
final _fileFetcher = FileFetcher();
|
||||||
|
|
||||||
|
final _jobResultListener = JobResultListener<Map<String, dynamic>>();
|
||||||
|
|
||||||
toggleSelectMode() {
|
toggleSelectMode() {
|
||||||
_selectMode = !_selectMode;
|
_selectMode = !_selectMode;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -78,14 +86,29 @@ class FileModel extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
receiveFileDir(Map<String, dynamic> evt) {
|
||||||
|
_fileFetcher.tryCompleteTask(evt['value'], evt['is_local']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// job 类型 复制结束 删除结束
|
||||||
jobDone(Map<String, dynamic> evt) {
|
jobDone(Map<String, dynamic> evt) {
|
||||||
|
if (_jobResultListener.isListening) {
|
||||||
|
_jobResultListener.complete(evt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_selectMode = false;
|
||||||
_jobProgress.state = JobState.done;
|
_jobProgress.state = JobState.done;
|
||||||
refresh();
|
refresh();
|
||||||
notifyListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jobError(Map<String, dynamic> evt) {
|
jobError(Map<String, dynamic> evt) {
|
||||||
|
if (_jobResultListener.isListening) {
|
||||||
|
_jobResultListener.complete(evt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
_selectMode = false;
|
||||||
_jobProgress.clear();
|
_jobProgress.clear();
|
||||||
_jobProgress.state = JobState.error;
|
_jobProgress.state = JobState.error;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -96,30 +119,28 @@ class FileModel extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
tryUpdateDir(String fd, bool isLocal) {
|
onReady() {
|
||||||
try {
|
openDirectory(FFI.getByName("get_home_dir"), isLocal: true);
|
||||||
final fileDir = FileDirectory.fromJson(jsonDecode(fd), _sortStyle);
|
openDirectory(FFI.ffiModel.pi.homeDir, isLocal: false);
|
||||||
if (isLocal) {
|
|
||||||
_currentLocalDir = fileDir;
|
|
||||||
} else {
|
|
||||||
_currentRemoteDir = fileDir;
|
|
||||||
}
|
|
||||||
notifyListeners(); // TODO use too early, error occur:setState() or markNeedsBuild() called during build.
|
|
||||||
} catch (e) {
|
|
||||||
debugPrint("Failed to tryUpdateDir :$fd");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
openDirectory(_isLocal ? _currentLocalDir.path : _currentRemoteDir.path);
|
openDirectory(_isLocal ? _currentLocalDir.path : _currentRemoteDir.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
openDirectory(String path) {
|
openDirectory(String path, {bool? isLocal}) async {
|
||||||
if (_isLocal) {
|
isLocal = isLocal ?? _isLocal;
|
||||||
final res = FFI.getByName("read_dir", path);
|
try {
|
||||||
tryUpdateDir(res, true);
|
final fd = await _fileFetcher.fetchDirectory(path, isLocal);
|
||||||
} else {
|
fd.changeSortStyle(_sortStyle);
|
||||||
FFI.setByName("read_remote_dir", path);
|
if (isLocal) {
|
||||||
|
_currentLocalDir = fd;
|
||||||
|
} else {
|
||||||
|
_currentRemoteDir = fd;
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("Failed to openDirectory :$e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,29 +170,156 @@ class FileModel extends ChangeNotifier {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAction(SelectedItems items) {
|
bool removeCheckboxRemember = false;
|
||||||
|
|
||||||
|
removeAction(SelectedItems items) async {
|
||||||
|
removeCheckboxRemember = false;
|
||||||
if (items.isLocal == null) {
|
if (items.isLocal == null) {
|
||||||
debugPrint("Failed to removeFile ,wrong path state");
|
debugPrint("Failed to removeFile ,wrong path state");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
items.items.forEach((entry) {
|
await Future.forEach(items.items, (Entry item) async {
|
||||||
_jobId++;
|
_jobId++;
|
||||||
if (entry.isFile) {
|
var title = "";
|
||||||
// TODO dir
|
var content = "";
|
||||||
final msg = {
|
late final List<Entry> entries;
|
||||||
"id": _jobId.toString(),
|
if (item.isFile) {
|
||||||
"path": entry.path,
|
title = "是否永久删除文件";
|
||||||
"file_num": "0",
|
content = "${item.name}";
|
||||||
"is_remote": (!(items.isLocal!)).toString()
|
entries = [item];
|
||||||
};
|
} else if (item.isDirectory) {
|
||||||
debugPrint("remove :$msg");
|
title = "这不是一个空文件夹";
|
||||||
FFI.setByName("remove_file", jsonEncode(msg));
|
showLoading("正在读取...");
|
||||||
// items.remove(entry);
|
final fd = await _fileFetcher.fetchDirectoryRecursive(
|
||||||
|
_jobId, item.path, items.isLocal!);
|
||||||
|
EasyLoading.dismiss();
|
||||||
|
// 空文件夹
|
||||||
|
if(fd.entries.isEmpty){
|
||||||
|
final confirm = await showRemoveDialog("是否删除空文件夹",item.name,false);
|
||||||
|
if(confirm == true){
|
||||||
|
sendRemoveEmptyDir(item.path, 0, items.isLocal!);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
debugPrint("removeDirAllIntent res:${fd.id}");
|
||||||
|
entries = fd.entries;
|
||||||
|
} else {
|
||||||
|
debugPrint("none : ${item.toString()}");
|
||||||
|
entries = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < entries.length; i++) {
|
||||||
|
final dirShow = item.isDirectory?"是否删除文件夹下的文件?\n":"";
|
||||||
|
final count = entries.length>1?"第 ${i + 1}/${entries.length} 项":"";
|
||||||
|
content = dirShow + "$count \n${entries[i].path}";
|
||||||
|
final confirm = await showRemoveDialog(title,content,item.isDirectory);
|
||||||
|
debugPrint("已选择:$confirm");
|
||||||
|
try {
|
||||||
|
if (confirm == true) {
|
||||||
|
sendRemoveFile(entries[i].path, i, items.isLocal!);
|
||||||
|
final res = await _jobResultListener.start();
|
||||||
|
debugPrint("remove got res ${res.toString()}");
|
||||||
|
// handle remove res;
|
||||||
|
if (item.isDirectory &&
|
||||||
|
res['file_num'] == (entries.length - 1).toString()) {
|
||||||
|
sendRemoveEmptyDir(item.path, i, items.isLocal!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removeCheckboxRemember) {
|
||||||
|
if (confirm == true) {
|
||||||
|
for (var j = i + 1; j < entries.length; j++) {
|
||||||
|
sendRemoveFile(entries[j].path, j, items.isLocal!);
|
||||||
|
final res = await _jobResultListener.start();
|
||||||
|
debugPrint("remove got res ${res.toString()}");
|
||||||
|
if (item.isDirectory &&
|
||||||
|
res['file_num'] == (entries.length - 1).toString()) {
|
||||||
|
sendRemoveEmptyDir(item.path, i, items.isLocal!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
createDir(String path) {}
|
Future<bool?> showRemoveDialog(String title,String content,bool showCheckbox) async {
|
||||||
|
return await DialogManager.show<bool>(
|
||||||
|
(setState, Function(bool v) close) => CustomAlertDialog(
|
||||||
|
title: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.warning, color: Colors.red),
|
||||||
|
SizedBox(width: 20),
|
||||||
|
Text(title)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
content: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Text(content),
|
||||||
|
SizedBox(height: 5),
|
||||||
|
Text("此操作不可逆!",style: TextStyle(fontWeight: FontWeight.bold)),
|
||||||
|
showCheckbox?
|
||||||
|
CheckboxListTile(
|
||||||
|
contentPadding: const EdgeInsets.all(0),
|
||||||
|
dense: true,
|
||||||
|
controlAffinity: ListTileControlAffinity.leading,
|
||||||
|
title: Text(
|
||||||
|
"应用于文件夹下所有文件",
|
||||||
|
),
|
||||||
|
value: removeCheckboxRemember,
|
||||||
|
onChanged: (v) {
|
||||||
|
if (v == null) return;
|
||||||
|
setState(() => removeCheckboxRemember = v);
|
||||||
|
},
|
||||||
|
):SizedBox.shrink()
|
||||||
|
]),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
style: flatButtonStyle,
|
||||||
|
onPressed: () => close(true), child: Text("Yes")),
|
||||||
|
TextButton(
|
||||||
|
style: flatButtonStyle,
|
||||||
|
onPressed: () => close(false), child: Text("No"))
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
sendRemoveFile(String path, int fileNum, bool isLocal) {
|
||||||
|
final msg = {
|
||||||
|
"id": _jobId.toString(),
|
||||||
|
"path": path,
|
||||||
|
"file_num": fileNum.toString(),
|
||||||
|
"is_remote": (!(isLocal)).toString()
|
||||||
|
};
|
||||||
|
FFI.setByName("remove_file", jsonEncode(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
sendRemoveEmptyDir(String path, int fileNum, bool isLocal) {
|
||||||
|
final msg = {
|
||||||
|
"id": _jobId.toString(),
|
||||||
|
"path": path,
|
||||||
|
"is_remote": (!isLocal).toString()
|
||||||
|
};
|
||||||
|
FFI.setByName("remove_all_empty_dirs", jsonEncode(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
createDir(String path) {
|
||||||
|
_jobId ++;
|
||||||
|
final msg = {
|
||||||
|
"id": _jobId.toString(),
|
||||||
|
"path": path,
|
||||||
|
"is_remote": (!isLocal).toString()
|
||||||
|
};
|
||||||
|
FFI.setByName("create_dir",jsonEncode(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
cancelJob(int id){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
changeSortStyle(SortBy sort) {
|
changeSortStyle(SortBy sort) {
|
||||||
_sortStyle = sort;
|
_sortStyle = sort;
|
||||||
@ -186,6 +334,149 @@ class FileModel extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class JobResultListener<T> {
|
||||||
|
Completer<T>? _completer;
|
||||||
|
Timer? _timer;
|
||||||
|
int _timeoutSecond = 5;
|
||||||
|
|
||||||
|
bool get isListening => _completer != null;
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
if (_completer != null) {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
_completer!.completeError("Cancel manually");
|
||||||
|
_completer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<T> start() {
|
||||||
|
if (_completer != null) return Future.error("Already start listen");
|
||||||
|
_completer = Completer();
|
||||||
|
_timer = Timer(Duration(seconds: _timeoutSecond), () {
|
||||||
|
if (!_completer!.isCompleted) {
|
||||||
|
_completer!.completeError("Time out");
|
||||||
|
}
|
||||||
|
_completer = null;
|
||||||
|
});
|
||||||
|
return _completer!.future;
|
||||||
|
}
|
||||||
|
|
||||||
|
complete(T res) {
|
||||||
|
if (_completer != null) {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
_completer!.complete(res);
|
||||||
|
_completer = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FileFetcher {
|
||||||
|
// Map<String,Completer<FileDirectory>> localTasks = Map(); // now we only use read local dir sync
|
||||||
|
Map<String, Completer<FileDirectory>> remoteTasks = Map();
|
||||||
|
Map<int, Completer<FileDirectory>> readRecursiveTasks = Map();
|
||||||
|
|
||||||
|
Future<FileDirectory> registerReadTask(bool isLocal, String path) {
|
||||||
|
// final jobs = isLocal?localJobs:remoteJobs; // maybe we will use read local dir async later
|
||||||
|
final tasks = remoteTasks; // bypass now
|
||||||
|
if (tasks.containsKey(path)) {
|
||||||
|
throw "Failed to registerReadTask, already have same read job";
|
||||||
|
}
|
||||||
|
final c = Completer<FileDirectory>();
|
||||||
|
tasks[path] = c;
|
||||||
|
|
||||||
|
Timer(Duration(seconds: 2), () {
|
||||||
|
tasks.remove(path);
|
||||||
|
if (c.isCompleted) return; // 计时器加入map
|
||||||
|
c.completeError("Failed to read dir,timeout");
|
||||||
|
});
|
||||||
|
return c.future;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<FileDirectory> registerReadRecursiveTask(int id) {
|
||||||
|
final tasks = readRecursiveTasks;
|
||||||
|
if (tasks.containsKey(id)) {
|
||||||
|
throw "Failed to registerRemoveTask, already have same ReadRecursive job";
|
||||||
|
}
|
||||||
|
final c = Completer<FileDirectory>();
|
||||||
|
tasks[id] = c;
|
||||||
|
|
||||||
|
Timer(Duration(seconds: 2), () {
|
||||||
|
tasks.remove(id);
|
||||||
|
if (c.isCompleted) return; // 计时器加入map
|
||||||
|
c.completeError("Failed to read dir,timeout");
|
||||||
|
});
|
||||||
|
return c.future;
|
||||||
|
}
|
||||||
|
|
||||||
|
tryCompleteTask(String? msg, String? isLocalStr) {
|
||||||
|
debugPrint("tryCompleteTask : $msg");
|
||||||
|
if (msg == null || isLocalStr == null) return;
|
||||||
|
late final isLocal;
|
||||||
|
late final tasks;
|
||||||
|
if (isLocalStr == "true") {
|
||||||
|
isLocal = true;
|
||||||
|
} else if (isLocalStr == "false") {
|
||||||
|
isLocal = false;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
final fd = FileDirectory.fromJson(jsonDecode(msg));
|
||||||
|
if (fd.id > 0) {
|
||||||
|
// fd.id > 0 is result for read recursive
|
||||||
|
// TODO later,will be better if every fetch use ID,so that there will only one task map for read and recursive read
|
||||||
|
tasks = readRecursiveTasks;
|
||||||
|
final completer = tasks.remove(fd.id);
|
||||||
|
completer?.complete(fd);
|
||||||
|
} else if (fd.path.isNotEmpty) {
|
||||||
|
// result for normal read dir
|
||||||
|
// final jobs = isLocal?localJobs:remoteJobs; // maybe we will use read local dir async later
|
||||||
|
tasks = remoteTasks; // bypass now
|
||||||
|
final completer = tasks.remove(fd.path);
|
||||||
|
completer?.complete(fd);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("tryCompleteJob err :$e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<FileDirectory> fetchDirectory(String path, bool isLocal) async {
|
||||||
|
debugPrint("fetch :$path");
|
||||||
|
try {
|
||||||
|
if (isLocal) {
|
||||||
|
final res = FFI.getByName("read_dir", path);
|
||||||
|
final fd = FileDirectory.fromJson(jsonDecode(res));
|
||||||
|
return fd;
|
||||||
|
} else {
|
||||||
|
FFI.setByName("read_remote_dir", path);
|
||||||
|
return registerReadTask(isLocal, path);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return Future.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<FileDirectory> fetchDirectoryRecursive(
|
||||||
|
int id, String path, bool isLocal) async {
|
||||||
|
debugPrint("fetchDirectoryRecursive id:$id , path:$path");
|
||||||
|
try {
|
||||||
|
final msg = {
|
||||||
|
"id": id.toString(),
|
||||||
|
"path": path,
|
||||||
|
"is_remote": (!isLocal).toString()
|
||||||
|
};
|
||||||
|
FFI.setByName("read_dir_recursive", jsonEncode(msg));
|
||||||
|
return registerReadRecursiveTask(id);
|
||||||
|
} catch (e) {
|
||||||
|
return Future.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class FileDirectory {
|
class FileDirectory {
|
||||||
List<Entry> entries = [];
|
List<Entry> entries = [];
|
||||||
int id = 0;
|
int id = 0;
|
||||||
@ -195,7 +486,7 @@ class FileDirectory {
|
|||||||
|
|
||||||
FileDirectory();
|
FileDirectory();
|
||||||
|
|
||||||
FileDirectory.fromJson(Map<String, dynamic> json, SortBy sort) {
|
FileDirectory.fromJsonWithSort(Map<String, dynamic> json, SortBy sort) {
|
||||||
id = json['id'];
|
id = json['id'];
|
||||||
path = json['path'];
|
path = json['path'];
|
||||||
if (json['entries'] != null) {
|
if (json['entries'] != null) {
|
||||||
@ -207,6 +498,17 @@ class FileDirectory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileDirectory.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
path = json['path'];
|
||||||
|
if (json['entries'] != null) {
|
||||||
|
entries = <Entry>[];
|
||||||
|
json['entries'].forEach((v) {
|
||||||
|
entries.add(new Entry.fromJsonWithPath(v, path));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
changeSortStyle(SortBy sort) {
|
changeSortStyle(SortBy sort) {
|
||||||
entries = _sortList(entries, sort);
|
entries = _sortList(entries, sort);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -135,7 +135,8 @@ class FfiModel with ChangeNotifier {
|
|||||||
} else if (name == 'chat') {
|
} else if (name == 'chat') {
|
||||||
FFI.chatModel.receive(evt['text'] ?? "");
|
FFI.chatModel.receive(evt['text'] ?? "");
|
||||||
} else if (name == 'file_dir') {
|
} else if (name == 'file_dir') {
|
||||||
FFI.fileModel.tryUpdateDir(evt['value'] ?? "",false);
|
// FFI.fileModel.fileFetcher.tryCompleteTask(evt['value'],evt['is_local']);
|
||||||
|
FFI.fileModel.receiveFileDir(evt);
|
||||||
} else if (name == 'job_progress'){
|
} else if (name == 'job_progress'){
|
||||||
FFI.fileModel.tryUpdateJobProgress(evt);
|
FFI.fileModel.tryUpdateJobProgress(evt);
|
||||||
} else if (name == 'job_done'){
|
} else if (name == 'job_done'){
|
||||||
@ -185,29 +186,36 @@ class FfiModel with ChangeNotifier {
|
|||||||
|
|
||||||
void handlePeerInfo(Map<String, dynamic> evt, BuildContext context) {
|
void handlePeerInfo(Map<String, dynamic> evt, BuildContext context) {
|
||||||
EasyLoading.dismiss();
|
EasyLoading.dismiss();
|
||||||
|
DialogManager.reset();
|
||||||
_pi.version = evt['version'];
|
_pi.version = evt['version'];
|
||||||
_pi.username = evt['username'];
|
_pi.username = evt['username'];
|
||||||
_pi.hostname = evt['hostname'];
|
_pi.hostname = evt['hostname'];
|
||||||
_pi.platform = evt['platform'];
|
_pi.platform = evt['platform'];
|
||||||
_pi.sasEnabled = evt['sas_enabled'] == "true";
|
_pi.sasEnabled = evt['sas_enabled'] == "true";
|
||||||
_pi.currentDisplay = int.parse(evt['current_display']);
|
_pi.currentDisplay = int.parse(evt['current_display']);
|
||||||
List<dynamic> displays = json.decode(evt['displays']);
|
_pi.homeDir = evt['home_dir'];
|
||||||
_pi.displays = [];
|
|
||||||
for (int i = 0; i < displays.length; ++i) {
|
if(evt['is_file_transfer'] == "true"){
|
||||||
Map<String, dynamic> d0 = displays[i];
|
FFI.fileModel.onReady();
|
||||||
var d = Display();
|
}else{
|
||||||
d.x = d0['x'].toDouble();
|
_pi.displays = [];
|
||||||
d.y = d0['y'].toDouble();
|
List<dynamic> displays = json.decode(evt['displays']);
|
||||||
d.width = d0['width'];
|
for (int i = 0; i < displays.length; ++i) {
|
||||||
d.height = d0['height'];
|
Map<String, dynamic> d0 = displays[i];
|
||||||
_pi.displays.add(d);
|
var d = Display();
|
||||||
}
|
d.x = d0['x'].toDouble();
|
||||||
if (_pi.currentDisplay < _pi.displays.length) {
|
d.y = d0['y'].toDouble();
|
||||||
_display = _pi.displays[_pi.currentDisplay];
|
d.width = d0['width'];
|
||||||
}
|
d.height = d0['height'];
|
||||||
if (displays.length > 0) {
|
_pi.displays.add(d);
|
||||||
showLoading(translate('Connected, waiting for image...'));
|
}
|
||||||
_waitForImage = true;
|
if (_pi.currentDisplay < _pi.displays.length) {
|
||||||
|
_display = _pi.displays[_pi.currentDisplay];
|
||||||
|
}
|
||||||
|
if (displays.length > 0) {
|
||||||
|
showLoading(translate('Connected, waiting for image...'));
|
||||||
|
_waitForImage = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
@ -918,6 +926,7 @@ class PeerInfo {
|
|||||||
String username = "";
|
String username = "";
|
||||||
String hostname = "";
|
String hostname = "";
|
||||||
String platform = "";
|
String platform = "";
|
||||||
|
String homeDir = "";
|
||||||
bool sasEnabled = false;
|
bool sasEnabled = false;
|
||||||
int currentDisplay = 0;
|
int currentDisplay = 0;
|
||||||
List<Display> displays = [];
|
List<Display> displays = [];
|
||||||
|
|||||||
@ -32,12 +32,8 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
showLoading(translate('Connecting...'));
|
showLoading(translate('Connecting...'));
|
||||||
FFI.connect(widget.id, isFileTransfer: true);
|
FFI.connect(widget.id, isFileTransfer: true);
|
||||||
|
|
||||||
final res = FFI.getByName("read_dir", FFI.getByName("get_home_dir"));
|
|
||||||
debugPrint("read_dir local :$res");
|
|
||||||
model.tryUpdateDir(res, true);
|
|
||||||
|
|
||||||
_interval = Timer.periodic(Duration(milliseconds: 30),
|
_interval = Timer.periodic(Duration(milliseconds: 30),
|
||||||
(timer) => FFI.ffiModel.update(widget.id, context, handleMsgBox));
|
(timer) => FFI.ffiModel.update(widget.id, context, handleMsgBox));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -98,45 +94,49 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
headTools(),
|
headTools(),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: entries.length + 1,
|
itemCount: entries.length + 1,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
if (index >= entries.length) {
|
if (index >= entries.length) {
|
||||||
// 添加尾部信息 文件统计信息等
|
// 添加尾部信息 文件统计信息等
|
||||||
// 添加快速返回上部
|
// 添加快速返回上部
|
||||||
// 使用 bottomSheet 提示以选择的文件数量 点击后展开查看更多
|
// 使用 bottomSheet 提示以选择的文件数量 点击后展开查看更多
|
||||||
return listTail();
|
return listTail();
|
||||||
}
|
}
|
||||||
var selected = false;
|
var selected = false;
|
||||||
if (model.selectMode) {
|
if (model.selectMode) {
|
||||||
selected = _selectedItems.contains(entries[index]);
|
selected = _selectedItems.contains(entries[index]);
|
||||||
}
|
}
|
||||||
var sizeStr = "";
|
var sizeStr = "";
|
||||||
if(entries[index].isFile){
|
if (entries[index].isFile) {
|
||||||
final size = entries[index].size;
|
final size = entries[index].size;
|
||||||
if(size< 1024){
|
if (size < 1024) {
|
||||||
sizeStr += size.toString() + "B";
|
sizeStr += size.toString() + "B";
|
||||||
}else if(size< 1024 * 1024){
|
} else if (size < 1024 * 1024) {
|
||||||
sizeStr += (size/1024).toStringAsFixed(2) + "kB";
|
sizeStr += (size / 1024).toStringAsFixed(2) + "kB";
|
||||||
}else if(size < 1024 * 1024 * 1024){
|
} else if (size < 1024 * 1024 * 1024) {
|
||||||
sizeStr += (size/1024/1024).toStringAsFixed(2) + "MB";
|
sizeStr += (size / 1024 / 1024).toStringAsFixed(2) + "MB";
|
||||||
}else if(size < 1024 * 1024 * 1024 * 1024){
|
} else if (size < 1024 * 1024 * 1024 * 1024) {
|
||||||
sizeStr += (size/1024/1024/1024).toStringAsFixed(2) + "GB";
|
sizeStr += (size / 1024 / 1024 / 1024).toStringAsFixed(2) + "GB";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Card(
|
return Card(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: Icon(
|
leading: Icon(
|
||||||
entries[index].isFile ? Icons.feed_outlined : Icons
|
entries[index].isFile ? Icons.feed_outlined : Icons.folder,
|
||||||
.folder,
|
size: 40),
|
||||||
size: 40),
|
title: Text(entries[index].name),
|
||||||
|
selected: selected,
|
||||||
title: Text(entries[index].name),
|
subtitle: Text(
|
||||||
selected: selected,
|
entries[index]
|
||||||
subtitle: Text(
|
.lastModified()
|
||||||
entries[index].lastModified().toString().replaceAll(
|
.toString()
|
||||||
".000", "") + " " + sizeStr,style: TextStyle(fontSize: 12,color: MyTheme.darkGray),),
|
.replaceAll(".000", "") +
|
||||||
trailing: needShowCheckBox()
|
" " +
|
||||||
? Checkbox(
|
sizeStr,
|
||||||
|
style: TextStyle(fontSize: 12, color: MyTheme.darkGray),
|
||||||
|
),
|
||||||
|
trailing: needShowCheckBox()
|
||||||
|
? Checkbox(
|
||||||
value: selected,
|
value: selected,
|
||||||
onChanged: (v) {
|
onChanged: (v) {
|
||||||
if (v == null) return;
|
if (v == null) return;
|
||||||
@ -147,37 +147,57 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
}
|
}
|
||||||
setState(() {});
|
setState(() {});
|
||||||
})
|
})
|
||||||
: null,
|
: PopupMenuButton<String>(
|
||||||
onTap: () {
|
icon: Icon(Icons.more_vert),
|
||||||
if (model.selectMode &&
|
itemBuilder: (context) {
|
||||||
!_selectedItems.isOtherPage(isLocal)) {
|
return [
|
||||||
if (selected) {
|
PopupMenuItem(
|
||||||
_selectedItems.remove(entries[index]);
|
child: Text("删除"),
|
||||||
} else {
|
value: "delete",
|
||||||
_selectedItems.add(isLocal, entries[index]);
|
),
|
||||||
}
|
PopupMenuItem(
|
||||||
setState(() {});
|
child: Text("详细信息"),
|
||||||
return;
|
value: "delete",
|
||||||
}
|
enabled: false,
|
||||||
if (entries[index].isDirectory) {
|
)
|
||||||
model.openDirectory(entries[index].path);
|
];
|
||||||
breadCrumbScrollToEnd();
|
},
|
||||||
} else {
|
onSelected: (v) {
|
||||||
// Perform file-related tasks.
|
if (v == "delete") {
|
||||||
}
|
final items = SelectedItems();
|
||||||
},
|
items.add(isLocal, entries[index]);
|
||||||
onLongPress: () {
|
model.removeAction(items);
|
||||||
_selectedItems.clear();
|
}
|
||||||
model.toggleSelectMode();
|
}),
|
||||||
if (model.selectMode) {
|
onTap: () {
|
||||||
_selectedItems.add(isLocal, entries[index]);
|
if (model.selectMode && !_selectedItems.isOtherPage(isLocal)) {
|
||||||
}
|
if (selected) {
|
||||||
setState(() {});
|
_selectedItems.remove(entries[index]);
|
||||||
},
|
} else {
|
||||||
),
|
_selectedItems.add(isLocal, entries[index]);
|
||||||
);
|
}
|
||||||
},
|
setState(() {});
|
||||||
))
|
return;
|
||||||
|
}
|
||||||
|
if (entries[index].isDirectory) {
|
||||||
|
model.openDirectory(entries[index].path);
|
||||||
|
breadCrumbScrollToEnd();
|
||||||
|
} else {
|
||||||
|
// Perform file-related tasks.
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLongPress: () {
|
||||||
|
_selectedItems.clear();
|
||||||
|
model.toggleSelectMode();
|
||||||
|
if (model.selectMode) {
|
||||||
|
_selectedItems.add(isLocal, entries[index]);
|
||||||
|
}
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,68 +243,101 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget headTools() =>
|
Widget headTools() => Container(
|
||||||
Container(
|
|
||||||
child: Row(
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: BreadCrumb(
|
||||||
|
items: getPathBreadCrumbItems(() => debugPrint("pressed home"),
|
||||||
|
(e) => debugPrint("pressed url:$e")),
|
||||||
|
divider: Icon(Icons.chevron_right),
|
||||||
|
overflow: ScrollableOverflow(controller: _breadCrumbScroller),
|
||||||
|
)),
|
||||||
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
// IconButton(onPressed: () {}, icon: Icon(Icons.sort)),
|
||||||
child: BreadCrumb(
|
PopupMenuButton<SortBy>(
|
||||||
items: getPathBreadCrumbItems(() =>
|
icon: Icon(Icons.sort),
|
||||||
debugPrint("pressed home"),
|
itemBuilder: (context) {
|
||||||
(e) => debugPrint("pressed url:$e")),
|
return SortBy.values
|
||||||
divider: Icon(Icons.chevron_right),
|
.map((e) => PopupMenuItem(
|
||||||
overflow: ScrollableOverflow(
|
|
||||||
controller: _breadCrumbScroller),
|
|
||||||
)),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
// IconButton(onPressed: () {}, icon: Icon(Icons.sort)),
|
|
||||||
PopupMenuButton<SortBy>(
|
|
||||||
icon: Icon(Icons.sort),
|
|
||||||
itemBuilder: (context) {
|
|
||||||
return SortBy.values
|
|
||||||
.map((e) =>
|
|
||||||
PopupMenuItem(
|
|
||||||
child:
|
child:
|
||||||
Text(translate(e
|
Text(translate(e.toString().split(".").last)),
|
||||||
.toString()
|
|
||||||
.split(".")
|
|
||||||
.last)),
|
|
||||||
value: e,
|
value: e,
|
||||||
))
|
))
|
||||||
.toList();
|
.toList();
|
||||||
},
|
},
|
||||||
onSelected: model.changeSortStyle),
|
onSelected: model.changeSortStyle),
|
||||||
PopupMenuButton<String>(
|
PopupMenuButton<String>(
|
||||||
icon: Icon(Icons.more_vert),
|
icon: Icon(Icons.more_vert),
|
||||||
itemBuilder: (context) {
|
itemBuilder: (context) {
|
||||||
return [
|
return [
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [Icon(Icons.refresh), Text("刷新")],
|
children: [Icon(Icons.refresh), Text("刷新")],
|
||||||
),
|
),
|
||||||
value: "refresh",
|
value: "refresh",
|
||||||
),
|
),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [Icon(Icons.check), Text("多选")],
|
children: [Icon(Icons.check), Text("多选")],
|
||||||
),
|
),
|
||||||
value: "select",
|
value: "select",
|
||||||
)
|
),
|
||||||
];
|
PopupMenuItem(
|
||||||
},
|
child: Row(
|
||||||
onSelected: (v) {
|
children: [
|
||||||
if (v == "refresh") {
|
Icon(Icons.folder),
|
||||||
model.refresh();
|
Text(translate("Create Folder"))
|
||||||
} else if (v == "select") {
|
],
|
||||||
_selectedItems.clear();
|
),
|
||||||
model.toggleSelectMode();
|
value: "folder",
|
||||||
}
|
)
|
||||||
}),
|
];
|
||||||
],
|
},
|
||||||
)
|
onSelected: (v) {
|
||||||
|
if (v == "refresh") {
|
||||||
|
model.refresh();
|
||||||
|
} else if (v == "select") {
|
||||||
|
_selectedItems.clear();
|
||||||
|
model.toggleSelectMode();
|
||||||
|
} else if (v == "folder") {
|
||||||
|
final name = TextEditingController();
|
||||||
|
DialogManager.show((setState, close) => CustomAlertDialog(
|
||||||
|
title: Text(translate("Create Folder")),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
TextFormField(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: translate(
|
||||||
|
"Please enter the folder name"),
|
||||||
|
),
|
||||||
|
controller: name,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
style: flatButtonStyle,
|
||||||
|
onPressed: () {
|
||||||
|
if (name.value.text.isNotEmpty) {
|
||||||
|
model.createDir(Path.join(model.currentDir.path,name.value.text));
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Text(translate("OK"))),
|
||||||
|
TextButton(
|
||||||
|
style: flatButtonStyle,
|
||||||
|
onPressed: () => close(false),
|
||||||
|
child: Text(translate("Cancel")))
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
));
|
)
|
||||||
|
],
|
||||||
|
));
|
||||||
|
|
||||||
Widget emptyPage() {
|
Widget emptyPage() {
|
||||||
return Column(
|
return Column(
|
||||||
@ -319,7 +372,7 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(Icons.delete_forever),
|
icon: Icon(Icons.delete_forever),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if(_selectedItems.length>0){
|
if (_selectedItems.length > 0) {
|
||||||
model.removeAction(_selectedItems);
|
model.removeAction(_selectedItems);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -337,7 +390,6 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
icon: Icon(Icons.paste),
|
icon: Icon(Icons.paste),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
model.toggleSelectMode();
|
model.toggleSelectMode();
|
||||||
// TODO
|
|
||||||
model.sendFiles(_selectedItems);
|
model.sendFiles(_selectedItems);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -350,21 +402,21 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
return BottomSheetBody(
|
return BottomSheetBody(
|
||||||
leading: CircularProgressIndicator(),
|
leading: CircularProgressIndicator(),
|
||||||
title: "正在发送文件...",
|
title: "正在发送文件...",
|
||||||
text: "速度: ${(model.jobProgress.speed / 1024).toStringAsFixed(
|
text:
|
||||||
2)} kb/s",
|
"速度: ${(model.jobProgress.speed / 1024).toStringAsFixed(2)} kb/s",
|
||||||
onCanceled: null,
|
onCanceled: null,
|
||||||
);
|
);
|
||||||
case JobState.done:
|
case JobState.done:
|
||||||
return BottomSheetBody(
|
return BottomSheetBody(
|
||||||
leading: Icon(Icons.check),
|
leading: Icon(Icons.check),
|
||||||
title: "发送成功!",
|
title: "操作成功!",
|
||||||
text: "",
|
text: "",
|
||||||
onCanceled: () => model.jobReset(),
|
onCanceled: () => model.jobReset(),
|
||||||
);
|
);
|
||||||
case JobState.error:
|
case JobState.error:
|
||||||
return BottomSheetBody(
|
return BottomSheetBody(
|
||||||
leading: Icon(Icons.error),
|
leading: Icon(Icons.error),
|
||||||
title: "发送错误!",
|
title: "错误!",
|
||||||
text: "",
|
text: "",
|
||||||
onCanceled: () => model.jobReset(),
|
onCanceled: () => model.jobReset(),
|
||||||
);
|
);
|
||||||
@ -374,35 +426,35 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BreadCrumbItem> getPathBreadCrumbItems(void Function() onHome,
|
List<BreadCrumbItem> getPathBreadCrumbItems(
|
||||||
void Function(String) onPressed) {
|
void Function() onHome, void Function(String) onPressed) {
|
||||||
final path = model.currentDir.path;
|
final path = model.currentDir.path;
|
||||||
final list = Path.split(path);
|
final list = Path.split(path);
|
||||||
list.remove('/');
|
list.remove('/');
|
||||||
final breadCrumbList = [
|
final breadCrumbList = [
|
||||||
BreadCrumbItem(
|
BreadCrumbItem(
|
||||||
content: IconButton(
|
content: IconButton(
|
||||||
icon: Icon(Icons.home_filled),
|
icon: Icon(Icons.home_filled),
|
||||||
onPressed: onHome,
|
onPressed: onHome,
|
||||||
))
|
))
|
||||||
];
|
];
|
||||||
breadCrumbList.addAll(list.map((e) =>
|
breadCrumbList.addAll(list.map((e) => BreadCrumbItem(
|
||||||
BreadCrumbItem(
|
content: TextButton(
|
||||||
content: TextButton(
|
child: Text(e),
|
||||||
child: Text(e),
|
style:
|
||||||
style:
|
|
||||||
ButtonStyle(minimumSize: MaterialStateProperty.all(Size(0, 0))),
|
ButtonStyle(minimumSize: MaterialStateProperty.all(Size(0, 0))),
|
||||||
onPressed: () => onPressed(e)))));
|
onPressed: () => onPressed(e)))));
|
||||||
return breadCrumbList;
|
return breadCrumbList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BottomSheetBody extends StatelessWidget {
|
class BottomSheetBody extends StatelessWidget {
|
||||||
BottomSheetBody({required this.leading,
|
BottomSheetBody(
|
||||||
required this.title,
|
{required this.leading,
|
||||||
required this.text,
|
required this.title,
|
||||||
this.onCanceled,
|
required this.text,
|
||||||
this.actions});
|
this.onCanceled,
|
||||||
|
this.actions});
|
||||||
|
|
||||||
final Widget leading;
|
final Widget leading;
|
||||||
final String title;
|
final String title;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user