Merge pull request #2449 from Heap-Hop/fix_ft

Fix file transfer bugs
This commit is contained in:
RustDesk 2022-12-04 23:04:09 +08:00 committed by GitHub
commit b798e7415d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 59 deletions

View File

@ -93,6 +93,7 @@ class _FileManagerPageState extends State<FileManagerPage>
Wakelock.enable(); Wakelock.enable();
} }
debugPrint("File manager page init success with id ${widget.id}"); debugPrint("File manager page init success with id ${widget.id}");
model.onDirChanged = breadCrumbScrollToEnd;
// register location listener // register location listener
_locationNodeLocal.addListener(onLocalLocationFocusChanged); _locationNodeLocal.addListener(onLocalLocationFocusChanged);
_locationNodeRemote.addListener(onRemoteLocationFocusChanged); _locationNodeRemote.addListener(onRemoteLocationFocusChanged);
@ -100,17 +101,18 @@ class _FileManagerPageState extends State<FileManagerPage>
@override @override
void dispose() { void dispose() {
model.onClose(); model.onClose().whenComplete(() {
_ffi.close(); _ffi.close();
_ffi.dialogManager.dismissAll(); _ffi.dialogManager.dismissAll();
if (!Platform.isLinux) { if (!Platform.isLinux) {
Wakelock.disable(); Wakelock.disable();
} }
Get.delete<FFI>(tag: 'ft_${widget.id}'); Get.delete<FFI>(tag: 'ft_${widget.id}');
_locationNodeLocal.removeListener(onLocalLocationFocusChanged); _locationNodeLocal.removeListener(onLocalLocationFocusChanged);
_locationNodeRemote.removeListener(onRemoteLocationFocusChanged); _locationNodeRemote.removeListener(onRemoteLocationFocusChanged);
_locationNodeLocal.dispose(); _locationNodeLocal.dispose();
_locationNodeRemote.dispose(); _locationNodeRemote.dispose();
});
super.dispose(); super.dispose();
} }
@ -636,7 +638,6 @@ class _FileManagerPageState extends State<FileManagerPage>
}), }),
IconButton( IconButton(
onPressed: () { onPressed: () {
breadCrumbScrollToEnd(isLocal);
model.refresh(isLocal: isLocal); model.refresh(isLocal: isLocal);
}, },
splashRadius: kDesktopIconButtonSplashRadius, splashRadius: kDesktopIconButtonSplashRadius,
@ -800,7 +801,8 @@ class _FileManagerPageState extends State<FileManagerPage>
onPointerSignal: (e) { onPointerSignal: (e) {
if (e is PointerScrollEvent) { if (e is PointerScrollEvent) {
final sc = getBreadCrumbScrollController(isLocal); final sc = getBreadCrumbScrollController(isLocal);
sc.jumpTo(sc.offset + e.scrollDelta.dy / 4); final scale = Platform.isWindows ? 2 : 4;
sc.jumpTo(sc.offset + e.scrollDelta.dy / scale);
} }
}, },
child: BreadCrumb( child: BreadCrumb(
@ -824,7 +826,7 @@ class _FileManagerPageState extends State<FileManagerPage>
final x = offset.dx; final x = offset.dx;
final y = offset.dy + size.height + 1; final y = offset.dy + size.height + 1;
final isPeerWindows = isWindows(isLocal); final isPeerWindows = model.getCurrentIsWindows(isLocal);
final List<MenuEntryBase> menuItems = [ final List<MenuEntryBase> menuItems = [
MenuEntryButton( MenuEntryButton(
childBuilder: (TextStyle? style) => isPeerWindows childBuilder: (TextStyle? style) => isPeerWindows
@ -912,7 +914,8 @@ class _FileManagerPageState extends State<FileManagerPage>
bool isLocal, void Function(List<String>) onPressed) { bool isLocal, void Function(List<String>) onPressed) {
final path = model.getCurrentDir(isLocal).path; final path = model.getCurrentDir(isLocal).path;
final breadCrumbList = List<BreadCrumbItem>.empty(growable: true); final breadCrumbList = List<BreadCrumbItem>.empty(growable: true);
if (isWindows(isLocal) && path == '/') { final isWindows = model.getCurrentIsWindows(isLocal);
if (isWindows && path == '/') {
breadCrumbList.add(BreadCrumbItem( breadCrumbList.add(BreadCrumbItem(
content: TextButton( content: TextButton(
child: buildWindowsThisPC(), child: buildWindowsThisPC(),
@ -921,7 +924,7 @@ class _FileManagerPageState extends State<FileManagerPage>
onPressed: () => onPressed(['/'])) onPressed: () => onPressed(['/']))
.marginSymmetric(horizontal: 4))); .marginSymmetric(horizontal: 4)));
} else { } else {
final list = PathUtil.split(path, model.getCurrentIsWindows(isLocal)); final list = PathUtil.split(path, isWindows);
breadCrumbList.addAll(list.asMap().entries.map((e) => BreadCrumbItem( breadCrumbList.addAll(list.asMap().entries.map((e) => BreadCrumbItem(
content: TextButton( content: TextButton(
child: Text(e.value), child: Text(e.value),
@ -933,14 +936,6 @@ class _FileManagerPageState extends State<FileManagerPage>
return breadCrumbList; return breadCrumbList;
} }
bool isWindows(bool isLocal) {
if (isLocal) {
return Platform.isWindows;
} else {
return _ffi.ffiModel.pi.platform.toLowerCase() == "windows";
}
}
breadCrumbScrollToEnd(bool isLocal) { breadCrumbScrollToEnd(bool isLocal) {
Future.delayed(Duration(milliseconds: 200), () { Future.delayed(Duration(milliseconds: 200), () {
final breadCrumbScroller = getBreadCrumbScrollController(isLocal); final breadCrumbScroller = getBreadCrumbScrollController(isLocal);
@ -999,9 +994,7 @@ class _FileManagerPageState extends State<FileManagerPage>
} }
openDirectory(String path, {bool isLocal = false}) { openDirectory(String path, {bool isLocal = false}) {
model.openDirectory(path, isLocal: isLocal).then((_) { model.openDirectory(path, isLocal: isLocal);
breadCrumbScrollToEnd(isLocal);
});
} }
void handleDragDone(DropDoneDetails details, bool isLocal) { void handleDragDone(DropDoneDetails details, bool isLocal) {

View File

@ -32,15 +32,17 @@ class _FileManagerPageState extends State<FileManagerPage> {
.showLoading(translate('Connecting...'), onCancel: closeConnection); .showLoading(translate('Connecting...'), onCancel: closeConnection);
}); });
gFFI.ffiModel.updateEventListener(widget.id); gFFI.ffiModel.updateEventListener(widget.id);
model.onDirChanged = (_) => breadCrumbScrollToEnd();
Wakelock.enable(); Wakelock.enable();
} }
@override @override
void dispose() { void dispose() {
model.onClose(); model.onClose().whenComplete(() {
gFFI.close(); gFFI.close();
gFFI.dialogManager.dismissAll(); gFFI.dialogManager.dismissAll();
Wakelock.disable(); Wakelock.disable();
});
super.dispose(); super.dispose();
} }
@ -136,7 +138,7 @@ class _FileManagerPageState extends State<FileManagerPage> {
child: Row( child: Row(
children: [ children: [
Icon( Icon(
model.currentShowHidden model.getCurrentShowHidden()
? Icons.check_box_outlined ? Icons.check_box_outlined
: Icons.check_box_outline_blank, : Icons.check_box_outline_blank,
color: Theme.of(context).iconTheme.color), color: Theme.of(context).iconTheme.color),
@ -183,7 +185,8 @@ class _FileManagerPageState extends State<FileManagerPage> {
model.createDir(PathUtil.join( model.createDir(PathUtil.join(
model.currentDir.path, model.currentDir.path,
name.value.text, name.value.text,
model.currentIsWindows)); model
.getCurrentIsWindows()));
close(); close();
} }
}, },
@ -309,7 +312,6 @@ class _FileManagerPageState extends State<FileManagerPage> {
} }
if (entries[index].isDirectory || entries[index].isDrive) { if (entries[index].isDirectory || entries[index].isDrive) {
model.openDirectory(entries[index].path); model.openDirectory(entries[index].path);
breadCrumbScrollToEnd();
} else { } else {
// Perform file-related tasks. // Perform file-related tasks.
} }
@ -350,12 +352,12 @@ class _FileManagerPageState extends State<FileManagerPage> {
if (model.currentHome.startsWith(list[0])) { if (model.currentHome.startsWith(list[0])) {
// absolute path // absolute path
for (var item in list) { for (var item in list) {
path = PathUtil.join(path, item, model.currentIsWindows); path = PathUtil.join(path, item, model.getCurrentIsWindows());
} }
} else { } else {
path += model.currentHome; path += model.currentHome;
for (var item in list) { for (var item in list) {
path = PathUtil.join(path, item, model.currentIsWindows); path = PathUtil.join(path, item, model.getCurrentIsWindows());
} }
} }
model.openDirectory(path); model.openDirectory(path);
@ -499,7 +501,7 @@ class _FileManagerPageState extends State<FileManagerPage> {
List<BreadCrumbItem> getPathBreadCrumbItems( List<BreadCrumbItem> getPathBreadCrumbItems(
void Function() onHome, void Function(List<String>) onPressed) { void Function() onHome, void Function(List<String>) onPressed) {
final path = model.currentShortPath; final path = model.currentShortPath;
final list = PathUtil.split(path, model.currentIsWindows); final list = PathUtil.split(path, model.getCurrentIsWindows());
final breadCrumbList = [ final breadCrumbList = [
BreadCrumbItem( BreadCrumbItem(
content: IconButton( content: IconButton(

View File

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/common.dart'; import 'package:flutter_hbb/common.dart';
@ -42,6 +43,9 @@ class FileModel extends ChangeNotifier {
/// JobTable <jobId, JobProgress> /// JobTable <jobId, JobProgress>
final _jobTable = List<JobProgress>.empty(growable: true).obs; final _jobTable = List<JobProgress>.empty(growable: true).obs;
/// `isLocal` bool
Function(bool)? onDirChanged;
RxList<JobProgress> get jobTable => _jobTable; RxList<JobProgress> get jobTable => _jobTable;
bool get isLocal => _isSelectedLocal; bool get isLocal => _isSelectedLocal;
@ -141,18 +145,14 @@ class FileModel extends ChangeNotifier {
} }
} }
bool get currentShowHidden => bool getCurrentShowHidden([bool? isLocal]) {
_isSelectedLocal ? _localOption.showHidden : _remoteOption.showHidden; final isLocal_ = isLocal ?? _isSelectedLocal;
return isLocal_ ? _localOption.showHidden : _remoteOption.showHidden;
bool getCurrentShowHidden(bool isLocal) {
return isLocal ? _localOption.showHidden : _remoteOption.showHidden;
} }
bool get currentIsWindows => bool getCurrentIsWindows([bool? isLocal]) {
_isSelectedLocal ? _localOption.isWindows : _remoteOption.isWindows; final isLocal_ = isLocal ?? _isSelectedLocal;
return isLocal_ ? _localOption.isWindows : _remoteOption.isWindows;
bool getCurrentIsWindows(bool isLocal) {
return isLocal ? _localOption.isWindows : _remoteOption.isWindows;
} }
final _fileFetcher = FileFetcher(); final _fileFetcher = FileFetcher();
@ -327,13 +327,13 @@ class FileModel extends ChangeNotifier {
_localOption.showHidden = (await bind.sessionGetPeerOption( _localOption.showHidden = (await bind.sessionGetPeerOption(
id: parent.target?.id ?? "", name: "local_show_hidden")) id: parent.target?.id ?? "", name: "local_show_hidden"))
.isNotEmpty; .isNotEmpty;
_localOption.isWindows = Platform.isWindows;
_remoteOption.showHidden = (await bind.sessionGetPeerOption( _remoteOption.showHidden = (await bind.sessionGetPeerOption(
id: parent.target?.id ?? "", name: "remote_show_hidden")) id: parent.target?.id ?? "", name: "remote_show_hidden"))
.isNotEmpty; .isNotEmpty;
_remoteOption.isWindows = parent.target?.ffiModel.pi.platform == "Windows"; _remoteOption.isWindows =
parent.target?.ffiModel.pi.platform.toLowerCase() == "windows";
debugPrint("remote platform: ${parent.target?.ffiModel.pi.platform}");
await Future.delayed(Duration(milliseconds: 100)); await Future.delayed(Duration(milliseconds: 100));
@ -354,10 +354,12 @@ class FileModel extends ChangeNotifier {
await bind.sessionLoadLastTransferJobs(id: '${parent.target?.id}'); await bind.sessionLoadLastTransferJobs(id: '${parent.target?.id}');
} }
onClose() { Future<void> onClose() async {
parent.target?.dialogManager.dismissAll(); parent.target?.dialogManager.dismissAll();
jobReset(); jobReset();
onDirChanged = null;
// save config // save config
Map<String, String> msgMap = {}; Map<String, String> msgMap = {};
@ -367,7 +369,7 @@ class FileModel extends ChangeNotifier {
msgMap["remote_show_hidden"] = _remoteOption.showHidden ? "Y" : ""; msgMap["remote_show_hidden"] = _remoteOption.showHidden ? "Y" : "";
final id = parent.target?.id ?? ""; final id = parent.target?.id ?? "";
for (final msg in msgMap.entries) { for (final msg in msgMap.entries) {
bind.sessionPeerOption(id: id, name: msg.key, value: msg.value); await bind.sessionPeerOption(id: id, name: msg.key, value: msg.value);
} }
_currentLocalDir.clear(); _currentLocalDir.clear();
_currentRemoteDir.clear(); _currentRemoteDir.clear();
@ -399,14 +401,10 @@ class FileModel extends ChangeNotifier {
if (!isBack) { if (!isBack) {
pushHistory(isLocal); pushHistory(isLocal);
} }
final showHidden = final showHidden = getCurrentShowHidden(isLocal);
isLocal ? _localOption.showHidden : _remoteOption.showHidden; final isWindows = getCurrentIsWindows(isLocal);
final isWindows =
isLocal ? _localOption.isWindows : _remoteOption.isWindows;
// process /C:\ -> C:\ on Windows // process /C:\ -> C:\ on Windows
if (isLocal if (isWindows && path.length > 1 && path[0] == '/') {
? _localOption.isWindows
: _remoteOption.isWindows && path.length > 1 && path[0] == '/') {
path = path.substring(1); path = path.substring(1);
if (path[path.length - 1] != '\\') { if (path[path.length - 1] != '\\') {
path = "$path\\"; path = "$path\\";
@ -421,6 +419,7 @@ class FileModel extends ChangeNotifier {
_currentRemoteDir = fd; _currentRemoteDir = fd;
} }
notifyListeners(); notifyListeners();
onDirChanged?.call(isLocal);
} catch (e) { } catch (e) {
debugPrint("Failed to openDirectory $path: $e"); debugPrint("Failed to openDirectory $path: $e");
} }