fix remote home dir

This commit is contained in:
csf 2022-04-07 16:20:32 +08:00
parent e780fd9253
commit 1ab99075ce
4 changed files with 80 additions and 47 deletions

View File

@ -76,6 +76,7 @@ class MainActivity : FlutterActivity() {
"request_permission" -> {
if(call.arguments is String){
requestPermission(context, call.arguments as String)
result.success(true)
} else {
result.success(false)
}

View File

@ -11,14 +11,6 @@ import 'model.dart';
enum SortBy { Name, Type, Modified, Size }
// enum FileType {
// Dir = 0,
// DirLink = 2,
// DirDrive = 3,
// File = 4,
// FileLink = 5,
// }
class FileModel extends ChangeNotifier {
var _isLocal = false;
var _selectMode = false;
@ -55,15 +47,15 @@ class FileModel extends ChangeNotifier {
String get currentHome => _isLocal ? _localOption.home : _remoteOption.home;
String get currentShortPath {
if(currentDir.path.startsWith(currentHome)){
if (currentDir.path.startsWith(currentHome)) {
var path = currentDir.path.replaceFirst(currentHome, "");
if(path.length ==0 ) return "";
if(path[0] == "/" || path[0] == "\\") {
if (path.length == 0) return "";
if (path[0] == "/" || path[0] == "\\") {
// remove more '/' or '\'
path = path.replaceFirst(path[0], "");
}
return path;
}else{
} else {
return currentDir.path.replaceFirst(currentHome, "");
}
}
@ -112,6 +104,17 @@ class FileModel extends ChangeNotifier {
}
receiveFileDir(Map<String, dynamic> evt) {
if (_remoteOption.home.isEmpty && evt['is_local'] == "false") {
// init remote home, the connection will automatic read remote home when established,
try {
final fd = FileDirectory.fromJson(jsonDecode(evt['value']));
fd.format(_remoteOption.isWindows, sort: _sortStyle);
_remoteOption.home = fd.path;
_currentRemoteDir = fd;
notifyListeners();
return;
} finally {}
}
_fileFetcher.tryCompleteTask(evt['value'], evt['is_local']);
}
@ -143,29 +146,30 @@ class FileModel extends ChangeNotifier {
notifyListeners();
}
onReady() {
_localOption = DirectoryOption(
home: FFI.getByName("get_home_dir"),
showHidden: FFI.getByName("peer_option", "local_show_hidden") != "");
_remoteOption = DirectoryOption(
home: FFI.ffiModel.pi.homeDir,
showHidden: FFI.getByName("peer_option", "remote_show_hidden") != "",
isWindows: FFI.ffiModel.pi.platform == "Windows");
onReady() async {
_localOption.home = FFI.getByName("get_home_dir");
_localOption.showHidden =
FFI.getByName("peer_option", "local_show_hidden").isNotEmpty;
_remoteOption.showHidden =
FFI.getByName("peer_option", "remote_show_hidden").isNotEmpty;
_remoteOption.isWindows = FFI.ffiModel.pi.platform == "Windows";
debugPrint("remote platform: ${FFI.ffiModel.pi.platform}");
await Future.delayed(Duration(milliseconds: 100));
final local = FFI.getByName("peer_option", "local_dir");
final remote = FFI.getByName("peer_option", "remote_dir");
openDirectory(local.isEmpty ? _localOption.home : local, isLocal: true);
openDirectory(remote.isEmpty ? _remoteOption.home : remote, isLocal: false);
Timer(Duration(seconds: 2), () {
if (_currentLocalDir.path.isEmpty) {
openDirectory(_localOption.home, isLocal: true);
}
if (_currentRemoteDir.path.isEmpty) {
openDirectory(_remoteOption.home, isLocal: false);
}
});
await Future.delayed(Duration(seconds: 1));
if (_currentLocalDir.path.isEmpty) {
openDirectory(_localOption.home, isLocal: true);
}
if (_currentRemoteDir.path.isEmpty) {
openDirectory(_remoteOption.home, isLocal: false);
}
}
onClose() {
@ -192,6 +196,8 @@ class FileModel extends ChangeNotifier {
FFI.setByName('peer_option', jsonEncode(msg));
_currentLocalDir.clear();
_currentRemoteDir.clear();
_localOption.clear();
_remoteOption.clear();
}
refresh() {
@ -278,7 +284,11 @@ class FileModel extends ChangeNotifier {
fd.format(isWindows);
EasyLoading.dismiss();
if (fd.entries.isEmpty) {
final confirm = await showRemoveDialog(translate("Are you sure you want to delete this empty directory?"), item.name, false);
final confirm = await showRemoveDialog(
translate(
"Are you sure you want to delete this empty directory?"),
item.name,
false);
if (confirm == true) {
sendRemoveEmptyDir(item.path, 0, items.isLocal!);
}
@ -290,9 +300,10 @@ class FileModel extends ChangeNotifier {
}
for (var i = 0; i < entries.length; i++) {
final dirShow = item.isDirectory ? "${translate("Are you sure you want to delete the file of this directory?")}\n" : "";
final count =
entries.length > 1 ? "${i + 1}/${entries.length}" : "";
final dirShow = item.isDirectory
? "${translate("Are you sure you want to delete the file of this directory?")}\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);
@ -403,7 +414,7 @@ class FileModel extends ChangeNotifier {
}
cancelJob(int id) {
FFI.setByName("cancel_job",id.toString());
FFI.setByName("cancel_job", id.toString());
}
changeSortStyle(SortBy sort) {
@ -668,6 +679,12 @@ class DirectoryOption {
DirectoryOption(
{this.home = "", this.showHidden = false, this.isWindows = false});
clear() {
home = "";
showHidden = false;
isWindows = false;
}
}
// code from file_manager pkg after edit

View File

@ -236,7 +236,6 @@ class FfiModel with ChangeNotifier {
_pi.platform = evt['platform'];
_pi.sasEnabled = evt['sas_enabled'] == "true";
_pi.currentDisplay = int.parse(evt['current_display']);
_pi.homeDir = evt['home_dir'];
if (evt['is_file_transfer'] == "true") {
FFI.fileModel.onReady();
@ -879,7 +878,6 @@ class PeerInfo {
String username = "";
String hostname = "";
String platform = "";
String homeDir = "";
bool sasEnabled = false;
int currentDisplay = 0;
List<Display> displays = [];

View File

@ -4,6 +4,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_hbb/models/file_model.dart';
import 'package:provider/provider.dart';
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
import 'package:toggle_switch/toggle_switch.dart';
import '../common.dart';
import '../models/model.dart';
@ -58,18 +59,26 @@ class _FileManagerPageState extends State<FileManagerPage> {
backgroundColor: MyTheme.grayBg,
appBar: AppBar(
leading: Row(children: [
IconButton(icon: Icon(Icons.arrow_back), onPressed: goBack),
IconButton(icon: Icon(Icons.close), onPressed: clientClose),
]),
leadingWidth: 200,
centerTitle: true,
title: Text(translate(model.isLocal ? "Local" : "Remote")),
actions: [
IconButton(
icon: Icon(Icons.change_circle),
onPressed: () => model.togglePage(),
)
],
title: ToggleSwitch(
initialLabelIndex: model.isLocal ? 0 : 1,
activeBgColor: [MyTheme.idColor],
inactiveBgColor: MyTheme.grayBg,
totalSwitches: 2,
minWidth: 100,
fontSize: 15,
iconSize: 18,
labels: [translate("Local"), translate("Remote")],
icons: [Icons.phone_android_sharp, Icons.screen_share],
onToggle: (index) {
final current = model.isLocal ? 0 : 1;
if (index != current) {
model.togglePage();
}
},
),
),
body: body(),
bottomSheet: bottomSheet(),
@ -428,9 +437,17 @@ class _FileManagerPageState extends State<FileManagerPage> {
final list = PathUtil.split(path, model.currentIsWindows);
final breadCrumbList = [
BreadCrumbItem(
content: IconButton(
icon: Icon(Icons.home_filled),
onPressed: onHome,
content: Row(
children: [
IconButton(
icon: Icon(Icons.arrow_upward),
onPressed: goBack,
),
IconButton(
icon: Icon(Icons.home_filled),
onPressed: onHome,
)
],
))
];
breadCrumbList.addAll(list.asMap().entries.map((e) => BreadCrumbItem(