new: sftp jump history

This commit is contained in:
lollipopkit
2023-08-23 20:37:29 +08:00
parent ad11b9fcc5
commit 93f6368753
4 changed files with 61 additions and 26 deletions

View File

@@ -0,0 +1,32 @@
import 'package:hive_flutter/hive_flutter.dart';
import 'package:toolbox/core/persistant_store.dart';
typedef _HistoryType = List<String>;
/// index from 0 -> n : latest -> oldest
class _History {
final _HistoryType _history;
final String _name;
final Box<_HistoryType> _box;
_History({
required Box<_HistoryType> box,
required String name,
}) : _box = box,
_name = name,
_history = box.get(name, defaultValue: <String>[])!;
void add(String path) {
_history.remove(path);
_history.insert(0, path);
_box.put(_name, _history);
}
_HistoryType get all => _history;
}
class HistoryStore extends PersistentStore<_HistoryType> {
late final _History sftpPath = _History(box: box, name: 'sftpPath');
late final _History sshCmds = _History(box: box, name: 'sshCmds');
}