mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-06 00:04:24 +01:00
fix & opt.
- fix: `sftpGoPath` - opt.: `PersistentStore.toJson` - rm: `first` store - opt.: log print
This commit is contained in:
@@ -60,11 +60,11 @@ class Backup {
|
||||
spis = Stores.server.fetch(),
|
||||
snippets = Stores.snippet.fetch(),
|
||||
keys = Stores.key.fetch(),
|
||||
dockerHosts = Stores.docker.fetchAll(),
|
||||
dockerHosts = Stores.docker.toJson(),
|
||||
settings = Stores.setting.toJson();
|
||||
|
||||
static Future<String> backup() async {
|
||||
final result = _diyEncrtpt(json.encode(Backup.loadFromStore()));
|
||||
final result = _diyEncrypt(json.encode(Backup.loadFromStore()));
|
||||
final path = await Paths.bak;
|
||||
await File(path).writeAsString(result);
|
||||
return path;
|
||||
@@ -95,7 +95,7 @@ class Backup {
|
||||
: this.fromJson(json.decode(_diyDecrypt(raw)));
|
||||
}
|
||||
|
||||
String _diyEncrtpt(String raw) => json.encode(
|
||||
String _diyEncrypt(String raw) => json.encode(
|
||||
raw.codeUnits.map((e) => e * 2 + 1).toList(growable: false),
|
||||
);
|
||||
|
||||
|
||||
@@ -68,7 +68,9 @@ enum PkgManager {
|
||||
list.removeWhere((element) => element.isEmpty);
|
||||
final endLine = list.lastIndexWhere(
|
||||
(element) => element.contains('Obsoleting Packages'));
|
||||
list = list.sublist(0, endLine);
|
||||
if (endLine != -1 && list.isNotEmpty) {
|
||||
list = list.sublist(0, endLine);
|
||||
}
|
||||
break;
|
||||
case PkgManager.apt:
|
||||
// avoid other outputs
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:logging/logging.dart';
|
||||
class Loggers {
|
||||
const Loggers._();
|
||||
|
||||
static final root = Logger('Root');
|
||||
static final app = Logger('App');
|
||||
static final parse = Logger('Parse');
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:toolbox/core/persistant_store.dart';
|
||||
import 'package:toolbox/data/store/docker.dart';
|
||||
import 'package:toolbox/data/store/first.dart';
|
||||
import 'package:toolbox/data/store/history.dart';
|
||||
import 'package:toolbox/data/store/private_key.dart';
|
||||
import 'package:toolbox/data/store/server.dart';
|
||||
@@ -17,7 +16,6 @@ class Stores {
|
||||
static final history = locator<HistoryStore>();
|
||||
static final key = locator<PrivateKeyStore>();
|
||||
static final snippet = locator<SnippetStore>();
|
||||
static final first = locator<FirstStore>();
|
||||
|
||||
static final List<PersistentStore> all = [
|
||||
setting,
|
||||
@@ -26,6 +24,5 @@ class Stores {
|
||||
history,
|
||||
key,
|
||||
snippet,
|
||||
first,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -10,8 +10,4 @@ class DockerStore extends PersistentStore<String> {
|
||||
void put(String id, String host) {
|
||||
box.put(id, host);
|
||||
}
|
||||
|
||||
Map<String, String> fetchAll() {
|
||||
return box.toMap().cast<String, String>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import 'package:toolbox/core/persistant_store.dart';
|
||||
|
||||
/// It stores whether is the first time of some.
|
||||
class FirstStore extends PersistentStore<bool> {
|
||||
FirstStore() : super('first');
|
||||
|
||||
/// Show tip of suspend
|
||||
late final showSuspendTip = StoreProperty(box, 'showSuspendTip', true);
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:toolbox/core/persistant_store.dart';
|
||||
|
||||
typedef _HistoryList = List<String>;
|
||||
typedef _HistoryMap = Map<String, String>;
|
||||
|
||||
/// index from 0 -> n : latest -> oldest
|
||||
class _ListHistory {
|
||||
final _HistoryList _history;
|
||||
final List _history;
|
||||
final String _name;
|
||||
final Box _box;
|
||||
|
||||
@@ -15,7 +12,7 @@ class _ListHistory {
|
||||
required String name,
|
||||
}) : _box = box,
|
||||
_name = name,
|
||||
_history = box.get(name, defaultValue: <String>[])!;
|
||||
_history = box.get(name, defaultValue: [])!;
|
||||
|
||||
void add(String path) {
|
||||
_history.remove(path);
|
||||
@@ -23,11 +20,11 @@ class _ListHistory {
|
||||
_box.put(_name, _history);
|
||||
}
|
||||
|
||||
_HistoryList get all => _history;
|
||||
List get all => _history;
|
||||
}
|
||||
|
||||
class _MapHistory {
|
||||
final _HistoryMap _history;
|
||||
final Map _history;
|
||||
final String _name;
|
||||
final Box _box;
|
||||
|
||||
@@ -36,7 +33,7 @@ class _MapHistory {
|
||||
required String name,
|
||||
}) : _box = box,
|
||||
_name = name,
|
||||
_history = box.get(name, defaultValue: <String, String>{})!;
|
||||
_history = box.get(name, defaultValue: <dynamic, dynamic>{})!;
|
||||
|
||||
void put(String id, String val) {
|
||||
_history[id] = val;
|
||||
|
||||
@@ -8,9 +8,6 @@ import '../res/default.dart';
|
||||
class SettingStore extends PersistentStore {
|
||||
SettingStore() : super('setting');
|
||||
|
||||
/// Convert all settings into json
|
||||
Map<String, dynamic> toJson() => {for (var e in box.keys) e: box.get(e)};
|
||||
|
||||
// ------BEGIN------
|
||||
//
|
||||
// These settings are not displayed in the settings page
|
||||
@@ -220,6 +217,9 @@ class SettingStore extends PersistentStore {
|
||||
/// Open SFTP with last viewed path
|
||||
late final sftpOpenLastPath = StoreProperty(box, 'sftpOpenLastPath', true);
|
||||
|
||||
/// Show tip of suspend
|
||||
late final showSuspendTip = StoreProperty(box, 'showSuspendTip', true);
|
||||
|
||||
// Never show these settings for users
|
||||
//
|
||||
// ------BEGIN------
|
||||
|
||||
Reference in New Issue
Block a user