From 5b9a76f8a580ac19d0e6e74d841283498fcd1917 Mon Sep 17 00:00:00 2001 From: csf Date: Sun, 4 Dec 2022 22:41:44 +0900 Subject: [PATCH] fix file transfer load/save config, opt breadCrumbScroll --- .../lib/desktop/pages/file_manager_page.dart | 29 +++++++++---------- .../lib/mobile/pages/file_manager_page.dart | 11 +++---- flutter/lib/models/file_model.dart | 10 +++++-- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/flutter/lib/desktop/pages/file_manager_page.dart b/flutter/lib/desktop/pages/file_manager_page.dart index 021f03713..e5476fc2f 100644 --- a/flutter/lib/desktop/pages/file_manager_page.dart +++ b/flutter/lib/desktop/pages/file_manager_page.dart @@ -93,6 +93,7 @@ class _FileManagerPageState extends State Wakelock.enable(); } debugPrint("File manager page init success with id ${widget.id}"); + model.onDirChanged = breadCrumbScrollToEnd; // register location listener _locationNodeLocal.addListener(onLocalLocationFocusChanged); _locationNodeRemote.addListener(onRemoteLocationFocusChanged); @@ -100,17 +101,18 @@ class _FileManagerPageState extends State @override void dispose() { - model.onClose(); - _ffi.close(); - _ffi.dialogManager.dismissAll(); - if (!Platform.isLinux) { - Wakelock.disable(); - } - Get.delete(tag: 'ft_${widget.id}'); - _locationNodeLocal.removeListener(onLocalLocationFocusChanged); - _locationNodeRemote.removeListener(onRemoteLocationFocusChanged); - _locationNodeLocal.dispose(); - _locationNodeRemote.dispose(); + model.onClose().whenComplete(() { + _ffi.close(); + _ffi.dialogManager.dismissAll(); + if (!Platform.isLinux) { + Wakelock.disable(); + } + Get.delete(tag: 'ft_${widget.id}'); + _locationNodeLocal.removeListener(onLocalLocationFocusChanged); + _locationNodeRemote.removeListener(onRemoteLocationFocusChanged); + _locationNodeLocal.dispose(); + _locationNodeRemote.dispose(); + }); super.dispose(); } @@ -636,7 +638,6 @@ class _FileManagerPageState extends State }), IconButton( onPressed: () { - breadCrumbScrollToEnd(isLocal); model.refresh(isLocal: isLocal); }, splashRadius: kDesktopIconButtonSplashRadius, @@ -999,9 +1000,7 @@ class _FileManagerPageState extends State } openDirectory(String path, {bool isLocal = false}) { - model.openDirectory(path, isLocal: isLocal).then((_) { - breadCrumbScrollToEnd(isLocal); - }); + model.openDirectory(path, isLocal: isLocal); } void handleDragDone(DropDoneDetails details, bool isLocal) { diff --git a/flutter/lib/mobile/pages/file_manager_page.dart b/flutter/lib/mobile/pages/file_manager_page.dart index 6e5c91484..5a96cda62 100644 --- a/flutter/lib/mobile/pages/file_manager_page.dart +++ b/flutter/lib/mobile/pages/file_manager_page.dart @@ -32,15 +32,17 @@ class _FileManagerPageState extends State { .showLoading(translate('Connecting...'), onCancel: closeConnection); }); gFFI.ffiModel.updateEventListener(widget.id); + model.onDirChanged = (_) => breadCrumbScrollToEnd(); Wakelock.enable(); } @override void dispose() { - model.onClose(); - gFFI.close(); - gFFI.dialogManager.dismissAll(); - Wakelock.disable(); + model.onClose().whenComplete(() { + gFFI.close(); + gFFI.dialogManager.dismissAll(); + Wakelock.disable(); + }); super.dispose(); } @@ -309,7 +311,6 @@ class _FileManagerPageState extends State { } if (entries[index].isDirectory || entries[index].isDrive) { model.openDirectory(entries[index].path); - breadCrumbScrollToEnd(); } else { // Perform file-related tasks. } diff --git a/flutter/lib/models/file_model.dart b/flutter/lib/models/file_model.dart index 4beac01be..ee5c081a6 100644 --- a/flutter/lib/models/file_model.dart +++ b/flutter/lib/models/file_model.dart @@ -42,6 +42,9 @@ class FileModel extends ChangeNotifier { /// JobTable final _jobTable = List.empty(growable: true).obs; + /// `isLocal` bool + Function(bool)? onDirChanged; + RxList get jobTable => _jobTable; bool get isLocal => _isSelectedLocal; @@ -354,10 +357,12 @@ class FileModel extends ChangeNotifier { await bind.sessionLoadLastTransferJobs(id: '${parent.target?.id}'); } - onClose() { + Future onClose() async { parent.target?.dialogManager.dismissAll(); jobReset(); + onDirChanged = null; + // save config Map msgMap = {}; @@ -367,7 +372,7 @@ class FileModel extends ChangeNotifier { msgMap["remote_show_hidden"] = _remoteOption.showHidden ? "Y" : ""; final id = parent.target?.id ?? ""; 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(); _currentRemoteDir.clear(); @@ -421,6 +426,7 @@ class FileModel extends ChangeNotifier { _currentRemoteDir = fd; } notifyListeners(); + onDirChanged?.call(isLocal); } catch (e) { debugPrint("Failed to openDirectory $path: $e"); }