fix remote home dir
This commit is contained in:
parent
e780fd9253
commit
1ab99075ce
@ -76,6 +76,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
"request_permission" -> {
|
"request_permission" -> {
|
||||||
if(call.arguments is String){
|
if(call.arguments is String){
|
||||||
requestPermission(context, call.arguments as String)
|
requestPermission(context, call.arguments as String)
|
||||||
|
result.success(true)
|
||||||
} else {
|
} else {
|
||||||
result.success(false)
|
result.success(false)
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,6 @@ import 'model.dart';
|
|||||||
|
|
||||||
enum SortBy { Name, Type, Modified, Size }
|
enum SortBy { Name, Type, Modified, Size }
|
||||||
|
|
||||||
// enum FileType {
|
|
||||||
// Dir = 0,
|
|
||||||
// DirLink = 2,
|
|
||||||
// DirDrive = 3,
|
|
||||||
// File = 4,
|
|
||||||
// FileLink = 5,
|
|
||||||
// }
|
|
||||||
|
|
||||||
class FileModel extends ChangeNotifier {
|
class FileModel extends ChangeNotifier {
|
||||||
var _isLocal = false;
|
var _isLocal = false;
|
||||||
var _selectMode = false;
|
var _selectMode = false;
|
||||||
@ -55,15 +47,15 @@ class FileModel extends ChangeNotifier {
|
|||||||
String get currentHome => _isLocal ? _localOption.home : _remoteOption.home;
|
String get currentHome => _isLocal ? _localOption.home : _remoteOption.home;
|
||||||
|
|
||||||
String get currentShortPath {
|
String get currentShortPath {
|
||||||
if(currentDir.path.startsWith(currentHome)){
|
if (currentDir.path.startsWith(currentHome)) {
|
||||||
var path = currentDir.path.replaceFirst(currentHome, "");
|
var path = currentDir.path.replaceFirst(currentHome, "");
|
||||||
if(path.length ==0 ) return "";
|
if (path.length == 0) return "";
|
||||||
if(path[0] == "/" || path[0] == "\\") {
|
if (path[0] == "/" || path[0] == "\\") {
|
||||||
// remove more '/' or '\'
|
// remove more '/' or '\'
|
||||||
path = path.replaceFirst(path[0], "");
|
path = path.replaceFirst(path[0], "");
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}else{
|
} else {
|
||||||
return currentDir.path.replaceFirst(currentHome, "");
|
return currentDir.path.replaceFirst(currentHome, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,6 +104,17 @@ class FileModel extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
receiveFileDir(Map<String, dynamic> evt) {
|
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']);
|
_fileFetcher.tryCompleteTask(evt['value'], evt['is_local']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,29 +146,30 @@ class FileModel extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
onReady() {
|
onReady() async {
|
||||||
_localOption = DirectoryOption(
|
_localOption.home = FFI.getByName("get_home_dir");
|
||||||
home: FFI.getByName("get_home_dir"),
|
_localOption.showHidden =
|
||||||
showHidden: FFI.getByName("peer_option", "local_show_hidden") != "");
|
FFI.getByName("peer_option", "local_show_hidden").isNotEmpty;
|
||||||
_remoteOption = DirectoryOption(
|
|
||||||
home: FFI.ffiModel.pi.homeDir,
|
_remoteOption.showHidden =
|
||||||
showHidden: FFI.getByName("peer_option", "remote_show_hidden") != "",
|
FFI.getByName("peer_option", "remote_show_hidden").isNotEmpty;
|
||||||
isWindows: FFI.ffiModel.pi.platform == "Windows");
|
_remoteOption.isWindows = FFI.ffiModel.pi.platform == "Windows";
|
||||||
|
|
||||||
debugPrint("remote platform: ${FFI.ffiModel.pi.platform}");
|
debugPrint("remote platform: ${FFI.ffiModel.pi.platform}");
|
||||||
|
|
||||||
|
await Future.delayed(Duration(milliseconds: 100));
|
||||||
|
|
||||||
final local = FFI.getByName("peer_option", "local_dir");
|
final local = FFI.getByName("peer_option", "local_dir");
|
||||||
final remote = FFI.getByName("peer_option", "remote_dir");
|
final remote = FFI.getByName("peer_option", "remote_dir");
|
||||||
openDirectory(local.isEmpty ? _localOption.home : local, isLocal: true);
|
openDirectory(local.isEmpty ? _localOption.home : local, isLocal: true);
|
||||||
openDirectory(remote.isEmpty ? _remoteOption.home : remote, isLocal: false);
|
openDirectory(remote.isEmpty ? _remoteOption.home : remote, isLocal: false);
|
||||||
Timer(Duration(seconds: 2), () {
|
await Future.delayed(Duration(seconds: 1));
|
||||||
if (_currentLocalDir.path.isEmpty) {
|
if (_currentLocalDir.path.isEmpty) {
|
||||||
openDirectory(_localOption.home, isLocal: true);
|
openDirectory(_localOption.home, isLocal: true);
|
||||||
}
|
}
|
||||||
if (_currentRemoteDir.path.isEmpty) {
|
if (_currentRemoteDir.path.isEmpty) {
|
||||||
openDirectory(_remoteOption.home, isLocal: false);
|
openDirectory(_remoteOption.home, isLocal: false);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onClose() {
|
onClose() {
|
||||||
@ -192,6 +196,8 @@ class FileModel extends ChangeNotifier {
|
|||||||
FFI.setByName('peer_option', jsonEncode(msg));
|
FFI.setByName('peer_option', jsonEncode(msg));
|
||||||
_currentLocalDir.clear();
|
_currentLocalDir.clear();
|
||||||
_currentRemoteDir.clear();
|
_currentRemoteDir.clear();
|
||||||
|
_localOption.clear();
|
||||||
|
_remoteOption.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
@ -278,7 +284,11 @@ class FileModel extends ChangeNotifier {
|
|||||||
fd.format(isWindows);
|
fd.format(isWindows);
|
||||||
EasyLoading.dismiss();
|
EasyLoading.dismiss();
|
||||||
if (fd.entries.isEmpty) {
|
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) {
|
if (confirm == true) {
|
||||||
sendRemoveEmptyDir(item.path, 0, items.isLocal!);
|
sendRemoveEmptyDir(item.path, 0, items.isLocal!);
|
||||||
}
|
}
|
||||||
@ -290,9 +300,10 @@ class FileModel extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < entries.length; i++) {
|
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 dirShow = item.isDirectory
|
||||||
final count =
|
? "${translate("Are you sure you want to delete the file of this directory?")}\n"
|
||||||
entries.length > 1 ? "${i + 1}/${entries.length}" : "";
|
: "";
|
||||||
|
final count = entries.length > 1 ? "${i + 1}/${entries.length}" : "";
|
||||||
content = dirShow + "$count \n${entries[i].path}";
|
content = dirShow + "$count \n${entries[i].path}";
|
||||||
final confirm =
|
final confirm =
|
||||||
await showRemoveDialog(title, content, item.isDirectory);
|
await showRemoveDialog(title, content, item.isDirectory);
|
||||||
@ -403,7 +414,7 @@ class FileModel extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancelJob(int id) {
|
cancelJob(int id) {
|
||||||
FFI.setByName("cancel_job",id.toString());
|
FFI.setByName("cancel_job", id.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
changeSortStyle(SortBy sort) {
|
changeSortStyle(SortBy sort) {
|
||||||
@ -668,6 +679,12 @@ class DirectoryOption {
|
|||||||
|
|
||||||
DirectoryOption(
|
DirectoryOption(
|
||||||
{this.home = "", this.showHidden = false, this.isWindows = false});
|
{this.home = "", this.showHidden = false, this.isWindows = false});
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
home = "";
|
||||||
|
showHidden = false;
|
||||||
|
isWindows = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// code from file_manager pkg after edit
|
// code from file_manager pkg after edit
|
||||||
|
@ -236,7 +236,6 @@ class FfiModel with ChangeNotifier {
|
|||||||
_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']);
|
||||||
_pi.homeDir = evt['home_dir'];
|
|
||||||
|
|
||||||
if (evt['is_file_transfer'] == "true") {
|
if (evt['is_file_transfer'] == "true") {
|
||||||
FFI.fileModel.onReady();
|
FFI.fileModel.onReady();
|
||||||
@ -879,7 +878,6 @@ 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 = [];
|
||||||
|
@ -4,6 +4,7 @@ import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|||||||
import 'package:flutter_hbb/models/file_model.dart';
|
import 'package:flutter_hbb/models/file_model.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
|
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
|
||||||
|
import 'package:toggle_switch/toggle_switch.dart';
|
||||||
|
|
||||||
import '../common.dart';
|
import '../common.dart';
|
||||||
import '../models/model.dart';
|
import '../models/model.dart';
|
||||||
@ -58,18 +59,26 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
backgroundColor: MyTheme.grayBg,
|
backgroundColor: MyTheme.grayBg,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
leading: Row(children: [
|
leading: Row(children: [
|
||||||
IconButton(icon: Icon(Icons.arrow_back), onPressed: goBack),
|
|
||||||
IconButton(icon: Icon(Icons.close), onPressed: clientClose),
|
IconButton(icon: Icon(Icons.close), onPressed: clientClose),
|
||||||
]),
|
]),
|
||||||
leadingWidth: 200,
|
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
title: Text(translate(model.isLocal ? "Local" : "Remote")),
|
title: ToggleSwitch(
|
||||||
actions: [
|
initialLabelIndex: model.isLocal ? 0 : 1,
|
||||||
IconButton(
|
activeBgColor: [MyTheme.idColor],
|
||||||
icon: Icon(Icons.change_circle),
|
inactiveBgColor: MyTheme.grayBg,
|
||||||
onPressed: () => model.togglePage(),
|
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(),
|
body: body(),
|
||||||
bottomSheet: bottomSheet(),
|
bottomSheet: bottomSheet(),
|
||||||
@ -428,9 +437,17 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
|||||||
final list = PathUtil.split(path, model.currentIsWindows);
|
final list = PathUtil.split(path, model.currentIsWindows);
|
||||||
final breadCrumbList = [
|
final breadCrumbList = [
|
||||||
BreadCrumbItem(
|
BreadCrumbItem(
|
||||||
content: IconButton(
|
content: Row(
|
||||||
icon: Icon(Icons.home_filled),
|
children: [
|
||||||
onPressed: onHome,
|
IconButton(
|
||||||
|
icon: Icon(Icons.arrow_upward),
|
||||||
|
onPressed: goBack,
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.home_filled),
|
||||||
|
onPressed: onHome,
|
||||||
|
)
|
||||||
|
],
|
||||||
))
|
))
|
||||||
];
|
];
|
||||||
breadCrumbList.addAll(list.asMap().entries.map((e) => BreadCrumbItem(
|
breadCrumbList.addAll(list.asMap().entries.map((e) => BreadCrumbItem(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user