app 从「mock 骨架」切到「真实 core host」:新增 src/host 装配层(env/job/ game/launch/identity/versions/install/meter/java/accounts/logs/settings/engine/ dispatch),是 app 里除 settings_bridge 外唯一 use unlucky_core 的地方,出口只有 crate::dto 的 DTO/事件(三通道纪律,AGENTS §6)。 页面接线: - 实例页:profiles+版本 JSON 继承链+会话索引 → 磁贴(真实版本/加载器徽标/最后启动/ 隔离档位/载荷缺失);启动按钮走 LaunchRequest 装配 → Launcher::spawn → JSONL 尾随 → 运行/失败回写;M30 ModeChangeWarning 进横幅通知条。 - 新建实例向导:版本 → 加载器 → 名字 → 确认 → 真实安装进度;Fabric/Quilt 可装, Forge/NeoForge 因需要 installer processors(仅 CLI 有)显式拒装并给出 CLI 命令。 - 下载页:远端 manifest(12h 缓存)+ 内嵌 unlisted → 分类(正式/预览/远古四子类); 安装进度(文件数/字节/速度/ETA,速度由相邻采样差分)+ 阶段边界可取消; Java 分组:四家发行版 + 回退链可视化(计划链/真实 ChainLog)+ 本地运行时。 - 账户页:三轨账户列表(只读公开字段)+ 离线新增 + 删除/切换 + 微软设备码登录 (用户码/链接/轮询状态;取消后丢弃结果)。凭据只在 host/identity 与 host/accounts 出现,DTO 无 token 字段(单测钉住)。 - 设置页:新增 download/java/data/ai/mcp 五组,行由 core::setting schema 键生成, 写回走 SettingStore::set(与 ull config set / AI set_config 同源 launcher.json)。 - 日志页:会话索引 → 列表;事件 JSONL → 日志行(等级高亮)+ D8 规则引擎诊断卡片; 启动中实时尾随(600ms/拍,只读新增字节);崩溃日志导入分析(hs_err/crash/latest)。 架构与守线: - 新页面状态走 ui/page_state.slint 的 PageState global(main.slint 再导出), Rust 侧 page_sync.rs 灌入、callbacks_pages.rs 接线;避免属性逐层转发顶破 400 行。 - DTO 全部 Serialize+Deserialize(IPC 契约),新增 accounts/java/settings/install/ notices 五个子模块;事件扩展 LogAppended/LaunchFinished/AccountsChanged/ DeviceLoginChanged/JavaChanged/InstallProgress/SettingsChanged/NoticesChanged。 - 截图通道扩展:--data-dir(钉数据根且 settings 同源)/--mock/--screenshot-page/ --screenshot-wizard/--screenshot-session/--screenshot-install/--screenshot-launch (真实中间态,取图后自动 stop 防孤儿进程)。 已知边界:GUI 账户「当前启动账户」仅内存态(core schema 无 auth.* 键,app 不自建键); Forge/NeoForge GUI 安装待 processors 执行器上移。
221 lines
6.4 KiB
Rust
221 lines
6.4 KiB
Rust
//! 设置页 DTO:设置分组的通用行模型。
|
||
//!
|
||
//! 「行」是 UI 与 `core::setting` schema 之间的唯一形状:一行 = 一个键 + 一种控件 +
|
||
//! 当前值。写回走 [`crate::dto::AppCommand::SetSetting`],由 host 用 `SettingStore::set`
|
||
//! 落盘(不自己拼 JSON、不另立配置文件,`AGENTS §6`)。
|
||
|
||
use serde::{Deserialize, Serialize};
|
||
|
||
/// 控件类型(决定设置页画什么)。
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub enum SettingControl {
|
||
/// 开关
|
||
Toggle,
|
||
/// 分段单选(`options` + `selected`)
|
||
Choice,
|
||
/// 单行文本(`value_text`)
|
||
Text,
|
||
/// 只读展示(当前路径/当前版本这类)
|
||
ReadOnly,
|
||
/// 动作按钮(`action` 给回调 id)
|
||
Action,
|
||
}
|
||
|
||
/// 一行设置。
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub struct SettingRowView {
|
||
/// schema 键(`download.concurrency`)
|
||
pub key: String,
|
||
/// 行标题
|
||
pub label: String,
|
||
/// 说明/当前值附注
|
||
pub description: String,
|
||
/// 控件
|
||
pub control: SettingControl,
|
||
/// 开关值
|
||
pub flag: bool,
|
||
/// 单选序号
|
||
pub selected: i32,
|
||
/// 单选项文案
|
||
pub options: Vec<String>,
|
||
/// 文本值
|
||
pub value_text: String,
|
||
/// 动作 id(`detect_region` 这类)
|
||
pub action: String,
|
||
}
|
||
|
||
impl SettingRowView {
|
||
/// 开关行。
|
||
pub fn toggle(key: &str, label: &str, description: &str, value: bool) -> Self {
|
||
Self {
|
||
key: key.to_string(),
|
||
label: label.to_string(),
|
||
description: description.to_string(),
|
||
control: SettingControl::Toggle,
|
||
flag: value,
|
||
selected: 0,
|
||
options: Vec::new(),
|
||
value_text: String::new(),
|
||
action: String::new(),
|
||
}
|
||
}
|
||
|
||
/// 单选行。
|
||
pub fn choice(
|
||
key: &str,
|
||
label: &str,
|
||
description: &str,
|
||
options: &[&str],
|
||
selected: i32,
|
||
) -> Self {
|
||
Self {
|
||
key: key.to_string(),
|
||
label: label.to_string(),
|
||
description: description.to_string(),
|
||
control: SettingControl::Choice,
|
||
flag: false,
|
||
selected,
|
||
options: options.iter().map(|item| (*item).to_string()).collect(),
|
||
value_text: String::new(),
|
||
action: String::new(),
|
||
}
|
||
}
|
||
|
||
/// 文本行。
|
||
pub fn text(key: &str, label: &str, description: &str, value: &str) -> Self {
|
||
Self {
|
||
key: key.to_string(),
|
||
label: label.to_string(),
|
||
description: description.to_string(),
|
||
control: SettingControl::Text,
|
||
flag: false,
|
||
selected: 0,
|
||
options: Vec::new(),
|
||
value_text: value.to_string(),
|
||
action: String::new(),
|
||
}
|
||
}
|
||
|
||
/// 只读行。
|
||
pub fn read_only(label: &str, value: &str) -> Self {
|
||
Self {
|
||
key: String::new(),
|
||
label: label.to_string(),
|
||
description: value.to_string(),
|
||
control: SettingControl::ReadOnly,
|
||
flag: false,
|
||
selected: 0,
|
||
options: Vec::new(),
|
||
value_text: value.to_string(),
|
||
action: String::new(),
|
||
}
|
||
}
|
||
|
||
/// 动作行。
|
||
pub fn action(key: &str, label: &str, description: &str, action: &str) -> Self {
|
||
Self {
|
||
key: key.to_string(),
|
||
label: label.to_string(),
|
||
description: description.to_string(),
|
||
control: SettingControl::Action,
|
||
flag: false,
|
||
selected: 0,
|
||
options: Vec::new(),
|
||
value_text: String::new(),
|
||
action: action.to_string(),
|
||
}
|
||
}
|
||
}
|
||
|
||
/// 一个设置分组(设置页右栏的一段)。
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub struct SettingGroupView {
|
||
/// 分组 id(与设置页子导航的 `SettingSection` 同名:download / java / data / ai / mcp)
|
||
pub id: String,
|
||
/// 分组标题
|
||
pub title: String,
|
||
/// 行
|
||
pub rows: Vec<SettingRowView>,
|
||
}
|
||
|
||
impl SettingGroupView {
|
||
/// 建组。
|
||
pub fn new(id: &str, title: &str) -> Self {
|
||
Self {
|
||
id: id.to_string(),
|
||
title: title.to_string(),
|
||
rows: Vec::new(),
|
||
}
|
||
}
|
||
|
||
/// 追加一行(链式)。
|
||
pub fn with(mut self, row: SettingRowView) -> Self {
|
||
self.rows.push(row);
|
||
self
|
||
}
|
||
}
|
||
|
||
/// 在分组快照里找一个键的当前值(设置页回填用)。
|
||
pub fn find_row<'a>(groups: &'a [SettingGroupView], key: &str) -> Option<&'a SettingRowView> {
|
||
groups
|
||
.iter()
|
||
.flat_map(|group| group.rows.iter())
|
||
.find(|row| row.key == key)
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
|
||
#[test]
|
||
fn rows_carry_exactly_one_control_kind() {
|
||
let toggle = SettingRowView::toggle("agent.mcp.enabled", "MCP", "", true);
|
||
assert_eq!(toggle.control, SettingControl::Toggle);
|
||
assert!(toggle.flag);
|
||
|
||
let choice = SettingRowView::choice("download.region", "地区", "", &["auto", "cn"], 1);
|
||
assert_eq!(choice.options, vec!["auto", "cn"]);
|
||
assert_eq!(choice.selected, 1);
|
||
|
||
let action = SettingRowView::action("java.action", "检测", "", "detect_region");
|
||
assert_eq!(action.action, "detect_region");
|
||
}
|
||
|
||
#[test]
|
||
fn find_row_scans_all_groups() {
|
||
let groups = vec![
|
||
SettingGroupView::new("download", "下载").with(SettingRowView::text(
|
||
"download.proxy_url",
|
||
"代理",
|
||
"",
|
||
"",
|
||
)),
|
||
SettingGroupView::new("mcp", "MCP").with(SettingRowView::toggle(
|
||
"agent.mcp.enabled",
|
||
"开关",
|
||
"",
|
||
false,
|
||
)),
|
||
];
|
||
assert_eq!(
|
||
find_row(&groups, "agent.mcp.enabled").map(|row| row.label.as_str()),
|
||
Some("开关")
|
||
);
|
||
assert!(find_row(&groups, "nope").is_none());
|
||
}
|
||
|
||
#[test]
|
||
fn rows_are_serde_round_trip_safe() {
|
||
let group = SettingGroupView::new("download", "下载").with(SettingRowView::choice(
|
||
"download.concurrency",
|
||
"并发",
|
||
"",
|
||
&["4", "8", "16"],
|
||
1,
|
||
));
|
||
let text = serde_json::to_string(&group).expect("序列化");
|
||
let back: SettingGroupView = serde_json::from_str(&text).expect("反序列化");
|
||
assert_eq!(back, group);
|
||
}
|
||
}
|