From 2e11d8827e7277d88b4c23974db94f0f904ae3fc Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Sat, 27 Jan 2024 23:14:46 +0800 Subject: [PATCH] fix: store type --- ios/Runner.xcodeproj/project.pbxproj | 36 +++++++++++++------------- lib/core/persistant_store.dart | 27 ++++++++++++++++--- lib/core/utils/misc.dart | 9 +++++++ lib/core/utils/sync/icloud.dart | 7 +++-- lib/data/res/build_data.dart | 6 ++--- lib/data/store/setting.dart | 24 +++++++++++------ macos/Runner.xcodeproj/project.pbxproj | 14 +++++----- 7 files changed, 80 insertions(+), 43 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 14416e39..fa747a57 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -586,7 +586,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -596,7 +596,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -720,7 +720,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -730,7 +730,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -748,7 +748,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist"; @@ -758,7 +758,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -779,7 +779,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -792,7 +792,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; @@ -818,7 +818,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -831,7 +831,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -854,7 +854,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_TEAM = BA88US33G6; GCC_C_LANGUAGE_STANDARD = gnu11; GENERATE_INFOPLIST_FILE = YES; @@ -867,7 +867,7 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -890,7 +890,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_PREVIEWS = YES; @@ -902,7 +902,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd; @@ -931,7 +931,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_PREVIEWS = YES; @@ -943,7 +943,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd; PRODUCT_NAME = ServerBox; @@ -969,7 +969,7 @@ CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_ASSET_PATHS = ""; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_PREVIEWS = YES; @@ -981,7 +981,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.WatchEnd; PRODUCT_NAME = ServerBox; diff --git a/lib/core/persistant_store.dart b/lib/core/persistant_store.dart index 28465661..05237413 100644 --- a/lib/core/persistant_store.dart +++ b/lib/core/persistant_store.dart @@ -95,12 +95,16 @@ extension StoreX on PersistentStore { String key, List defaultValue, { bool updateLastModified = true, + T Function(dynamic val)? decoder, + dynamic Function(T val)? encoder, }) { return _StoreListProperty( box, key, defaultValue, updateLastModified: updateLastModified, + encoder: encoder, + decoder: decoder, ); } } @@ -118,12 +122,16 @@ class _StoreProperty implements StorePropertyBase { 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 listenable() { @@ -134,6 +142,9 @@ class _StoreProperty implements StorePropertyBase { T fetch() { final stored = _box.get(_key); if (stored == null || stored is! T) { + if (decoder != null) { + return decoder!(stored); + } return defaultValue; } return stored; @@ -142,6 +153,9 @@ class _StoreProperty implements StorePropertyBase { @override Future put(T value) { if (updateLastModified) _box.updateLastModified(); + if (encoder != null) { + return _box.put(_key, encoder!(value)); + } return _box.put(_key, value); } @@ -157,12 +171,16 @@ class _StoreListProperty implements StorePropertyBase> { this._key, this.defaultValue, { this.updateLastModified = true, + this.decoder, + this.encoder, }); final Box _box; final String _key; List defaultValue; bool updateLastModified; + final T Function(dynamic val)? decoder; + final dynamic Function(T val)? encoder; @override ValueListenable> listenable() { @@ -172,17 +190,20 @@ class _StoreListProperty implements StorePropertyBase> { @override List fetch() { final val = _box.get(_key, defaultValue: defaultValue)!; - if (val is! List) { throw Exception('StoreListProperty("$_key") is: ${val.runtimeType}'); } - - return List.from(val); + return decoder == null + ? List.from(val) + : val.map((e) => decoder!.call(e)).toList(); } @override Future put(List value) { if (updateLastModified) _box.updateLastModified(); + if (encoder != null) { + return _box.put(_key, value.map(encoder!).toList()); + } return _box.put(_key, value); } diff --git a/lib/core/utils/misc.dart b/lib/core/utils/misc.dart index 5532777e..48e93dc2 100644 --- a/lib/core/utils/misc.dart +++ b/lib/core/utils/misc.dart @@ -39,3 +39,12 @@ String pathJoin(String path1, String path2) { bool isFileUrl(String url) => url.split('/').last.contains('.'); int get timeStamp => DateTime.now().millisecondsSinceEpoch; + +bool isBaseType(Object? obj) { + return obj is String || + obj is int || + obj is double || + obj is bool || + obj is List || + obj is Map; +} diff --git a/lib/core/utils/sync/icloud.dart b/lib/core/utils/sync/icloud.dart index eab4b9e1..fb5d3187 100644 --- a/lib/core/utils/sync/icloud.dart +++ b/lib/core/utils/sync/icloud.dart @@ -190,10 +190,9 @@ abstract final class ICloud { return; } - final dlFile = await File(await Paths.bak).readAsString(); - final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile); - await dlBak.restore(); - + final dlFile = await File(await Paths.bak).readAsString(); + final dlBak = await Computer.shared.start(Backup.fromJsonString, dlFile); + await dlBak.restore(); await backup(); } diff --git a/lib/data/res/build_data.dart b/lib/data/res/build_data.dart index 877913ea..c8445eaf 100644 --- a/lib/data/res/build_data.dart +++ b/lib/data/res/build_data.dart @@ -2,9 +2,9 @@ class BuildData { static const String name = "ServerBox"; - static const int build = 724; + static const int build = 725; static const String engine = "3.16.8"; - static const String buildAt = "2024-01-26 21:05:29"; - static const int modifications = 2; + static const String buildAt = "2024-01-27 21:27:49"; + static const int modifications = 4; static const int script = 36; } diff --git a/lib/data/store/setting.dart b/lib/data/store/setting.dart index 0a63c34a..72b2c4d1 100644 --- a/lib/data/store/setting.dart +++ b/lib/data/store/setting.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:toolbox/core/persistant_store.dart'; import 'package:toolbox/core/utils/platform/base.dart'; import 'package:toolbox/data/model/app/menu/server_func.dart'; +import 'package:toolbox/data/model/ssh/virtual_key.dart'; import '../model/app/net_view.dart'; import '../res/default.dart'; @@ -141,6 +142,8 @@ class SettingStore extends PersistentStore { late final sshVirtKeys = listProperty( 'sshVirtKeys', Defaults.sshVirtKeys, + encoder: (val) => val.index, + decoder: (val) => VirtKey.values[val], ); late final netViewType = property( @@ -209,14 +212,19 @@ class SettingStore extends PersistentStore { /// Whether collapse UI items by default late final collapseUIDefault = property('collapseUIDefault', true); - late final serverFuncBtns = listProperty('serverBtns', [ - ServerFuncBtn.terminal, - ServerFuncBtn.sftp, - ServerFuncBtn.container, - ServerFuncBtn.process, - ServerFuncBtn.pkg, - ServerFuncBtn.snippet, - ]); + late final serverFuncBtns = listProperty( + 'serverBtns', + [ + ServerFuncBtn.terminal, + ServerFuncBtn.sftp, + ServerFuncBtn.container, + ServerFuncBtn.process, + ServerFuncBtn.pkg, + ServerFuncBtn.snippet, + ], + encoder: (val) => val.index, + decoder: (val) => ServerFuncBtn.values[val], + ); // Never show these settings for users // diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index 92015c84..08ffe237 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -439,8 +439,8 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 724; - DEVELOPMENT_TEAM = ""; + CURRENT_PROJECT_VERSION = 725; + DEVELOPMENT_TEAM = BA88US33G6; INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = "Server Box"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; @@ -449,7 +449,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "Server Box"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -574,7 +574,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_TEAM = BA88US33G6; INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = "Server Box"; @@ -584,7 +584,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "Server Box"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -604,7 +604,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "3rd Party Mac Developer Application"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 724; + CURRENT_PROJECT_VERSION = 725; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=macosx*]" = BA88US33G6; INFOPLIST_FILE = Runner/Info.plist; @@ -615,7 +615,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.0.724; + MARKETING_VERSION = 1.0.725; PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox; PRODUCT_NAME = "Server Box"; PROVISIONING_PROFILE_SPECIFIER = "";