docs: 为核心协议层、服务层与主要页面补充代码注释,修复下载进度计算逻辑
This commit is contained in:
1 parent
7e618adf6c
commit
854f00038c
14 files changed
+244
-28
No files matched your search
@@ -4,17 +4,27 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../providers/server_provider.dart';
|
||||
|
||||
/// 服务器配置的加密持久化。
|
||||
///
|
||||
/// 服务器配置里含 RCON 密码和 SSH 密码,属于敏感信息,
|
||||
/// 因此走 [FlutterSecureStorage](Android Keystore / iOS Keychain),
|
||||
/// 而不是普通的 SharedPreferences 明文存储。
|
||||
class SecureStorageService {
|
||||
/// 当前使用的加密存储 key
|
||||
static const _key = 'mc_servers_encrypted';
|
||||
|
||||
/// 旧版本明文存储 key(迁移用,读取一次后即删除)
|
||||
static const _legacyKey = 'mc_servers';
|
||||
|
||||
static const _storage = FlutterSecureStorage(
|
||||
aOptions: AndroidOptions(),
|
||||
iOptions: IOSOptions(
|
||||
// first_unlock_this_device:开机首次解锁后可读,且不随 iCloud 备份迁移到其他设备
|
||||
accessibility: KeychainAccessibility.first_unlock_this_device,
|
||||
),
|
||||
);
|
||||
|
||||
/// 读取服务器列表,必要时把旧版明文数据迁移到加密存储。
|
||||
static Future<List<ServerConfig>> loadServers() async {
|
||||
final encrypted = await _storage.read(key: _key);
|
||||
if (encrypted != null) {
|
||||
@@ -29,6 +39,7 @@ class SecureStorageService {
|
||||
}
|
||||
}
|
||||
|
||||
// 迁移路径:v1 用 SharedPreferences 明文存储,读到后转存加密存储并清理旧数据
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final legacy = prefs.getString(_legacyKey);
|
||||
if (legacy != null) {
|
||||
@@ -42,6 +53,7 @@ class SecureStorageService {
|
||||
return [];
|
||||
}
|
||||
|
||||
/// 覆盖写入全部服务器配置(列表整体序列化,非增量更新)。
|
||||
static Future<void> saveServers(List<ServerConfig> servers) async {
|
||||
final encoded = jsonEncode(servers.map((s) => s.toJson()).toList());
|
||||
await _storage.write(key: _key, value: encoded);
|
||||
|
||||
Reference in new issue
Block a user