docs: 为核心协议层、服务层与主要页面补充代码注释,修复下载进度计算逻辑

This commit is contained in:
ZV Team committed 2026-10-27 20:46:03 +08:00
1 parent 7e618adf6c
commit 854f00038c
14 files changed
+244 -28

No files matched your search

+16
View File
@@ -1,6 +1,13 @@
import 'package:flutter/foundation.dart';
import '../data/services/secure_storage_service.dart';
/// 一台 Minecraft 服务器的连接配置。
///
/// 包含两组凭据:
/// - **RCON**(host / port / password):控制台命令、玩家管理;
/// - **SSH**(ssh* 字段):SFTP 文件操作、终端、日志。
///
/// 两组凭据相互独立,只填 RCON 也能正常使用控制台与玩家功能。
class ServerConfig {
final String id;
final String name;
@@ -41,6 +48,7 @@ class ServerConfig {
'sshPassword': sshPassword,
};
/// 从旧版本存档反序列化时,SSH 字段可能不存在,全部给默认值以兼容升级。
factory ServerConfig.fromJson(Map<String, dynamic> json) => ServerConfig(
id: json['id'],
name: json['name'],
@@ -54,8 +62,14 @@ class ServerConfig {
);
}
/// 服务器列表状态:增删改查 + 持久化。
///
/// 所有写操作都会立即落盘([SecureStorageService]),
/// 保证进程被杀后配置不丢。
class ServerProvider extends ChangeNotifier {
List<ServerConfig> _servers = [];
/// 对外暴露不可变视图,防止 UI 层直接修改内部列表导致状态不同步。
List<ServerConfig> get servers => List.unmodifiable(_servers);
Future<void> loadServers() async {
@@ -69,6 +83,7 @@ class ServerProvider extends ChangeNotifier {
notifyListeners();
}
/// 按 id 匹配替换(id 由创建时生成,编辑不改变 id)。
Future<void> updateServer(ServerConfig server) async {
final index = _servers.indexWhere((s) => s.id == server.id);
if (index != -1) _servers[index] = server;
@@ -82,6 +97,7 @@ class ServerProvider extends ChangeNotifier {
notifyListeners();
}
/// 按 id 查找;找不到(如服务器已被删除)返回 null。
ServerConfig? byId(String? id) {
if (id == null) return null;
try {