mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 15:54:35 +01:00
fix & opt.
- fix: db type err - opt.: server detail page `customCmd` card
This commit is contained in:
@@ -33,4 +33,4 @@ extension StringX on String {
|
||||
|
||||
extension StringXX on String? {
|
||||
String? get selfIfNotNullEmpty => this?.isEmpty == true ? null : this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,16 +61,12 @@ class PersistentStore {
|
||||
String key,
|
||||
List<T> defaultValue, {
|
||||
bool updateLastModified = true,
|
||||
T Function(dynamic val)? decoder,
|
||||
dynamic Function(T val)? encoder,
|
||||
}) {
|
||||
return _StoreListProperty<T>(
|
||||
box,
|
||||
key,
|
||||
defaultValue,
|
||||
updateLastModified: updateLastModified,
|
||||
encoder: encoder,
|
||||
decoder: decoder,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -123,16 +119,12 @@ class _StoreProperty<T> implements StorePropertyBase<T> {
|
||||
this._key,
|
||||
this.defaultValue, {
|
||||
this.updateLastModified = true,
|
||||
this.decoder,
|
||||
this.encoder,
|
||||
});
|
||||
|
||||
final Box _box;
|
||||
final String _key;
|
||||
T defaultValue;
|
||||
bool updateLastModified;
|
||||
final T Function(dynamic val)? decoder;
|
||||
final dynamic Function(T val)? encoder;
|
||||
|
||||
@override
|
||||
ValueListenable<T> listenable() {
|
||||
@@ -141,15 +133,9 @@ class _StoreProperty<T> implements StorePropertyBase<T> {
|
||||
|
||||
@override
|
||||
T fetch() {
|
||||
final stored = _box.get(_key);
|
||||
if (stored == null || stored is! T) {
|
||||
try {
|
||||
if (decoder != null) {
|
||||
return decoder!(stored);
|
||||
}
|
||||
} catch (_) {
|
||||
_logger.warning('Failed to decode "$_key"');
|
||||
}
|
||||
final stored = _box.get(_key, defaultValue: defaultValue);
|
||||
if (stored is! T) {
|
||||
_logger.warning('StoreProperty("$_key") is: ${stored.runtimeType}');
|
||||
return defaultValue;
|
||||
}
|
||||
return stored;
|
||||
@@ -158,9 +144,6 @@ class _StoreProperty<T> implements StorePropertyBase<T> {
|
||||
@override
|
||||
Future<void> put(T value) {
|
||||
if (updateLastModified) _box.updateLastModified();
|
||||
if (encoder != null) {
|
||||
return _box.put(_key, encoder!(value));
|
||||
}
|
||||
return _box.put(_key, value);
|
||||
}
|
||||
|
||||
@@ -176,16 +159,12 @@ class _StoreListProperty<T> implements StorePropertyBase<List<T>> {
|
||||
this._key,
|
||||
this.defaultValue, {
|
||||
this.updateLastModified = true,
|
||||
this.decoder,
|
||||
this.encoder,
|
||||
});
|
||||
|
||||
final Box _box;
|
||||
final String _key;
|
||||
List<T> defaultValue;
|
||||
bool updateLastModified;
|
||||
final T Function(dynamic val)? decoder;
|
||||
final dynamic Function(T val)? encoder;
|
||||
|
||||
@override
|
||||
ValueListenable<List<T>> listenable() {
|
||||
@@ -195,26 +174,21 @@ class _StoreListProperty<T> implements StorePropertyBase<List<T>> {
|
||||
@override
|
||||
List<T> fetch() {
|
||||
final val = _box.get(_key, defaultValue: defaultValue)!;
|
||||
if (val is! List) {
|
||||
throw Exception('StoreListProperty("$_key") is: ${val.runtimeType}');
|
||||
}
|
||||
if (decoder != null) {
|
||||
try {
|
||||
return List<T>.from(val.map(decoder!));
|
||||
} catch (_) {
|
||||
_logger.warning('Failed to decode "$_key"');
|
||||
return defaultValue;
|
||||
try {
|
||||
if (val is! List) {
|
||||
final exception = 'StoreListProperty("$_key") is: ${val.runtimeType}';
|
||||
_logger.warning(exception);
|
||||
throw Exception(exception);
|
||||
}
|
||||
return List<T>.from(val);
|
||||
} catch (_) {
|
||||
return defaultValue;
|
||||
}
|
||||
return List<T>.from(val);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> put(List<T> value) {
|
||||
if (updateLastModified) _box.updateLastModified();
|
||||
if (encoder != null) {
|
||||
return _box.put(_key, value.map(encoder!).toList());
|
||||
}
|
||||
return _box.put(_key, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,4 +36,4 @@ extension ServerX on Server {
|
||||
return status.err ?? l10n.serverTabFailed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class ServerPrivateInfo {
|
||||
pwd != old.pwd ||
|
||||
keyId != old.keyId ||
|
||||
alterUrl != old.alterUrl ||
|
||||
jumpId != old.jumpId ||
|
||||
jumpId != old.jumpId ||
|
||||
custom?.cmds != old.custom?.cmds;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 824;
|
||||
static const String engine = "3.19.3";
|
||||
static const String buildAt = "2024-03-23 10:51:07";
|
||||
static const int modifications = 6;
|
||||
static const int script = 41;
|
||||
static const int build = 827;
|
||||
static const String engine = "3.19.4";
|
||||
static const String buildAt = "2024-03-27 09:52:08";
|
||||
static const int modifications = 7;
|
||||
static const int script = 42;
|
||||
}
|
||||
|
||||
@@ -718,6 +718,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
|
||||
}
|
||||
|
||||
Widget _buildCustom(ServerStatus ss) {
|
||||
if (ss.customCmds.isEmpty) return UIs.placeholder;
|
||||
return CardX(
|
||||
child: ExpandTile(
|
||||
leading: const Icon(MingCute.command_line, size: 17),
|
||||
|
||||
@@ -347,7 +347,8 @@ class _ServerPageState extends State<ServerPage>
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (!(s.spi.autoConnect ?? true) && s.state == ServerState.disconnected) {
|
||||
} else if (!(s.spi.autoConnect ?? true) &&
|
||||
s.state == ServerState.disconnected) {
|
||||
rightCorner = InkWell(
|
||||
onTap: () => Pros.server.refresh(spi: s.spi),
|
||||
child: const Padding(
|
||||
|
||||
Reference in New Issue
Block a user