Files
flutter_server_box/lib/data/store/setting.dart
GT610 9ac866644c ref:Refactor Settings UI and Fix Performance Issues (#1026)
* refactor(Settings page): Simplify the click handling logic of the cancel button

* fix(backup_service): Add a cancel button in the restore backup dialog

* refactor(Settings Page): Refactor the ordered list component and optimize state management

- Extract the logic for building list items into a separate method to improve maintainability
- Add animation effects to enhance the dragging experience
- Use PageStorageKey to maintain the scroll position
- Optimize the state management logic of the checkbox
- Add new contributors in github_id.dart

* fix: Add SafeArea to the settings page to prevent content from being obscured

Add SafeArea wrapping content in multiple settings pages to prevent content from being obscured by the navigation bar on certain devices, thereby enhancing user experience

* refactor: Extract file list retrieval method and optimize asynchronous loading of iOS settings page

Extract the `_getEntities` method from an inline function to a class member method to enhance code readability

Preload watch context and push token in the iOS settings page to avoid repeatedly creating Futures

* fix: Add a `key` attribute to the ChoiceChipX component to avoid rendering issues

* refactor(Settings page): Refactor the platform-related settings logic and merge the Android settings into the main page

Migrate the Android platform settings from a standalone page to the main settings page, and remove redundant Android settings page files

Adjust the platform setting logic, retaining only the special setting entry for the iOS platform

* build: Update fl_lib dependency to v1.0.363

* feat(Settings): Add persistent disable state for cards and virtual keys

Add persistent storage functionality for server detail cards and SSH virtual key disable status

Modify the logic of relevant pages to support the saving and restoration of disabled states

* refactor(setting): Simplify save logic and optimize file sorting performance

In the settings page, remove the unnecessary `enabledList` filtering and directly save the `_order` list

Optimize the sorting logic on the local file page by first retrieving the file status before proceeding with sorting

* fix: Optimize data filtering and backup service error handling on the settings page

Fix the data filtering logic in the settings page to only process key-value pairs with specific prefixes
Add error handling to the backup service, capture and display merge failure exceptions

* fix(Settings page): Fixed the issue where disabled items were not included in the order settings and asynchronously saved preference settings

Fix the issue where disabled items in the virtual keyboard and service details order settings are not included in the order list

Change the preference setting saving method to an asynchronous operation, and add a mounted check to prevent updating the state after the component is unmounted

* refactor: Optimize the reordering logic and remove redundant sorting methods

Narrow the scope of state updates in the reordering logic to only encompass the parts where data is actually modified

Remove the unused sorting methods in `_local.dart` to simplify the code

* refactor(view): Optimize the refresh logic of the local file page

Refactor the refresh method that directly calls setState into a unified _refresh method

Use the `_entitiesFuture` to cache the list of files to obtain results and avoid redundant calculations

* Update lib/view/page/storage/local.dart

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-01-25 18:43:57 +08:00

284 lines
10 KiB
Dart

import 'dart:convert';
import 'package:fl_lib/fl_lib.dart';
import 'package:server_box/data/model/app/menu/server_func.dart';
import 'package:server_box/data/model/app/net_view.dart';
import 'package:server_box/data/model/app/server_detail_card.dart';
import 'package:server_box/data/model/app/tab.dart';
import 'package:server_box/data/model/ssh/virtual_key.dart';
import 'package:server_box/data/res/default.dart';
class SettingStore extends HiveStore {
SettingStore._() : super('setting');
static final instance = SettingStore._();
/// Time out for server connect and more...
late final timeout = propertyDefault('timeOut', 5);
/// Record history of SFTP path and etc.
late final recordHistory = propertyDefault('recordHistory', true);
/// Lanch page idx
// late final launchPage = property('launchPage', Defaults.launchPageIdx);
/// Disk view: amount / IO
late final serverTabPreferDiskAmount = propertyDefault('serverTabPreferDiskAmount', false);
/// Bigger for bigger font size
/// 1.0 means 100%
/// Warning: This may cause some UI issues
late final textFactor = propertyDefault('textFactor', 1.0);
/// The seed of color scheme
late final colorSeed = propertyDefault('primaryColor', 4287106639);
late final serverStatusUpdateInterval = propertyDefault(
'serverStatusUpdateInterval',
Defaults.updateInterval,
);
// Max retry count when connect to server
late final maxRetryCount = propertyDefault('maxRetryCount', 2);
// Night mode: 0 -> auto, 1 -> light, 2 -> dark, 3 -> AMOLED, 4 -> AUTO-AMOLED
late final themeMode = propertyDefault('themeMode', 0);
// Font file path
late final fontPath = propertyDefault('fontPath', '');
// Backgroud running (Android)
late final bgRun = propertyDefault('bgRun', isAndroid);
// Server order
late final serverOrder = listProperty<String>('serverOrder');
late final snippetOrder = listProperty<String>('snippetOrder');
// Server details page cards order
late final detailCardOrder = listProperty(
'detailCardOrder',
defaultValue: ServerDetailCards.values.map((e) => e.name).toList(),
);
// Disabled detail cards (for persistence when toggling visibility)
late final detailCardDisabled = listProperty<String>('detailCardDisabled');
// Disabled SSH virtual keys (for persistence when toggling visibility)
late final sshVirtKeysDisabled = listProperty<int>('sshVirtKeysDisabled');
// SSH term font size
late final termFontSize = propertyDefault('termFontSize', 13.0);
// Locale
late final locale = propertyDefault('locale', '');
// SSH virtual key (ctrl | alt) auto turn off
late final sshVirtualKeyAutoOff = propertyDefault('sshVirtualKeyAutoOff', true);
late final editorFontSize = propertyDefault('editorFontSize', 12.5);
/// Trusted SSH host key fingerprints keyed by `serverId::keyType`.
late final sshKnownHostFingerprints = propertyDefault<Map<String, String>>(
'sshKnownHostFingerprints',
const {},
fromObj: (raw) {
if (raw is Map) {
return raw.map((key, value) => MapEntry(key.toString(), value.toString()));
}
return <String, String>{};
},
);
// Editor theme
late final editorTheme = propertyDefault('editorTheme', Defaults.editorTheme);
late final editorDarkTheme = propertyDefault('editorDarkTheme', Defaults.editorDarkTheme);
late final fullScreen = propertyDefault('fullScreen', false);
late final fullScreenJitter = propertyDefault('fullScreenJitter', true);
// late final fullScreenRotateQuarter = property(
// 'fullScreenRotateQuarter',
// 1,
// );
// late final keyboardType = property(
// 'keyboardType',
// TextInputType.text.index,
// );
late final sshVirtKeys = listProperty<int>(
'sshVirtKeys',
defaultValue: VirtKeyX.defaultOrder.map((e) => e.index).toList(),
fromObj: (val) => List<int>.from(val as List),
);
late final netViewType = propertyDefault(
'netViewType',
NetViewType.speed,
fromObj: (val) => NetViewType.values.firstWhereOrNull((e) => e.name == val),
toObj: (type) => type?.name,
);
// Only valid on iOS
late final autoUpdateHomeWidget = propertyDefault('autoUpdateHomeWidget', isIOS);
late final autoCheckAppUpdate = propertyDefault('autoCheckAppUpdate', true);
/// Display server tab function buttons on the bottom of each server card if [true]
///
/// Otherwise, display them on the top of server detail page
late final moveServerFuncs = propertyDefault('moveOutServerTabFuncBtns', false);
/// Whether use `rm -r` to delete directory on SFTP
late final sftpRmrDir = propertyDefault('sftpRmrDir', false);
/// Whether use system's primary color as the app's primary color
late final useSystemPrimaryColor = propertyDefault('useSystemPrimaryColor', false);
/// Only valid on iOS / Android / Windows
late final useBioAuth = propertyDefault('useBioAuth', false);
/// Delay to lock the App with BioAuth, in seconds.
/// Set to `0` to disable this feature.
late final delayBioAuthLock = propertyDefault('delayBioAuthLock', 0);
/// The performance of highlight is bad
late final editorHighlight = propertyDefault('editorHighlight', true);
/// Open SFTP with last viewed path
late final sftpOpenLastPath = propertyDefault('sftpOpenLastPath', true);
/// Show folders first in SFTP file browser
late final sftpShowFoldersFirst = propertyDefault('sftpShowFoldersFirst', true);
/// Show tip of suspend
late final showSuspendTip = propertyDefault('showSuspendTip', true);
/// Whether collapse UI items by default
late final collapseUIDefault = propertyDefault('collapseUIDefault', true);
/// Terminal AI helper configuration
late final askAiBaseUrl = propertyDefault('askAiBaseUrl', 'https://api.openai.com');
late final askAiApiKey = propertyDefault('askAiApiKey', '');
late final askAiModel = propertyDefault('askAiModel', 'gpt-4o-mini');
late final serverFuncBtns = listProperty('serverBtns', defaultValue: ServerFuncBtn.defaultIdxs);
/// Docker is more popular than podman, set to `false` to use docker
late final usePodman = propertyDefault('usePodman', false);
/// Try to use `sudo` to run docker command
late final containerTrySudo = propertyDefault('containerTrySudo', true);
/// Keep previous server status when err occurs
late final keepStatusWhenErr = propertyDefault('keepStatusWhenErr', false);
/// Parse container stat
late final containerParseStat = propertyDefault('containerParseStat', true);
/// Auto refresh container status
late final containerAutoRefresh = propertyDefault('containerAutoRefresh', true);
/// Use double column servers page on Desktop
late final doubleColumnServersPage = propertyDefault('doubleColumnServersPage', true);
/// Ignore local network device (eg: br-xxx, ovs-system...)
/// when building traffic view on server tab
//late final ignoreLocalNet = propertyDefault('ignoreLocalNet', true);
/// Remerber pwd in memory
/// Used for [DialogX.showPwdDialog]
late final rememberPwdInMem = propertyDefault('rememberPwdInMem', true);
/// SSH Term Theme
/// 0: follow app theme, 1: light, 2: dark
late final termTheme = propertyDefault('termTheme', 0);
/// Compatiablity for Chinese Android.
/// Set it to true, if you use Safe Keyboard on Chinese Android
// late final cnKeyboardComp = propertyDefault('cnKeyboardComp', false);
late final lastVer = propertyDefault('lastVer', 0);
/// Use CupertinoPageRoute for all routes
late final cupertinoRoute = propertyDefault('cupertinoRoute', isIOS);
/// Hide title bar on desktop
late final hideTitleBar = propertyDefault('hideTitleBar', isDesktop);
/// Display CPU view as progress, also called as old CPU view
late final cpuViewAsProgress = propertyDefault('cpuViewAsProgress', false);
late final displayCpuIndex = propertyDefault('displayCpuIndex', true);
late final editorSoftWrap = propertyDefault('editorSoftWrap', isIOS);
late final sshTermHelpShown = propertyDefault('sshTermHelpShown', false);
late final horizonVirtKey = propertyDefault('horizonVirtKey', false);
/// general wake lock
late final generalWakeLock = propertyDefault('generalWakeLock', false);
/// ssh page
late final sshWakeLock = propertyDefault('sshWakeLock', true);
late final sshBgImage = propertyDefault('sshBgImage', '');
late final sshBgOpacity = propertyDefault('sshBgOpacity', 0.3);
late final sshBlurRadius = propertyDefault('sshBlurRadius', 0.0);
/// fmt: https://example.com/{DIST}-{BRIGHT}.png
late final serverLogoUrl = propertyDefault('serverLogoUrl', '');
late final betaTest = propertyDefault('betaTest', false);
/// For desktop only.
/// Record the position and size of the window.
late final windowState = property<WindowState>(
'windowState',
fromObj: (raw) => WindowState.fromJson(jsonDecode(raw as String) as Map<String, dynamic>),
toObj: (state) => state == null ? null : jsonEncode(state.toJson()),
);
late final introVer = propertyDefault('introVer', 0);
late final letterCache = propertyDefault('letterCache', false);
/// Set it to `$EDITOR`, `vim` and etc. to use remote system editor in SSH terminal.
/// Set it empty to use local editor GUI.
late final sftpEditor = propertyDefault('sftpEditor', '');
/// Preferred terminal emulator command on desktop
late final desktopTerminal = propertyDefault('desktopTerminal', 'x-terminal-emulator');
/// Run foreground service on Android, if the SSH terminal is running
late final fgService = propertyDefault('fgService', false);
/// Close the editor after saving
late final closeAfterSave = propertyDefault('closeAfterSave', false);
/// Version of store db
late final storeVersion = propertyDefault('storeVersion', 0);
/// Have notified user for notificaiton permission or not
late final noNotiPerm = propertyDefault('noNotiPerm', false);
/// The backup password
late final backupasswd = SecureProp('bakPasswd');
/// Whether to read SSH config from ~/.ssh/config on first time
late final firstTimeReadSSHCfg = propertyDefault('firstTimeReadSSHCfg', true);
/// Tabs at home page
late final homeTabs = listProperty(
'homeTabs',
defaultValue: AppTab.values,
fromObj: AppTab.parseAppTabsFromObj,
toObj: (val) {
return val?.map((e) => e.name).toList() ?? [];
},
);
}