fix(m161): 收更新键/按钮/矮窗口/启动错误/导入结果五笔债

① update.auto_check / update.channel 登记进 core setting schema(1.6.0)
   - 新增 setting/keys/update.rs(两键 + UPDATE_CHANNELS,只允许 stable);
     SettingSchema 加 with_all 供域键表批量登记。
   - 新增 setting/update_prefs.rs:cache/update/prefs.json → launcher.json 的一次性迁移。
     四条硬约束:源指纹闸门(幂等)、不丢 false、新值胜出、旧文件改名 .migrated 后不再被读;
     主配置不可写时不动旧文件。收据 config/update-prefs-migration.json。
   - presenter Runtime 建会话时迁一次并把结局留在 migration();prefs 字段换成
     auto_check + 每次派发从主配置读 channel(不再硬编码 Channel::Stable)。
     保留旧字段 auto_check 的真实来源(原有测试 cases 会断言)。
   - CLI config get/set/dump 先跑同一次迁移(幂等),输出里给 migration 段与收据路径。

② presenter/dto/events.rs 的「本次会话不再弹提示条」注释改成真实语义
   (记的是版本号:同版本压住、更高版本照弹、手动检查清掉)。

③ 检查/下载进行中按钮禁用:pages/update/busy.rs 的 busy/can_check/can_apply;
   设置页两颗按钮改画禁用(不是消失),app 层 on_update_action 再挡一道
   (忙碌时 CheckNow/Apply 不派发);新增两条用例(含「忙完恢回可点」)。

④ 内容库低高度:content_layout::MIN_BODY_HEIGHT=460 + BodyMode(按固定件+三整行算出来,
   用例守着算式);frame::body_height 从 Ui::metrics 算正文可用高,pages::Model 带 window_height。
   ≥460 列表自己滚;<460 主列整列一个滚动条、列表按自然高度铺开。

⑤ 启动错误文案本地化:presenter 删掉 launch_summary / 「启动失败:」前缀 / 五条中文阶段前缀,
   改发 LaunchFailureView{stage,detail};LaunchFinished 改带 exit_code/uptime_ms/failure,
   Toast 由 app 层按 i18n key 现求(与 install_cancelled 同构)。InstancesFailed 拆成
   InstancesFailedStage(列表单行)+ LaunchStageFailed(详情/Toast 全文)。

⑥ 导入结果块:ImportReportView 加 failure_stage(NotStarted/RolledBack/RollbackIncomplete,
   由 core 的 rollback 机器位推出);标题、图标、底色三处分档,预检失败不再说「已回滚」。

顺带:六处注释/文档漂移(update.rs 的分工表与偏好落点、pack 的「已整包回滚」、
build_request 的 Errors、settings/update 的按钮禁用说明等),
以及为守 400 行把 update/cli-config/core-keys/presenter-dto/presenter-launch/i18n-golden
里贴线或越线的文件按模块拆开(纯搬移,行为不变)。
This commit is contained in:
AskaEth committed 2026-11-07 15:02:13 +08:00
1 parent b2d9f3927f
commit 03741ecd2d
69 files changed
+2653 -707

No files matched your search

+55 -21
View File
@@ -32,6 +32,10 @@ use crate::output::Report;
/// 敏感值在输出里的占位。
const MASK: &str = "<redacted>";
mod prefs_migration;
use prefs_migration::migrate_update_prefs;
/// `ull config get [<key>] [--show-secret]`。
///
/// # Errors
@@ -46,6 +50,9 @@ pub fn get(ctx: &Ctx, key: Option<&str>, show_secret: bool) -> Result<Report, Cl
/// 单键 get:读该键自己的落点文件(数据根键走便携目录那份)。
fn get_one(ctx: &Ctx, key: &str, show_secret: bool) -> Result<Report, CliError> {
// 先跑一次遗留偏好迁移(幂等;没有旧文件时只是一次 stat)。必须在 `load` **之前**:
// 迁移写的正是这份 `launcher.json`,先读后迁会让这一条输出还是旧值。
let migration = migrate_update_prefs(ctx);
let path = ctx.setting_path_for(key);
let store = SettingStore::load(&path, launcher_schema());
let schema = store.doc().schema().clone();
@@ -65,7 +72,7 @@ fn get_one(ctx: &Ctx, key: &str, show_secret: bool) -> Result<Report, CliError>
value.clone()
};
let problems = render_problems(&store);
let data = json!({
let mut data = json!({
"key": key,
"value": shown,
"redacted": hidden,
@@ -83,6 +90,12 @@ fn get_one(ctx: &Ctx, key: &str, show_secret: bool) -> Result<Report, CliError>
}
)];
human.push(format!("来自 {}", path.display()));
if let Some(note) = migration {
human.push(note.human);
if let Some(object) = data.as_object_mut() {
object.insert("migration".to_string(), note.data);
}
}
for problem in &problems {
human.push(format!("问题:{problem}"));
}
@@ -92,6 +105,7 @@ fn get_one(ctx: &Ctx, key: &str, show_secret: bool) -> Result<Report, CliError>
/// 无键全量 dump:以数据根那份为底,`core.*` 数据根键换成便携目录那份的生效值。
fn dump(ctx: &Ctx, show_secret: bool) -> Result<Report, CliError> {
let migration = migrate_update_prefs(ctx);
let path = ctx.launcher_config();
let store = SettingStore::load(&path, launcher_schema());
let schema = store.doc().schema().clone();
@@ -140,27 +154,33 @@ fn dump(ctx: &Ctx, show_secret: bool) -> Result<Report, CliError> {
ctx.data.game_home.display()
));
human.extend(text.lines().map(str::to_string));
if let Some(note) = &migration {
human.push(note.human.clone());
}
for problem in &problems {
human.push(format!("问题:{problem}"));
}
if masked {
human.push("(敏感值已掩码;加 --show-secret 显示明文)".to_string());
}
Ok(Report::new(
json!({
"path": path.display().to_string(),
"core_path": core_path.as_ref().map(|core| core.display().to_string()),
"config": document,
"redacted": masked,
"problems": problems,
"data_root": {
"mode": ctx.data.mode.as_str(),
"launcher_home": ctx.data.launcher_home.display().to_string(),
"game_home": ctx.data.game_home.display().to_string(),
},
}),
human,
))
let mut data = json!({
"path": path.display().to_string(),
"core_path": core_path.as_ref().map(|core| core.display().to_string()),
"config": document,
"redacted": masked,
"problems": problems,
"data_root": {
"mode": ctx.data.mode.as_str(),
"launcher_home": ctx.data.launcher_home.display().to_string(),
"game_home": ctx.data.game_home.display().to_string(),
},
});
if let Some(note) = migration {
if let Some(object) = data.as_object_mut() {
object.insert("migration".to_string(), note.data);
}
}
Ok(Report::new(data, human))
}
/// `ull config set <key> <value>`。
@@ -171,6 +191,8 @@ fn dump(ctx: &Ctx, show_secret: bool) -> Result<Report, CliError> {
///
/// 键不在 schema、值不合法、文件只读/不可读、写盘失败时返回用户错误。
pub fn set(ctx: &Ctx, key: &str, raw: &str) -> Result<Report, CliError> {
// 同一份遗留偏好先迁进来:否则用户「set 一个、get 另一个」会看到两份真相。
let migration = migrate_update_prefs(ctx);
let path = ctx.setting_path_for(key);
let mut store = SettingStore::load(&path, launcher_schema());
let sensitive = is_sensitive(store.doc().schema(), key);
@@ -195,7 +217,7 @@ pub fn set(ctx: &Ctx, key: &str, raw: &str) -> Result<Report, CliError> {
})?;
match &outcome {
SaveOutcome::Saved(saved) => {
let data = json!({
let mut data = json!({
"key": key,
"old": old,
"new": value,
@@ -209,13 +231,25 @@ pub fn set(ctx: &Ctx, key: &str, raw: &str) -> Result<Report, CliError> {
),
format!("已保存:{}", saved.display()),
];
if let Some(note) = migration {
human.push(note.human);
if let Some(object) = data.as_object_mut() {
object.insert("migration".to_string(), note.data);
}
}
human.extend(source_note(ctx, key));
Ok(Report::new(data, human))
}
SaveOutcome::Skipped(SkipReason::NotDirty) => Ok(Report::new(
json!({ "key": key, "new": value, "saved": null }),
vec![format!("{key} 已经是该值,未写盘")],
)),
SaveOutcome::Skipped(SkipReason::NotDirty) => {
let mut human = vec![format!("{key} 已经是该值,未写盘")];
if let Some(note) = &migration {
human.push(note.human.clone());
}
Ok(Report::new(
json!({ "key": key, "new": value, "saved": null }),
human,
))
}
SaveOutcome::Skipped(reason) => {
let error = CliError::user(
"config_read_only",
@@ -0,0 +1,70 @@
//! M159 的遗留更新偏好 → 主配置(`update.auto_check`)的迁移(M161)。
//!
//! 从 `commands/config.rs` 拆出:那边贴着 400 行硬线,而这块是**独立的一件事**
//! (遗留文件的桥接),与 get/set 的排版逻辑无关。
use serde_json::{json, Value};
use unlucky_core::setting::update_prefs::{self, Migration};
use crate::context::Ctx;
/// M159 的遗留更新偏好 → 主配置的迁移结果(只在**有话说**时返回)。
pub(super) struct PrefsNote {
/// 人读一行(`config get/set` 的人类可读输出里追加)
pub(super) human: String,
/// 同一件事的机器可读形状(`--json` 信封里追加)
pub(super) data: Value,
}
/// 把 `<数据根>/cache/update/prefs.json` 迁进 `launcher.json`(M161)。
///
/// 为什么 `config` 这个**读命令**也会写盘:那份遗留文件对 CLI 本来就不可见——用户在手头没 GUI
/// 的机器上 `config get update.auto_check`,旧实现永远回默认 `true`,而他的开关可能是关的。
/// 迁移是**幂等**的(源指纹闸门 + 旧文件改名 `.migrated`),有收据,且在写不进去时什么都不动
/// (见 [`unlucky_core::setting::update_prefs`])。没有旧文件时这里只是一次 `stat`。
pub(super) fn migrate_update_prefs(ctx: &Ctx) -> Option<PrefsNote> {
let layout = ctx.layout();
let paths = update_prefs::Targets {
launcher: &ctx.launcher_config(),
legacy: &layout.cache().join("update").join("prefs.json"),
receipt: &layout.config().join(update_prefs::RECEIPT_FILE),
};
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|elapsed| u64::try_from(elapsed.as_millis()).unwrap_or(u64::MAX))
.unwrap_or(0);
let migration = update_prefs::migrate(paths, now);
let (human, detail) = match &migration {
Migration::Nothing => return None,
Migration::Migrated { auto_check, .. } => (
format!(
"已把旧更新偏好迁入主配置:update.auto_check = {auto_check}(收据 {})",
paths.receipt.display()
),
format!("update.auto_check = {auto_check} 已迁移"),
),
Migration::NewValueWins { auto_check, .. } => (
format!(
"旧更新偏好文件已退役(主配置里已有 update.auto_check = {auto_check},新值胜出;收据 {})",
paths.receipt.display()
),
"旧文件已退役,主配置的值未改动".to_string(),
),
Migration::Unreadable { path, reason } => (
format!("旧更新偏好读不出来({}):{reason}", path.display()),
"旧文件坏,未迁移".to_string(),
),
Migration::Refused { reason } => (
format!("旧更新偏好未迁移:{reason}"),
"主配置不可写,未迁移".to_string(),
),
};
Some(PrefsNote {
human,
data: json!({
"id": migration.as_str(),
"receipt": migration.receipt().map(|path| path.display().to_string()),
"detail": detail,
}),
})
}
+64
View File
@@ -254,3 +254,67 @@ fn unknown_schema_prefix_warns_and_still_shows_file_values() {
report.human
);
}
/// M161:`ull config get update.auto_check` 读的是**主配置**,而且会把 M159 遗留的
/// `cache/update/prefs.json` 先迁进来(迁移收据在 `migration` 里可查)。
///
/// 这条是 mission「`ull config get update.auto_check` 真能读到」的端到端证明:
/// 旧文件里 `false` → 迁移 → 主配置 → CLI 输出 `false`(**不是**默认的 `true`)。
#[test]
fn the_update_switch_is_migrated_and_readable_from_the_cli() {
let temp = TempDir::new("update-prefs");
let exe = temp.path().join("exe");
let ctx = ctx_with(Globals::default(), &exe);
// 旧域内文件(M159 的落点):开关是关的。
let legacy = ctx.layout().cache().join("update").join("prefs.json");
write_json(&legacy, &json!({ "auto_check": false }));
let report = get(&ctx, Some("update.auto_check"), false).expect("读 update.auto_check");
assert_eq!(
report.data["value"],
json!(false),
"旧文件里的 false 必须读到(默认值是 true,读成默认就是丢值)"
);
assert_eq!(
report.data["path"],
json!(ctx.launcher_config().display().to_string()),
"落点必须是主配置(schema API),不是更新域自己的文件"
);
assert_eq!(
report.data["migration"]["id"],
json!("migrated"),
"迁移要走一遍并如实报出来:{report:?}"
);
let receipt = report.data["migration"]["receipt"]
.as_str()
.expect("收据路径")
.to_string();
assert!(Path::new(&receipt).is_file(), "收据可查:{receipt}");
assert!(!legacy.exists(), "旧文件必须退役");
assert!(
report
.human
.iter()
.any(|line| line.contains("已把旧更新偏好迁入主配置")),
"{:?}",
report.human
);
// 第二遍:什么都不做(幂等),值仍是 false。
let again = get(&ctx, Some("update.auto_check"), false).expect("再读一遍");
assert_eq!(again.data["value"], json!(false));
assert!(
again.data.get("migration").is_none(),
"第二遍不该再报迁移:{again:?}"
);
// `channels` 里只有 stable 时,写 beta 要当面被拒(而不是静默写成「设了没生效」)。
let error = set(&ctx, "update.channel", "beta").expect_err("beta 不在允许值里");
assert!(error.to_string().contains("beta"), "{error}");
// 允许值写得进去,且读得回来。
set(&ctx, "update.channel", "stable").expect("写 stable");
let channel = get(&ctx, Some("update.channel"), false).expect("读 update.channel");
assert_eq!(channel.data["value"], json!("stable"));
}