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:
1 parent
b2d9f3927f
commit
03741ecd2d
69 files changed
+2653
-707
No files matched your search
@@ -168,6 +168,9 @@ pub struct App {
|
||||
/// 已经提示过的取消次数(M105):`AppState::install_cancelled` 是「发生过几次取消」,
|
||||
/// 这里是「其中几次已经弹过提示」。两者不等 ⇒ 弹一次 i18n 提示。
|
||||
pub(super) install_cancelled_seen: u64,
|
||||
/// 已经提示过的启动收尾次数(M161):`AppState::launch_ends` 是「收尾过几场」,
|
||||
/// 这里是「其中几场已经弹过 Toast」。两者不等 ⇒ 弹一次(与 `install_cancelled_seen` 同构)。
|
||||
pub(super) launch_ends_seen: u64,
|
||||
/// 内容库页的页面内选择(M109):内容类型 / 选中项目 / 目标实例 / 关键词草稿。
|
||||
///
|
||||
/// 为什么在 `App` 而不是 presenter:这四样是「用户在这一屏上点了什么」,重建快照不该冲掉;
|
||||
|
||||
@@ -89,6 +89,7 @@ impl App {
|
||||
let mut view = pages::Model::new(
|
||||
pages::Screen::Instances,
|
||||
width,
|
||||
height,
|
||||
Some(pages::Screen::Instances.nav()),
|
||||
);
|
||||
view.lang = lang.lang();
|
||||
@@ -126,6 +127,7 @@ impl App {
|
||||
download_draft: pages::InstallDraft::default(),
|
||||
launch_form: pages::LaunchForm::default(),
|
||||
install_cancelled_seen: 0,
|
||||
launch_ends_seen: 0,
|
||||
content: pages::content::PageState::default(),
|
||||
account_form: pages::account::Form::new(),
|
||||
account: pages::account::Page::build(
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
use unlucky_presenter::toast::ToastKind;
|
||||
|
||||
use crate::app::view;
|
||||
use crate::pages;
|
||||
|
||||
use unlucky_presenter::router::Route;
|
||||
@@ -36,6 +37,23 @@ impl App {
|
||||
self.state.toasts.push(ToastKind::Info, text);
|
||||
}
|
||||
|
||||
// M161:启动收尾的提示语也在这里弹(presenter 只发结构:结局 + 退出码 + 失败阶段)。
|
||||
// 此前 presenter 直接推一条自己拼好的中文 Toast,英文界面会弹中文。
|
||||
if self.state.launch_ends != self.launch_ends_seen {
|
||||
self.launch_ends_seen = self.state.launch_ends;
|
||||
if let Some(finished) = self.state.last_launch_end.as_deref() {
|
||||
let text = view::instances::launch_toast(finished, self.lang());
|
||||
let kind = if finished.outcome == unlucky_presenter::dto::LogOutcome::Ok
|
||||
&& finished.failure.is_none()
|
||||
{
|
||||
ToastKind::Success
|
||||
} else {
|
||||
ToastKind::Error
|
||||
};
|
||||
self.state.toasts.push(kind, text);
|
||||
}
|
||||
}
|
||||
|
||||
// 分类是**页面自己持有的过滤条件**(真 host 丢弃 `ListVersions` 的分类参数):
|
||||
// 重建视图模型时带回去,否则每次事件都会把 chip 打回「全部」(复审 P2-1)。
|
||||
let category = self.view.download.category;
|
||||
@@ -48,6 +66,7 @@ impl App {
|
||||
self.view = super::super::view::model(
|
||||
&self.state,
|
||||
width,
|
||||
self.height,
|
||||
self.options.force_state,
|
||||
category,
|
||||
&draft,
|
||||
|
||||
@@ -20,8 +20,18 @@ impl App {
|
||||
/// 一条更新动作。
|
||||
pub(super) fn on_update_action(&mut self, action: UpdateAction) -> Task<Message> {
|
||||
match action {
|
||||
UpdateAction::CheckNow => self.dispatch(AppCommand::CheckUpdate),
|
||||
UpdateAction::Apply => self.dispatch(AppCommand::ApplyUpdate),
|
||||
UpdateAction::CheckNow => {
|
||||
if self.update_busy() {
|
||||
return self.refuse_busy("立即检查");
|
||||
}
|
||||
self.dispatch(AppCommand::CheckUpdate)
|
||||
}
|
||||
UpdateAction::Apply => {
|
||||
if self.update_busy() {
|
||||
return self.refuse_busy("下载并安装");
|
||||
}
|
||||
self.dispatch(AppCommand::ApplyUpdate)
|
||||
}
|
||||
UpdateAction::Dismiss => self.dispatch(AppCommand::DismissUpdate),
|
||||
UpdateAction::SetAutoCheck(on) => self.dispatch(AppCommand::SetUpdateAutoCheck(on)),
|
||||
UpdateAction::RestartNow => return self.restart_now(),
|
||||
@@ -29,6 +39,25 @@ impl App {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
/// 有没有一条检查/下载正在跑。
|
||||
///
|
||||
/// 与 `pages::Update::busy()` **同一个判据**(`applying` 或 `status == Checking`):
|
||||
/// presenter 的 `begin_check` / `begin_apply` 在 inflight 时静默 `return None`,
|
||||
/// 所以「忙碌」这件事必须在按下之前就挡住——否则用户点了没反应,还以为按钮坏了(M161)。
|
||||
///
|
||||
/// 这一层是**最后一道**:按钮已经画成禁用(`pages/settings/update.rs` 的 `can_check` /
|
||||
/// `can_apply`),但快捷键/未来新增的入口仍会走到这里。
|
||||
fn update_busy(&self) -> bool {
|
||||
let view = &self.state.update;
|
||||
view.applying || view.outcome.is_checking()
|
||||
}
|
||||
|
||||
/// 忙碌时把这条动作丢掉(不派发、不乐观改状态),并在日志里留一行取证。
|
||||
fn refuse_busy(&self, what: &str) -> Task<Message> {
|
||||
eprintln!("[update] 已有一条检查/下载在跑,忽略重复的「{what}」");
|
||||
Task::none()
|
||||
}
|
||||
|
||||
/// 立即重启:按同样的命令行拉起自己,然后退出。
|
||||
///
|
||||
/// 截图通道(`--screenshot`)**不重启**:那条路每跑一次就该落一张图然后退出,重启会覆盖同一
|
||||
@@ -142,6 +171,47 @@ mod tests {
|
||||
assert_eq!(last(&seen), AppCommand::SetUpdateAutoCheck(false));
|
||||
}
|
||||
|
||||
/// **忙碌时按下去不发命令**(M161:此前点了没反应,因为 presenter 在 inflight 时静默返回)。
|
||||
///
|
||||
/// 三条都要钉住:①`Checking` 时「立即检查」不派发;②`applying` 时「下载并安装」不派发;
|
||||
/// ③忙碌结束后**恢回可点**(失败/超时不该把按钮永久钉死)。
|
||||
#[test]
|
||||
fn pressing_while_busy_dispatches_nothing() {
|
||||
let (mut app, seen) = app();
|
||||
|
||||
app.state.update.outcome = unlucky_presenter::dto::UpdateOutcome::Checking;
|
||||
let _ = app.on_update_action(UpdateAction::CheckNow);
|
||||
assert!(
|
||||
seen.lock()
|
||||
.unwrap_or_else(|poisoned| poisoned.into_inner())
|
||||
.is_empty(),
|
||||
"正在检查时再按「立即检查」不许派发第二条命令"
|
||||
);
|
||||
|
||||
// 检查回来(失败也算回来):不忙了,能再点。
|
||||
app.state.update.outcome = unlucky_presenter::dto::UpdateOutcome::Failed(
|
||||
unlucky_presenter::dto::UpdateFailureView::new("network", "连不上", true),
|
||||
);
|
||||
let _ = app.on_update_action(UpdateAction::CheckNow);
|
||||
assert_eq!(last(&seen), AppCommand::CheckUpdate, "失败之后要能重试");
|
||||
|
||||
// 下载/校验/替换期间:`Apply` 与 `CheckNow` 都不许派发。
|
||||
let before = seen.lock().unwrap_or_else(|p| p.into_inner()).len();
|
||||
app.state.update.applying = true;
|
||||
let _ = app.on_update_action(UpdateAction::Apply);
|
||||
let _ = app.on_update_action(UpdateAction::CheckNow);
|
||||
assert_eq!(
|
||||
seen.lock().unwrap_or_else(|p| p.into_inner()).len(),
|
||||
before,
|
||||
"applying 期间不许派发任何新的检查/安装"
|
||||
);
|
||||
|
||||
// 应用结束:恢复可点。
|
||||
app.state.update.applying = false;
|
||||
let _ = app.on_update_action(UpdateAction::Apply);
|
||||
assert_eq!(last(&seen), AppCommand::ApplyUpdate, "失败/完成后恢回可点");
|
||||
}
|
||||
|
||||
/// 截图通道不重启:取证进程不许把自己重启成死循环。
|
||||
#[test]
|
||||
fn the_screenshot_channel_never_restarts() {
|
||||
|
||||
@@ -21,12 +21,12 @@ use super::state::{log_first_frame, App};
|
||||
use super::APP_TITLE;
|
||||
|
||||
mod account_page;
|
||||
mod instances;
|
||||
pub(super) mod instances;
|
||||
mod logs;
|
||||
mod rail;
|
||||
mod update;
|
||||
|
||||
use instances::{detail_of, runtime_status, supporting_line};
|
||||
use instances::{detail_of, runtime_status_row, supporting_line};
|
||||
use logs::logs_model;
|
||||
use update::update_of;
|
||||
|
||||
@@ -140,6 +140,7 @@ impl App {
|
||||
pub(super) fn model(
|
||||
state: &AppState,
|
||||
width: f32,
|
||||
height: f32,
|
||||
forced: Option<crate::cli::ForcedState>,
|
||||
category: pages::Category,
|
||||
draft: &pages::InstallDraft,
|
||||
@@ -158,7 +159,7 @@ pub(super) fn model(
|
||||
id: cell.instance.id.clone(),
|
||||
name: cell.instance.name.clone(),
|
||||
supporting: supporting_line(cell.instance, catalog),
|
||||
status: runtime_status(&cell.instance.runtime, catalog),
|
||||
status: runtime_status_row(&cell.instance.runtime, catalog),
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -174,6 +175,7 @@ pub(super) fn model(
|
||||
pages::Model {
|
||||
screen,
|
||||
window_width: width,
|
||||
window_height: height,
|
||||
active: route.nav(),
|
||||
instances: pages::Instances { rows, detail },
|
||||
download: pages::Download::from_snapshot(state, category, draft, lang.catalog()),
|
||||
|
||||
@@ -18,8 +18,11 @@
|
||||
//! 2. **运行状态只翻标签本体**:`Running · pid 1234` → `运行中 · pid 1234`,`pid` 与数字、
|
||||
//! `·` 分隔符一个字都不动([`Key::InstancesRunning`] 的占位符只有 `{pid}`)。
|
||||
|
||||
use unlucky_i18n::{Catalog, Key};
|
||||
use unlucky_presenter::dto::{InstanceRuntime, InstanceSummary, LaunchStage, LoaderKind};
|
||||
use unlucky_i18n::{Catalog, Key, Lang};
|
||||
use unlucky_presenter::dto::{
|
||||
InstanceRuntime, InstanceSummary, LaunchFailureStage, LaunchFinished, LaunchStage, LoaderKind,
|
||||
LogOutcome,
|
||||
};
|
||||
|
||||
use crate::pages::{Detail, LaunchFacts, Meta};
|
||||
|
||||
@@ -59,7 +62,7 @@ fn isolation(raw: &str, catalog: Catalog) -> String {
|
||||
}
|
||||
|
||||
/// 运行状态(列表行的 overline 与详情页的状态行共用一份文案)。
|
||||
pub(super) fn runtime_status(runtime: &InstanceRuntime, catalog: Catalog) -> Option<String> {
|
||||
pub(crate) fn runtime_status(runtime: &InstanceRuntime, catalog: Catalog) -> Option<String> {
|
||||
match runtime {
|
||||
InstanceRuntime::Idle => None,
|
||||
// 「阶段 · 百分比」:百分比是数字,不过词表;只有阶段名换语言
|
||||
@@ -71,13 +74,78 @@ pub(super) fn runtime_status(runtime: &InstanceRuntime, catalog: Catalog) -> Opt
|
||||
InstanceRuntime::Running { pid } => {
|
||||
Some(catalog.render(Key::InstancesRunning, &[("pid", &pid.to_string())]))
|
||||
}
|
||||
// `reason` 是 core 给的诊断原文(**数据**,不翻译);只有前半句是界面文案
|
||||
InstanceRuntime::Failed { reason } => {
|
||||
Some(catalog.render(Key::InstancesFailed, &[("reason", reason)]))
|
||||
}
|
||||
// `detail` 是 core/io 给的原文(**数据**,不翻译);「哪一步」与前半句是界面文案。
|
||||
// M161 之前这里只有 `reason`,而 reason 里已经是「启动失败:…」,于是英文界面会出现
|
||||
// 「Launch failed · 启动失败:找不到 Java」——半句英文半句中文。
|
||||
//
|
||||
// 这一份是**详情页**用的全文(详情列会自动换行);列表行那份是 [`runtime_status_row`]
|
||||
// (单行、不许折行,见 D-M79-5)。
|
||||
InstanceRuntime::Failed { stage, detail } => Some(catalog.render(
|
||||
Key::LaunchStageFailed,
|
||||
&[
|
||||
("stage", failure_stage_label(*stage, catalog)),
|
||||
("detail", detail.as_str()),
|
||||
],
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// 列表行用的运行状态:**单行**(`ListItem` 的 overline 不折行,D-M79-5)。
|
||||
///
|
||||
/// 与 [`runtime_status`] 只差一处:失败时不带 `detail`——那一段是原始错误文本(可能是一长串
|
||||
/// 路径),放进 60/76 高的单行 overline 会被裁成半截字。全文在**详情页**([`runtime_status`])。
|
||||
pub(crate) fn runtime_status_row(runtime: &InstanceRuntime, catalog: Catalog) -> Option<String> {
|
||||
match runtime {
|
||||
InstanceRuntime::Failed { stage, .. } => Some(catalog.render(
|
||||
Key::InstancesFailedStage,
|
||||
&[("stage", failure_stage_label(*stage, catalog))],
|
||||
)),
|
||||
other => runtime_status(other, catalog),
|
||||
}
|
||||
}
|
||||
|
||||
/// 失败阶段文案(presenter 给 slug,界面在这里选词)。
|
||||
///
|
||||
/// 与 [`stage_label`] 同一套做法:**不**复用 presenter 侧的任何中文常量。
|
||||
pub(crate) fn failure_stage_label(stage: LaunchFailureStage, catalog: Catalog) -> &'static str {
|
||||
catalog.text(match stage {
|
||||
LaunchFailureStage::VersionManifest => Key::LaunchStageVersionManifest,
|
||||
LaunchFailureStage::Inheritance => Key::LaunchStageInheritance,
|
||||
LaunchFailureStage::InstanceConfig => Key::LaunchStageInstanceConfig,
|
||||
LaunchFailureStage::Isolation => Key::LaunchStageIsolation,
|
||||
LaunchFailureStage::Identity => Key::LaunchStageIdentity,
|
||||
LaunchFailureStage::Spawn => Key::LaunchStageSpawn,
|
||||
})
|
||||
}
|
||||
|
||||
/// 一次启动收尾的 Toast 文案(**唯一的产地**:presenter 只发结构,不拼句子)。
|
||||
///
|
||||
/// 三种结局各有各的说法:正常结束报时长,崩溃/静默失败报「结局 + 阶段 + 原文」,
|
||||
/// 组装阶段就失败(`failure` 有值)报「哪一步 + 原文」。
|
||||
#[must_use]
|
||||
pub(crate) fn launch_toast(finished: &LaunchFinished, lang: Lang) -> String {
|
||||
let catalog = lang.catalog();
|
||||
if let Some(failure) = &finished.failure {
|
||||
return catalog.render(
|
||||
Key::LaunchStageFailed,
|
||||
&[
|
||||
("stage", failure_stage_label(failure.stage, catalog)),
|
||||
("detail", failure.detail.as_str()),
|
||||
],
|
||||
);
|
||||
}
|
||||
let outcome = catalog.text(match finished.outcome {
|
||||
LogOutcome::Ok => Key::LaunchOutcomeNormal,
|
||||
LogOutcome::Crashed => Key::LaunchOutcomeCrash,
|
||||
LogOutcome::SilentFail => Key::LaunchOutcomeSilent,
|
||||
});
|
||||
let seconds = format!("{:.1}", finished.uptime_ms as f64 / 1000.0);
|
||||
catalog.render(
|
||||
Key::LaunchToastEnded,
|
||||
&[("outcome", outcome), ("seconds", seconds.as_str())],
|
||||
)
|
||||
}
|
||||
|
||||
/// 阶段文案:**不**复用 `LaunchStage::label()`(那是核心层的中文诊断串,英文界面会漏中文)。
|
||||
fn stage_label(stage: LaunchStage, catalog: Catalog) -> &'static str {
|
||||
catalog.text(match stage {
|
||||
|
||||
@@ -74,7 +74,9 @@ fn crashed_only() -> AppState {
|
||||
id: "dev".to_string(),
|
||||
session: CRASH.to_string(),
|
||||
outcome: LogOutcome::Crashed,
|
||||
summary: "崩溃(exit 1)".to_string(),
|
||||
exit_code: Some(1),
|
||||
uptime_ms: 3_000,
|
||||
failure: None,
|
||||
}));
|
||||
|
||||
state
|
||||
@@ -166,7 +168,9 @@ fn an_imported_crash_file_still_shows_its_findings() {
|
||||
id: "dev".to_string(),
|
||||
session: CRASH.to_string(),
|
||||
outcome: LogOutcome::Crashed,
|
||||
summary: "崩溃(exit 1)".to_string(),
|
||||
exit_code: Some(1),
|
||||
uptime_ms: 3_000,
|
||||
failure: None,
|
||||
}));
|
||||
state.apply_core(CoreEvent::DiagnosisReady(report(
|
||||
"file:crash-2026-11-02_19.40.15-client.txt",
|
||||
|
||||
@@ -39,6 +39,7 @@ fn at_lang(state: &AppState, forced: Option<crate::cli::ForcedState>, lang: Lang
|
||||
model(
|
||||
state,
|
||||
1180.0,
|
||||
760.0,
|
||||
forced,
|
||||
pages::Category::All,
|
||||
&draft,
|
||||
@@ -125,11 +126,18 @@ fn a_busy_instance_offers_stop_instead_of_play() {
|
||||
#[test]
|
||||
fn failed_instances_can_be_retried() {
|
||||
let failed = instance(InstanceRuntime::Failed {
|
||||
reason: "exit 1".to_string(),
|
||||
stage: unlucky_presenter::dto::LaunchFailureStage::Spawn,
|
||||
detail: "exit 1".to_string(),
|
||||
});
|
||||
// 列表行是**单行**:只放「哪一步」(原文太长会被 `Wrapping::None` 裁成半截字)。
|
||||
assert_eq!(
|
||||
runtime_status(&failed.runtime, Lang::En.catalog()).as_deref(),
|
||||
Some("Launch failed · exit 1")
|
||||
super::instances::runtime_status_row(&failed.runtime, Lang::En.catalog()).as_deref(),
|
||||
Some("Launch failed · Starting the game process")
|
||||
);
|
||||
// 详情页给全文(阶段 + 原文)。
|
||||
assert_eq!(
|
||||
super::instances::runtime_status(&failed.runtime, Lang::En.catalog()).as_deref(),
|
||||
Some("Launch failed · Starting the game process: exit 1")
|
||||
);
|
||||
assert!(
|
||||
detail_of(&failed, Lang::En.catalog()).can_launch,
|
||||
@@ -319,3 +327,67 @@ fn the_agent_route_has_no_page() {
|
||||
assert!(model.instances.detail.is_none());
|
||||
assert_eq!(model.active, None, "AI 页不高亮任何导航项");
|
||||
}
|
||||
|
||||
/// **启动收尾的提示语跟着界面语言走**(M161 收的债)。
|
||||
///
|
||||
/// 此前 `LaunchFinished.summary` 是 presenter 拼的中文,英文界面上弹的就是中文;
|
||||
/// 现在 presenter 只给结构(结局 + 退出码 + 失败阶段),文案在这里按 key 现求。
|
||||
///
|
||||
/// 抓得住:①谁把中文串再写回 presenter(英文那一行会露中文);②失败时丢掉 `detail`
|
||||
/// (原文是取证信息,不许翻也不许删);③「跑起来再崩」被说成「启动失败在某一步」。
|
||||
#[test]
|
||||
fn the_launch_toast_speaks_the_interface_language() {
|
||||
use unlucky_presenter::dto::{
|
||||
LaunchFailureStage, LaunchFailureView, LaunchFinished, LogOutcome,
|
||||
};
|
||||
|
||||
let finished = |outcome, failure| LaunchFinished {
|
||||
id: "survival".to_string(),
|
||||
session: "20261031T120000-abcd12".to_string(),
|
||||
outcome,
|
||||
exit_code: Some(1),
|
||||
uptime_ms: 12_500,
|
||||
failure,
|
||||
};
|
||||
|
||||
// 正常结束:只报结局 + 时长(`正常结束 · 12.5 秒` / `Finished normally · 12.5s`)。
|
||||
let ok = finished(LogOutcome::Ok, None);
|
||||
let en = super::instances::launch_toast(&ok, Lang::En);
|
||||
let zh = super::instances::launch_toast(&ok, Lang::ZhCn);
|
||||
assert_eq!(en, "Finished normally · 12.5s");
|
||||
assert_eq!(zh, "正常结束 · 12.5 秒");
|
||||
assert_ne!(en, zh, "切语言时提示语要变");
|
||||
|
||||
// 装配阶段失败:说清**哪一步**,并把原文原样带出来。
|
||||
let failed = finished(
|
||||
LogOutcome::Crashed,
|
||||
Some(LaunchFailureView::new(
|
||||
LaunchFailureStage::InstanceConfig,
|
||||
"permission denied (os error 5)",
|
||||
)),
|
||||
);
|
||||
let en = super::instances::launch_toast(&failed, Lang::En);
|
||||
let zh = super::instances::launch_toast(&failed, Lang::ZhCn);
|
||||
assert!(
|
||||
en.starts_with("Launch failed · Reading the instance settings"),
|
||||
"{en}"
|
||||
);
|
||||
assert!(zh.starts_with("启动失败 · 读实例设置"), "{zh}");
|
||||
for text in [&en, &zh] {
|
||||
assert!(
|
||||
text.contains("permission denied (os error 5)"),
|
||||
"原文(取证信息)不许丢:{text}"
|
||||
);
|
||||
}
|
||||
// 英文界面里不许出现中文(反之亦然)——这条是本次债的核心。
|
||||
assert!(!en.chars().any(is_cjk), "英文提示里混了中文:{en}");
|
||||
assert!(
|
||||
!zh.contains("Launch failed"),
|
||||
"中文提示里混了英文前缀:{zh}"
|
||||
);
|
||||
}
|
||||
|
||||
/// 有没有中文字符(上面那条「不许混语言」的判据)。
|
||||
fn is_cjk(ch: char) -> bool {
|
||||
('\u{4e00}'..='\u{9fff}').contains(&ch)
|
||||
}
|
||||
@@ -81,8 +81,9 @@ pub fn view<'a>(
|
||||
metrics: FrameMetrics,
|
||||
model: &'a Content,
|
||||
lang: Lang,
|
||||
window_height: f32,
|
||||
) -> Element<'a, PageMessage> {
|
||||
view::view(ui, metrics, model, lang)
|
||||
view::view(ui, metrics, model, lang, window_height)
|
||||
}
|
||||
|
||||
/// 演示数据(`pages_demo` 出图与单测用;产品路径走 `Content::from_snapshot`)。
|
||||
|
||||
@@ -74,6 +74,53 @@ impl Tier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 主列在**矮窗口**下切成「整列一个滚动条」的门槛(M161)。
|
||||
///
|
||||
/// ## 为什么需要这条门槛
|
||||
///
|
||||
/// 主列自上而下是:搜索条(48)+ 筛选四排(4×32 + 3×8 = 152)+ 计数头(20)+ 结果列表 + 「加载更多」(40)
|
||||
/// 再加两条 `Space::X2` 间距。列表自己没有最小高度,于是窗口一矮,**列表视口只剩几十像素**:
|
||||
/// 一行 `ListItem` 是 60/76 高,被切成半行——两行文字(overline + 标题)看起来像「折行挤压」。
|
||||
///
|
||||
/// ## 明确的两档行为(不是到处加滚动条)
|
||||
///
|
||||
/// | 正文可用高 | 版面 |
|
||||
/// |---|---|
|
||||
/// | ≥ [`MIN_BODY_HEIGHT`] | 现状:**列表自己滚**(筛选条常驻,滚的时候不跑掉) |
|
||||
/// | < [`MIN_BODY_HEIGHT`] | 主列整列变成**一个**纵向滚动区:列表按自然高度铺开,一行都不压 |
|
||||
///
|
||||
/// 阈值 = 固定件(48 + 152 + 20 + 40 + 间距 ≈ 276)+ 至少三整行(3×60 = 180)= 456,
|
||||
/// 取 **460**(往上抹到 4 的倍数,给 divider / 取整留余量)。数值改了就改这里的算式与
|
||||
/// `layout/tests` 的等式用例。
|
||||
pub const MIN_BODY_HEIGHT: f32 = 460.0;
|
||||
|
||||
/// 正文高度的两档行为。
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BodyMode {
|
||||
/// 高够:列表自己滚(筛选条常驻)
|
||||
Split,
|
||||
/// 矮窗口:主列整列一个滚动区,列表按自然高度铺开
|
||||
ScrollWhole,
|
||||
}
|
||||
|
||||
impl BodyMode {
|
||||
/// 判据(纯函数,测得到)。
|
||||
#[must_use]
|
||||
pub fn of(body_height: f32) -> Self {
|
||||
if body_height >= MIN_BODY_HEIGHT {
|
||||
Self::Split
|
||||
} else {
|
||||
Self::ScrollWhole
|
||||
}
|
||||
}
|
||||
|
||||
/// 列表要不要自己滚。
|
||||
#[must_use]
|
||||
pub const fn list_scrolls(self) -> bool {
|
||||
matches!(self, Self::Split)
|
||||
}
|
||||
}
|
||||
|
||||
/// `Wide` 的门槛:标签栏 + 间距 + 列表下限 + 间距 + 详情。
|
||||
pub fn wide_min() -> f32 {
|
||||
RAIL_LABEL + GAP + layout::LINE_SAFE_WIDTH_PX + GAP + DETAIL
|
||||
@@ -192,3 +239,49 @@ mod tests {
|
||||
assert!(!Tier::Narrow.rail_has_labels());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod body_mode_tests {
|
||||
use super::*;
|
||||
|
||||
/// 门槛是**算出来的**:固定件(搜索 48 + 筛选 152 + 计数 20 + 加载更多 40 + 两条 8 间距)
|
||||
/// 加三整行列表(3 × 60)。谁把 460 改成拍脑袋的数,这条会红。
|
||||
#[test]
|
||||
fn the_minimum_body_height_is_fixed_parts_plus_three_rows() {
|
||||
let fixed = 48.0 + 152.0 + 20.0 + 40.0 + 2.0 * Space::X2.dp();
|
||||
let three_rows = 3.0 * 60.0;
|
||||
assert!(
|
||||
MIN_BODY_HEIGHT >= fixed + three_rows,
|
||||
"门槛 {MIN_BODY_HEIGHT} 小于「固定件 {fixed} + 三行 {three_rows}」——矮窗口还是会切半行"
|
||||
);
|
||||
assert!(
|
||||
MIN_BODY_HEIGHT <= fixed + three_rows + 16.0,
|
||||
"门槛留了太多余量:{} 会把还放得下的窗口也推进「整列滚动」档",
|
||||
MIN_BODY_HEIGHT - (fixed + three_rows)
|
||||
);
|
||||
}
|
||||
|
||||
/// 两档在门槛处切开,且只有 `Split` 让列表自己滚。
|
||||
#[test]
|
||||
fn the_body_mode_flips_at_the_threshold() {
|
||||
assert_eq!(BodyMode::of(MIN_BODY_HEIGHT), BodyMode::Split);
|
||||
assert_eq!(BodyMode::of(MIN_BODY_HEIGHT - 0.5), BodyMode::ScrollWhole);
|
||||
assert!(BodyMode::of(900.0).list_scrolls());
|
||||
assert!(!BodyMode::of(300.0).list_scrolls());
|
||||
}
|
||||
|
||||
/// 窗口最小尺寸(880×560)落在**矮**档:这是本条债的真实场景,别让它悄悄变回 `Split`。
|
||||
#[test]
|
||||
fn the_minimum_window_size_uses_the_scrolling_body() {
|
||||
// 560 窗口 − 顶栏 56 − 页头 88(两行标题 + 留白)− 上下页边距 2×16 ≈ 384
|
||||
let body = 560.0 - 56.0 - 88.0 - 32.0;
|
||||
assert_eq!(
|
||||
BodyMode::of(body),
|
||||
BodyMode::ScrollWhole,
|
||||
"最小窗口(560 高)必须走整列滚动:正文只剩 {body}"
|
||||
);
|
||||
// 验收尺寸 760 高 → 约 584,仍走「列表自己滚」。
|
||||
let body = 760.0 - 56.0 - 88.0 - 32.0;
|
||||
assert_eq!(BodyMode::of(body), BodyMode::Split, "验收尺寸不该换版面");
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ use unlucky_i18n::Lang;
|
||||
use unlucky_presenter::dto::{
|
||||
ConflictChoiceView, ConflictFileView, ConflictReasonView, ExportClassView, ExportFileView,
|
||||
ExportPreviewView, ExportReasonView, ExportState, FileActionView, ImportErrorView,
|
||||
ImportProgressView, ImportReportView, ImportStageView, ImportState, ImportStatusView,
|
||||
InstanceId, LoaderKind, MissingFileView, MissingReasonView, PackFormatView,
|
||||
ImportFailureStageView, ImportProgressView, ImportReportView, ImportStageView, ImportState,
|
||||
ImportStatusView, InstanceId, LoaderKind, MissingFileView, MissingReasonView, PackFormatView,
|
||||
};
|
||||
|
||||
use crate::pages::content::Target;
|
||||
@@ -88,8 +88,22 @@ pub(super) fn pack_in(state: &str, lang: Lang) -> (Pack, PackPageState) {
|
||||
import.report = Some(report(ImportStatusView::Partial, true));
|
||||
page.expanded = Some("config/sodium-options.json".to_string());
|
||||
}
|
||||
// 致命态:整包回滚 + 容忍域仍在(展示两类失败的视觉分野)
|
||||
"failed" => {
|
||||
// 致命态(M161 分成三档出图:预检没过 / 已回滚 / 回滚没做完)。
|
||||
// `failed` 保留旧名字(= 已回滚),另外两个是新档位。
|
||||
"failed" | "failed_rolled_back" => {
|
||||
let mut fatal = report(ImportStatusView::Failed, false);
|
||||
fatal.error = Some(ImportErrorView {
|
||||
code: "import_integrity".to_string(),
|
||||
label: "Integrity check".to_string(),
|
||||
message: "mods/sodium.jar: sha1 mismatch after write".to_string(),
|
||||
hint: Some("Re-download the pack from its source".to_string()),
|
||||
});
|
||||
fatal.rolled_back = true;
|
||||
fatal.failure_stage = Some(ImportFailureStageView::RolledBack);
|
||||
import.report = Some(fatal);
|
||||
}
|
||||
// 预检没过:**一个字节都没写**(与上一条只差 `failure_stage`,图上要能一眼分辨)
|
||||
"failed_preflight" => {
|
||||
let mut fatal = report(ImportStatusView::Failed, false);
|
||||
fatal.error = Some(ImportErrorView {
|
||||
code: "pack_traversal".to_string(),
|
||||
@@ -99,6 +113,21 @@ pub(super) fn pack_in(state: &str, lang: Lang) -> (Pack, PackPageState) {
|
||||
});
|
||||
fatal.files.clear();
|
||||
fatal.bytes_written = 0;
|
||||
fatal.rolled_back = true;
|
||||
fatal.failure_stage = Some(ImportFailureStageView::NotStarted);
|
||||
import.report = Some(fatal);
|
||||
}
|
||||
// 回滚没做完:目标目录可能与导入前不同
|
||||
"failed_incomplete" => {
|
||||
let mut fatal = report(ImportStatusView::Failed, false);
|
||||
fatal.error = Some(ImportErrorView {
|
||||
code: "import_integrity".to_string(),
|
||||
label: "Integrity check".to_string(),
|
||||
message: "mods/sodium.jar: sha1 mismatch after write".to_string(),
|
||||
hint: None,
|
||||
});
|
||||
fatal.rolled_back = false;
|
||||
fatal.failure_stage = Some(ImportFailureStageView::RollbackIncomplete);
|
||||
import.report = Some(fatal);
|
||||
}
|
||||
// 取消态:面板收回了,但「后台还在跑」这句话要留在屏上
|
||||
@@ -182,6 +211,7 @@ fn report(status: ImportStatusView, conflicts: bool) -> ImportReportView {
|
||||
registered: Some("Survival".to_string()),
|
||||
bytes_written: 3_400_000,
|
||||
rolled_back: true,
|
||||
failure_stage: None,
|
||||
};
|
||||
if conflicts {
|
||||
report.conflicts = vec![
|
||||
|
||||
@@ -23,7 +23,10 @@
|
||||
//! ## 容忍 / 致命在模型层就分开
|
||||
//!
|
||||
//! [`report::Report::missing`] 是「搞不到某个文件」(实例可用),[`report::Report::fatal`]
|
||||
//! 是「已整包回滚」。两者字段类型不同、画的时候颜色与图标也不同,不可能混成一个列表。
|
||||
//! 是致命失败。两者字段类型不同、画的时候颜色与图标也不同,不可能混成一个列表。
|
||||
//!
|
||||
//! 致命那一类内部还要再分三档(M161):预检没过(一个字节都没写)/ 已回滚 / 回滚没做完,
|
||||
//! 见 [`report::FatalKind`]——措辞、图标、底色三处都分开。
|
||||
|
||||
mod export;
|
||||
mod pick;
|
||||
@@ -33,7 +36,7 @@ mod report;
|
||||
pub use export::{format_label, request_of as request_export, Export, Preview};
|
||||
pub use pick::{Pick, PickRow};
|
||||
pub use progress::Running;
|
||||
pub use report::{ConflictRow, Report, Row};
|
||||
pub use report::{ConflictRow, FatalKind, Report, Row};
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
use unlucky_i18n::{Catalog, Key};
|
||||
use unlucky_presenter::dto::{
|
||||
ConflictChoiceView, ConflictFileView, ConflictReasonView, ImportErrorView, ImportReportView,
|
||||
ImportStatusView, MissingFileView, MissingReasonView,
|
||||
ConflictChoiceView, ConflictFileView, ConflictReasonView, ImportErrorView,
|
||||
ImportFailureStageView, ImportReportView, ImportStatusView, MissingFileView, MissingReasonView,
|
||||
};
|
||||
|
||||
use super::PackPageState;
|
||||
@@ -48,10 +48,40 @@ pub struct ConflictRow {
|
||||
pub expanded: bool,
|
||||
}
|
||||
|
||||
/// 致命失败块(**已整包回滚**)。
|
||||
/// 致命失败块(**两种措辞,不共用**)。
|
||||
///
|
||||
/// 为什么不是一句「失败」:`NotStarted`(预检就没过,一个字节都没写)与 `RolledBack`
|
||||
/// (写进去了,又整包回滚干净)对用户是不同的消息——前者「去修包再试」,后者「刚才动过你的目录,
|
||||
/// 已经复原」。M161 之前两者共用一句「已回滚 —— 目标目录零残留」,预检失败时那句话是假的。
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum FatalKind {
|
||||
/// 预检/装配阶段失败:目标目录**一个字节都没写**
|
||||
NotStarted,
|
||||
/// 写过目标目录,回滚**完整**完成
|
||||
RolledBack,
|
||||
/// 写过,但回滚有失败项(目标目录可能与导入前不同)
|
||||
RollbackIncomplete,
|
||||
}
|
||||
|
||||
impl FatalKind {
|
||||
/// 图标(与 [`Fatal::title`] 各说一遍:颜色/图标关掉时标题仍然分得清)。
|
||||
#[must_use]
|
||||
pub const fn icon(self) -> unlucky_design::icons::IconKind {
|
||||
match self {
|
||||
// 预检没过 = 「还没开始」,用警示而不是「已出错」:目录是干净的
|
||||
Self::NotStarted => unlucky_design::icons::IconKind::Warn,
|
||||
Self::RolledBack => unlucky_design::icons::IconKind::Restore,
|
||||
Self::RollbackIncomplete => unlucky_design::icons::IconKind::Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 致命失败块。
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Fatal {
|
||||
/// 「已回滚 —— 目标目录零残留」
|
||||
/// 三种阶段之一(决定标题/图标/底色)
|
||||
pub kind: FatalKind,
|
||||
/// 标题(预检未通过 / 已回滚 / 回滚不完整)
|
||||
pub title: String,
|
||||
/// 大类名(`路径穿越` / `清单损坏` …)
|
||||
pub label: String,
|
||||
@@ -124,7 +154,7 @@ pub(super) fn report_of(
|
||||
|
||||
Report {
|
||||
status: report.status,
|
||||
title: status_title(report.status, catalog).to_owned(),
|
||||
title: status_title(report, catalog).to_owned(),
|
||||
subtitle: subtitle(report, catalog),
|
||||
written_line: catalog.render(
|
||||
Key::PackReportWritten,
|
||||
@@ -133,7 +163,10 @@ pub(super) fn report_of(
|
||||
("bytes", &human(report)),
|
||||
],
|
||||
),
|
||||
fatal: report.error.as_ref().map(|error| fatal_of(error, catalog)),
|
||||
fatal: report
|
||||
.error
|
||||
.as_ref()
|
||||
.map(|error| fatal_of(error, report.failure_stage, catalog)),
|
||||
missing_title,
|
||||
missing: report
|
||||
.missing
|
||||
@@ -177,11 +210,22 @@ fn human(report: &ImportReportView) -> String {
|
||||
unlucky_presenter::dto::human_bytes(report.bytes_written)
|
||||
}
|
||||
|
||||
fn status_title(status: ImportStatusView, catalog: Catalog) -> &'static str {
|
||||
match status {
|
||||
/// 标题:三态 + **失败阶段**(预检未通过 ≠ 已回滚,M161)。
|
||||
fn status_title(report: &ImportReportView, catalog: Catalog) -> &'static str {
|
||||
match report.status {
|
||||
ImportStatusView::Success => catalog.text(Key::PackStatusSuccess),
|
||||
ImportStatusView::Partial => catalog.text(Key::PackStatusPartial),
|
||||
ImportStatusView::Failed => catalog.text(Key::PackStatusFailed),
|
||||
ImportStatusView::Failed => match report.failure_stage {
|
||||
Some(ImportFailureStageView::NotStarted) => {
|
||||
catalog.text(Key::PackStatusFailedNotStarted)
|
||||
}
|
||||
Some(ImportFailureStageView::RollbackIncomplete) => {
|
||||
catalog.text(Key::PackStatusFailedIncomplete)
|
||||
}
|
||||
// `None` 不该出现(失败必有阶段);退回「已回滚」这一句是旧行为,
|
||||
// 只有拿不到阶段时才会走到(例如未来的旧版对端)。
|
||||
_ => catalog.text(Key::PackStatusFailed),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,9 +247,24 @@ fn subtitle(report: &ImportReportView, catalog: Catalog) -> String {
|
||||
parts.join(" · ")
|
||||
}
|
||||
|
||||
fn fatal_of(error: &ImportErrorView, catalog: Catalog) -> Fatal {
|
||||
fn fatal_of(
|
||||
error: &ImportErrorView,
|
||||
stage: Option<ImportFailureStageView>,
|
||||
catalog: Catalog,
|
||||
) -> Fatal {
|
||||
let kind = match stage {
|
||||
Some(ImportFailureStageView::NotStarted) => FatalKind::NotStarted,
|
||||
Some(ImportFailureStageView::RollbackIncomplete) => FatalKind::RollbackIncomplete,
|
||||
_ => FatalKind::RolledBack,
|
||||
};
|
||||
let title = match kind {
|
||||
FatalKind::NotStarted => catalog.text(Key::PackFatalTitleNotStarted),
|
||||
FatalKind::RolledBack => catalog.text(Key::PackFatalTitle),
|
||||
FatalKind::RollbackIncomplete => catalog.text(Key::PackFatalTitleIncomplete),
|
||||
};
|
||||
Fatal {
|
||||
title: catalog.text(Key::PackFatalTitle).to_owned(),
|
||||
kind,
|
||||
title: title.to_owned(),
|
||||
label: error.label.clone(),
|
||||
message: error.message.clone(),
|
||||
code: error.code.clone(),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
//! 哪一态该出现哪一块。所有断言都能在没有图形环境的情况下跑。
|
||||
|
||||
mod pick;
|
||||
mod stage;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -226,6 +227,7 @@ fn report_keeps_tolerable_and_fatal_apart() {
|
||||
registered: None,
|
||||
bytes_written: 0,
|
||||
rolled_back: true,
|
||||
failure_stage: None,
|
||||
};
|
||||
let block = report_of(&report, &PackPageState::default(), catalog());
|
||||
assert!(block.fatal.is_some(), "致命块必须单独存在");
|
||||
@@ -262,6 +264,7 @@ fn conflicts_default_to_keeping_the_user_copy() {
|
||||
registered: None,
|
||||
bytes_written: 0,
|
||||
rolled_back: true,
|
||||
failure_stage: None,
|
||||
};
|
||||
// 「以包为准」只在导入到**已有实例**时给(复审 r1 P2-2),所以这里选一个实例
|
||||
let page = PackPageState {
|
||||
@@ -359,6 +362,7 @@ fn overwrite_is_offered_only_when_importing_into_an_existing_instance() {
|
||||
registered: None,
|
||||
bytes_written: 0,
|
||||
rolled_back: true,
|
||||
failure_stage: None,
|
||||
};
|
||||
|
||||
let new_instance = PackPageState::default();
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
//! M161:导入失败的**两种阶段**不许共用一句话。
|
||||
//!
|
||||
//! 从 `tests.rs` 拆出(那边贴着 400 行硬线):本文件只守「预检没过(一个字节都没写)」与
|
||||
//! 「已回滚」的措辞/图标分野。夹具在父模块(`use super::*`)。
|
||||
|
||||
use unlucky_presenter::dto::ImportFailureStageView;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// **「预检没过」与「已回滚」必须各说各的话**(M161 收的债)。
|
||||
///
|
||||
/// 此前两者共用 `rolled_back: true`,于是预检失败(一个字节都没写)也被写成
|
||||
/// 「已回滚 —— 目标目录零残留」——一个没发生的回滚。现在标题、图标、底色三处都分开,
|
||||
/// 且 `NotStarted` 的标题**不许**出现「回滚 / rolled back」这类词(那才是真正的谎)。
|
||||
#[test]
|
||||
fn the_two_failure_stages_never_share_one_sentence() {
|
||||
fn failed(stage: Option<ImportFailureStageView>) -> ImportReportView {
|
||||
ImportReportView {
|
||||
status: ImportStatusView::Failed,
|
||||
format: Some(PackFormatView::Modrinth),
|
||||
pack_name: Some("Broken".to_string()),
|
||||
pack_version: None,
|
||||
game_version: None,
|
||||
loader: None,
|
||||
version_id: None,
|
||||
target: PathBuf::from("C:/tmp"),
|
||||
files: Vec::new(),
|
||||
conflicts: Vec::new(),
|
||||
missing: Vec::new(),
|
||||
rejected: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
error: Some(ImportErrorView {
|
||||
code: "pack_traversal".to_string(),
|
||||
label: "path traversal".to_string(),
|
||||
message: "../etc/passwd".to_string(),
|
||||
hint: None,
|
||||
}),
|
||||
registered: None,
|
||||
bytes_written: 0,
|
||||
rolled_back: true,
|
||||
failure_stage: stage,
|
||||
}
|
||||
}
|
||||
|
||||
let zh = Lang::ZhCn.catalog();
|
||||
let not_started = report_of(
|
||||
&failed(Some(ImportFailureStageView::NotStarted)),
|
||||
&PackPageState::default(),
|
||||
zh,
|
||||
);
|
||||
let rolled_back = report_of(
|
||||
&failed(Some(ImportFailureStageView::RolledBack)),
|
||||
&PackPageState::default(),
|
||||
zh,
|
||||
);
|
||||
let incomplete = report_of(
|
||||
&failed(Some(ImportFailureStageView::RollbackIncomplete)),
|
||||
&PackPageState::default(),
|
||||
zh,
|
||||
);
|
||||
|
||||
// 三种标题互不相同(三态压力:谁把它们折叠回同一句,这里就红)。
|
||||
let titles = [
|
||||
not_started.title.as_str(),
|
||||
rolled_back.title.as_str(),
|
||||
incomplete.title.as_str(),
|
||||
];
|
||||
assert_eq!(
|
||||
titles
|
||||
.iter()
|
||||
.collect::<std::collections::HashSet<_>>()
|
||||
.len(),
|
||||
3,
|
||||
"三种失败阶段的标题撞了:{titles:?}"
|
||||
);
|
||||
|
||||
// 「预检没过」那一句里不许出现「回滚」(那是没发生的事)。
|
||||
let fatal = not_started.fatal.expect("致命块");
|
||||
assert_eq!(
|
||||
fatal.kind,
|
||||
crate::pages::content::packui::model::FatalKind::NotStarted
|
||||
);
|
||||
assert!(
|
||||
!fatal.title.contains("回滚"),
|
||||
"预检失败不该说「回滚」:{}",
|
||||
fatal.title
|
||||
);
|
||||
assert!(!not_started.title.contains("回滚"), "{}", not_started.title);
|
||||
// 已回滚那一句必须说清「回滚」这件事。
|
||||
assert!(
|
||||
rolled_back.title.contains("回滚"),
|
||||
"已回滚那句要说明回滚:{}",
|
||||
rolled_back.title
|
||||
);
|
||||
// 图标分开:预检没过不是「错误」字形(目录没动过),回滚不完整才是。
|
||||
assert_ne!(
|
||||
crate::pages::content::packui::model::FatalKind::NotStarted.icon(),
|
||||
crate::pages::content::packui::model::FatalKind::RolledBack.icon(),
|
||||
"两种阶段的图标不许一样"
|
||||
);
|
||||
|
||||
// 成功/部分成功没有「失败阶段」可言。
|
||||
let mut ok = failed(None);
|
||||
ok.status = ImportStatusView::Success;
|
||||
ok.error = None;
|
||||
assert!(report_of(&ok, &PackPageState::default(), zh)
|
||||
.fatal
|
||||
.is_none());
|
||||
}
|
||||
@@ -15,7 +15,7 @@ use crate::pages::frame;
|
||||
use crate::pages::Message as PageMessage;
|
||||
use crate::theme::Ui;
|
||||
|
||||
use super::super::model::{ConflictRow, Report};
|
||||
use super::super::model::{ConflictRow, FatalKind, Report};
|
||||
use super::super::PackMessage;
|
||||
use super::intent;
|
||||
use super::parts::{bounded, marker_box, rows_block, tolerable_title};
|
||||
@@ -62,34 +62,46 @@ pub(super) fn report_block<'a>(
|
||||
.width(Length::Fill);
|
||||
|
||||
if let Some(fatal) = &report.fatal {
|
||||
// 三种阶段各自的底色/图标:预检没过用 `SecondaryContainer`(**不是错的颜色**——
|
||||
// 目标目录一个字节都没写,没什么可修的残留),已回滚用 `ErrorContainer`,
|
||||
// 回滚不完整留 `ErrorContainer`(它才是真的要对一眼目录的状态)。
|
||||
let (role, on_role) = match fatal.kind {
|
||||
FatalKind::NotStarted => (Role::SecondaryContainer, Role::OnSecondaryContainer),
|
||||
_ => (Role::ErrorContainer, Role::OnErrorContainer),
|
||||
};
|
||||
block = block.push(marker_box(
|
||||
ui,
|
||||
Role::ErrorContainer,
|
||||
column![
|
||||
frame::text_role(
|
||||
ui,
|
||||
TypeRole::LabelLarge,
|
||||
true,
|
||||
fatal.title.as_str(),
|
||||
ui.color(Role::OnErrorContainer),
|
||||
),
|
||||
frame::text_role_owned(
|
||||
ui,
|
||||
TypeRole::BodyMedium,
|
||||
false,
|
||||
format!("{} · {}", fatal.label, fatal.code),
|
||||
ui.color(Role::OnErrorContainer),
|
||||
),
|
||||
frame::text_role(
|
||||
ui,
|
||||
TypeRole::BodySmall,
|
||||
false,
|
||||
fatal.message.as_str(),
|
||||
ui.color(Role::OnErrorContainer),
|
||||
),
|
||||
role,
|
||||
row![
|
||||
frame::glyph(fatal.kind.icon(), ui.color(on_role), frame::ICON_PX),
|
||||
column![
|
||||
frame::text_role(
|
||||
ui,
|
||||
TypeRole::LabelLarge,
|
||||
true,
|
||||
fatal.title.as_str(),
|
||||
ui.color(on_role),
|
||||
),
|
||||
frame::text_role_owned(
|
||||
ui,
|
||||
TypeRole::BodyMedium,
|
||||
false,
|
||||
format!("{} · {}", fatal.label, fatal.code),
|
||||
ui.color(on_role),
|
||||
),
|
||||
frame::text_role(
|
||||
ui,
|
||||
TypeRole::BodySmall,
|
||||
false,
|
||||
fatal.message.as_str(),
|
||||
ui.color(on_role),
|
||||
),
|
||||
]
|
||||
.spacing(ui.space(Space::X1))
|
||||
.width(Length::Fill),
|
||||
]
|
||||
.spacing(ui.space(Space::X1))
|
||||
.width(Length::Fill),
|
||||
.spacing(ui.space(Space::X2))
|
||||
.align_y(Alignment::Start),
|
||||
));
|
||||
if let Some(hint) = &fatal.hint {
|
||||
block = block.push(
|
||||
|
||||
@@ -98,12 +98,18 @@ pub(super) fn search<'a>(
|
||||
.into()
|
||||
}
|
||||
|
||||
/// 结果列表(独立滚动;底部「加载更多」钉在列表之外,见 [`more`])。
|
||||
/// 结果列表。
|
||||
///
|
||||
/// 两档(M161,判据同 [`super::layout::BodyMode`]):
|
||||
///
|
||||
/// * `mode.list_scrolls()`:列表**自己滚**(筛选条常驻,高窗口的常态);
|
||||
/// * 否则:行按自然高度铺开,滚动交给外层主列——矮窗口里一行 `ListItem` 不许被压成半行。
|
||||
pub(super) fn list<'a>(
|
||||
ui: &'a Ui,
|
||||
catalog: Catalog,
|
||||
model: &'a Content,
|
||||
rails: Rails,
|
||||
mode: super::layout::BodyMode,
|
||||
) -> Element<'a, PageMessage> {
|
||||
let rows = column(
|
||||
model
|
||||
@@ -117,20 +123,32 @@ pub(super) fn list<'a>(
|
||||
.width(Length::Fill);
|
||||
|
||||
let _ = catalog;
|
||||
container(
|
||||
scrollable(rows)
|
||||
.direction(scrollable::Direction::Vertical(
|
||||
scrollable::Scrollbar::new()
|
||||
.width(frame::SCROLLBAR_WIDTH)
|
||||
.scroller_width(frame::SCROLLBAR_WIDTH)
|
||||
.margin(frame::SCROLLBAR_MARGIN),
|
||||
))
|
||||
.height(Length::Fill)
|
||||
.style(frame::scroll_style(ui)),
|
||||
)
|
||||
.width(Length::Fixed(rails.list))
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
let inner: Element<'a, PageMessage> = if mode.list_scrolls() {
|
||||
container(
|
||||
scrollable(rows)
|
||||
.direction(scrollable::Direction::Vertical(
|
||||
scrollable::Scrollbar::new()
|
||||
.width(frame::SCROLLBAR_WIDTH)
|
||||
.scroller_width(frame::SCROLLBAR_WIDTH)
|
||||
.margin(frame::SCROLLBAR_MARGIN),
|
||||
))
|
||||
.height(Length::Fill)
|
||||
.style(frame::scroll_style(ui)),
|
||||
)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
} else {
|
||||
// 自然高度(不给 `Fill`):外层主列的那个滚动条负责滚。
|
||||
rows.into()
|
||||
};
|
||||
container(inner)
|
||||
.width(Length::Fixed(rails.list))
|
||||
.height(if mode.list_scrolls() {
|
||||
Length::Fill
|
||||
} else {
|
||||
Length::Shrink
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
fn hit_row<'a>(ui: &'a Ui, model: &Content, hit: &'a Hit) -> Element<'a, PageMessage> {
|
||||
|
||||
@@ -49,12 +49,17 @@ pub(super) fn view<'a>(
|
||||
metrics: FrameMetrics,
|
||||
model: &'a Content,
|
||||
lang: unlucky_i18n::Lang,
|
||||
window_height: f32,
|
||||
) -> Element<'a, PageMessage> {
|
||||
let catalog = lang.catalog();
|
||||
// 正文可用高 → 版面两档(`Split`:列表自己滚;`ScrollWhole`:主列整列一个滚动条)。
|
||||
// 门槛与判据在 [`content_layout`] 里,那里有用例钉住「不算拍脑袋的数」。
|
||||
let body_height = frame::body_height(ui, metrics, window_height, true);
|
||||
let mode = content_layout::BodyMode::of(body_height);
|
||||
let header = Header::new(catalog.text(Key::ContentTitle))
|
||||
.subtitle(catalog.text(Key::ContentSubtitle))
|
||||
.action(parts::section_switcher(ui, catalog, true));
|
||||
frame::page(ui, metrics, header, body(ui, metrics, catalog, model))
|
||||
frame::page(ui, metrics, header, body(ui, metrics, catalog, model, mode))
|
||||
}
|
||||
|
||||
fn body<'a>(
|
||||
@@ -62,6 +67,7 @@ fn body<'a>(
|
||||
metrics: FrameMetrics,
|
||||
catalog: Catalog,
|
||||
model: &'a Content,
|
||||
mode: content_layout::BodyMode,
|
||||
) -> Element<'a, PageMessage> {
|
||||
let rails = content_layout::resolve(metrics.available);
|
||||
|
||||
@@ -75,14 +81,14 @@ fn body<'a>(
|
||||
let main = column![
|
||||
kind_rail(ui, catalog, model, rails),
|
||||
divider::full(ui),
|
||||
main_column(ui, catalog, model, rails)
|
||||
main_column(ui, catalog, model, rails, mode)
|
||||
]
|
||||
.spacing(ui.space(Space::X2))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill);
|
||||
columns = row![main].width(Length::Fill).height(Length::Fill);
|
||||
} else {
|
||||
columns = columns.push(main_column(ui, catalog, model, rails));
|
||||
columns = columns.push(main_column(ui, catalog, model, rails, mode));
|
||||
if rails.tier.has_detail() {
|
||||
columns = columns.push(detail_column(ui, catalog, model, rails));
|
||||
}
|
||||
@@ -151,11 +157,19 @@ fn kind_rail<'a>(
|
||||
}
|
||||
|
||||
/// 主列:搜索条 + 筛选 + 计数 + 结果(或四态之一)。
|
||||
///
|
||||
/// `mode` 决定**谁滚**(M161,判据在 `content_layout::BodyMode`):
|
||||
///
|
||||
/// * `Split`:列表自己滚(筛选条常驻,高窗口的常态);
|
||||
/// * `ScrollWhole`:矮窗口——主列(含搜索条与筛选)整列进**一个**纵向滚动区,列表按自然高度铺开。
|
||||
/// 这样一行 `ListItem` 不会被压成半行(那看起来就是「折行挤压」),也不会出现「列表里一个滚动条、
|
||||
/// 外层又一个」的双滚动。
|
||||
fn main_column<'a>(
|
||||
ui: &'a Ui,
|
||||
catalog: Catalog,
|
||||
model: &'a Content,
|
||||
rails: Rails,
|
||||
mode: content_layout::BodyMode,
|
||||
) -> Element<'a, PageMessage> {
|
||||
// 主列的横向内边距不在这里加:`rails.list` 已经把可用宽算干了,再加 2×X2 会让整排
|
||||
// 溢出 32px(详情列被切掉一半,复审截图上正是这条)
|
||||
@@ -178,10 +192,15 @@ fn main_column<'a>(
|
||||
} else {
|
||||
// **必须给间距**(复审 P2-1):这一列原先漏了 `.spacing(..)`,而列表自身的纵向内边距是 0,
|
||||
// 于是「列表视口底边」与「加载更多」贴在一起,末行正好被切在半行上。
|
||||
let mut list = column![parts::list(ui, catalog, model, rails)]
|
||||
let mut list = column![parts::list(ui, catalog, model, rails, mode)]
|
||||
.spacing(ui.space(Space::X2))
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill);
|
||||
.width(Length::Fill);
|
||||
// 列表高度:`Split` 吃掉剩余高度(自己滚);`ScrollWhole` 按内容铺开(外层滚)。
|
||||
list = if mode.list_scrolls() {
|
||||
list.height(Length::Fill)
|
||||
} else {
|
||||
list.height(Length::Shrink)
|
||||
};
|
||||
// 紧凑档没有独立详情列:详情压在列表下面(整页替换的成本比「多一块」高)
|
||||
if !rails.tier.has_detail() {
|
||||
list = list
|
||||
@@ -191,10 +210,11 @@ fn main_column<'a>(
|
||||
list.push(parts::more(ui, catalog, model)).into()
|
||||
};
|
||||
|
||||
// `ScrollWhole` 档:主列整列一个滚动区(列表按自然高度)。**只有这一处**加滚动条,
|
||||
// 不在列表里再套一个(双滚动是「到处加滚动条糊」的典型症状)。
|
||||
let mut column = column![]
|
||||
.spacing(ui.space(Space::X2))
|
||||
.width(Length::Fixed(rails.list))
|
||||
.height(Length::Fill);
|
||||
.width(Length::Fixed(rails.list));
|
||||
|
||||
// M113: import/export —— 只有整合包这一类才有「把本地的包装进来 / 把实例打出去」。
|
||||
// 其它三类(Mod / 资源包 / 光影)的导入就是把文件拖进目录,不属于本条任务。
|
||||
@@ -204,7 +224,20 @@ fn main_column<'a>(
|
||||
.push(divider::full(ui));
|
||||
}
|
||||
|
||||
column.push(head).push(body).into()
|
||||
column = column.push(head).push(body);
|
||||
if mode.list_scrolls() {
|
||||
return column.height(Length::Fill).into();
|
||||
}
|
||||
iced::widget::scrollable(column.height(Length::Shrink))
|
||||
.direction(iced::widget::scrollable::Direction::Vertical(
|
||||
iced::widget::scrollable::Scrollbar::new()
|
||||
.width(frame::SCROLLBAR_WIDTH)
|
||||
.scroller_width(frame::SCROLLBAR_WIDTH)
|
||||
.margin(frame::SCROLLBAR_MARGIN),
|
||||
))
|
||||
.height(Length::Fill)
|
||||
.style(frame::scroll_style(ui))
|
||||
.into()
|
||||
}
|
||||
|
||||
/// 详情列(只在 `Wide` / `Narrow` 存在)。
|
||||
|
||||
@@ -114,6 +114,19 @@ pub fn page<'a>(
|
||||
.into()
|
||||
}
|
||||
|
||||
/// 页面正文的**可用高度**(窗口高 − 自绘标题栏 − 页头带 − 上下页边距)。
|
||||
///
|
||||
/// M161:内容库要靠它决定「矮窗口换版面」。三个被减掉的量都取自 [`page`]/[`header_bar`]
|
||||
/// 用的**同一个**来源(`Ui::metrics` 与 [`FrameMetrics::gutter`]),不另抄字面量——
|
||||
/// 谁改了页头高,这里跟着变。
|
||||
#[must_use]
|
||||
pub fn body_height(ui: &Ui, metrics: FrameMetrics, window_height: f32, has_subtitle: bool) -> f32 {
|
||||
let chrome = ui.metrics().titlebar_height
|
||||
+ ui.metrics().header_height(has_subtitle)
|
||||
+ 2.0 * metrics.gutter;
|
||||
(window_height - chrome).max(0.0)
|
||||
}
|
||||
|
||||
fn header_bar<'a>(ui: &'a Ui, metrics: FrameMetrics, header: Header<'a>) -> Element<'a, Message> {
|
||||
let spec = Component::TopAppBar.spec();
|
||||
// 16.4:标题 TitleLarge(emphasized w500),副标题 LabelMedium + OnSurfaceVariant
|
||||
|
||||
@@ -140,7 +140,7 @@ pub fn run(request: Request) -> Result<(), String> {
|
||||
let written = Arc::clone(&written);
|
||||
iced::application(
|
||||
move || {
|
||||
let mut model = demo_model(boot.screen, boot.width);
|
||||
let mut model = demo_model(boot.screen, boot.width, boot.height);
|
||||
// 截图通道把**消费 forced 的那批控件**(实例页)钉成常态,与产品 `--screenshot`
|
||||
// 的 `ForcedState::Rest` 同一条纪律。它管不到设置页 / 外观区(那边不读 forced),
|
||||
// 那两屏的密闭靠窗口级 passthrough——别把这条当成万能的。
|
||||
|
||||
@@ -61,12 +61,17 @@ const PAGE_SOURCES: [(&str, &str); 6] = [
|
||||
/// | `isolated` / `shared` | core 的隔离档位**稳定 id**(`IsolationMode::as_str`),`isolation()` 只认这两档,其余原样上屏 |
|
||||
/// | `pid` / `reason` | `Catalog::render` 的**占位符名**(与 catalog 里的 `{pid}` / `{reason}` 对应) |
|
||||
/// | `Instances` | `Texts::keys()` 的**族名前缀**(`Key::ALL` 的过滤条件,不是文案) |
|
||||
const ALLOWED_LITERALS: [&str; 19] = [
|
||||
const ALLOWED_LITERALS: [&str; 22] = [
|
||||
"{date} {time} UTC",
|
||||
"isolated",
|
||||
"shared",
|
||||
"pid",
|
||||
"reason",
|
||||
// M161:`InstancesFailed` 拆成「阶段 + 原文」之后,失败行改由 `LaunchStageFailed` 渲染,
|
||||
// 它的两个占位符名是 `{stage}` / `{detail}`(占位符名不是文案)。
|
||||
"stage",
|
||||
"detail",
|
||||
"outcome",
|
||||
"seconds",
|
||||
"Instances",
|
||||
// M157:图形后端三态的**稳定 id**(与 core 的 `GraphicsBackend::IDS` 同一份词表),
|
||||
// `backend_label` 只认这三档,其余原样上屏。
|
||||
@@ -87,6 +92,7 @@ const ALLOWED_LITERALS: [&str; 19] = [
|
||||
"1.20.4",
|
||||
"C:/Java/temurin-21/bin/java.exe",
|
||||
"ULL_LAUNCH_ARGS_FIXTURE",
|
||||
// M161:示例「被门槛挡下」的取值(夹具)。
|
||||
"gated",
|
||||
];
|
||||
|
||||
@@ -219,11 +225,23 @@ fn the_running_line_keeps_its_number_and_separator() {
|
||||
assert!(text.contains(" · pid "), "分隔符或 pid 变形了:{text}");
|
||||
}
|
||||
|
||||
// 失败那一行同理:core 给的原因原文原样保留,只翻前半句
|
||||
let failed_en = Catalog::of(Lang::En).render(Key::InstancesFailed, &[("reason", "exit 1")]);
|
||||
let failed_zh = Catalog::of(Lang::ZhCn).render(Key::InstancesFailed, &[("reason", "exit 1")]);
|
||||
assert_eq!(failed_en, "Launch failed · exit 1");
|
||||
assert_eq!(failed_zh, "启动失败 · exit 1");
|
||||
// 失败那一行同理(M161:`InstancesFailed` 已被 `LaunchStageFailed` 取代——「哪一步」也要翻,
|
||||
// 只有 `detail` 那段原文原样保留)
|
||||
let args = [("stage", "Starting the game process"), ("detail", "exit 1")];
|
||||
let failed_en = Catalog::of(Lang::En).render(Key::LaunchStageFailed, &args);
|
||||
let failed_zh = Catalog::of(Lang::ZhCn).render(
|
||||
Key::LaunchStageFailed,
|
||||
&[("stage", "启动游戏进程"), ("detail", "exit 1")],
|
||||
);
|
||||
assert_eq!(
|
||||
failed_en,
|
||||
"Launch failed · Starting the game process: exit 1"
|
||||
);
|
||||
assert_eq!(failed_zh, "启动失败 · 启动游戏进程:exit 1");
|
||||
for text in [&failed_en, &failed_zh] {
|
||||
assert!(text.contains("exit 1"), "原文丢了:{text}");
|
||||
}
|
||||
assert_ne!(failed_en, failed_zh, "切换语言时前半句要变");
|
||||
}
|
||||
|
||||
/// **页面里不许再写死界面文案**(白名单):带 ASCII 单词的字面量必须在 [`ALLOWED_LITERALS`] 里。
|
||||
|
||||
@@ -230,7 +230,11 @@ fn render<'a>(
|
||||
// M106:下载页此前写死成 `Lang::En`,现在跟 `model.lang`(页面文案跟着界面语言走)。
|
||||
Screen::Download => download::view(ui, metrics, &model.download, model.lang),
|
||||
// M109:内容库页同样跟 `model.lang`
|
||||
Screen::Content => content::view(ui, metrics, &model.content, model.lang),
|
||||
// M161:内容库要按**窗口高度**选版面(矮窗口不能把列表压扁),
|
||||
// 正文可用高由 `frame::body_height` 从窗口高减掉外壳算出(唯一来源)。
|
||||
Screen::Content => {
|
||||
content::view(ui, metrics, &model.content, model.lang, model.window_height)
|
||||
}
|
||||
// M159:设置页「更新」组要画 presenter 的更新快照(不在 `States` 里,理由见该组文档)。
|
||||
Screen::Settings => settings::view(ui, metrics, states, language, &model.update),
|
||||
Screen::Logs => logs::view(ui, metrics, &model.logs, model.lang),
|
||||
@@ -304,8 +308,11 @@ pub fn app_with_appearance<'a>(
|
||||
/// 演示模型(`pages_demo` example 与单测用;真页面走 `app/view.rs` 的 `AppState` 转换)。
|
||||
///
|
||||
/// 实例 / 下载 / 日志三页带演示数据,设置页仍是占位视觉。
|
||||
pub fn demo_model(screen: Screen, window_width: f32) -> Model {
|
||||
let mut model = Model::new(screen, window_width, Some(screen.nav()));
|
||||
///
|
||||
/// 高度也是模型的一部分(M161):内容库在矮窗口下要换版面,出图时 `--height` 必须
|
||||
/// 真的传进来,否则「矮窗口那几张图」画的是高窗口的版面。
|
||||
pub fn demo_model(screen: Screen, window_width: f32, window_height: f32) -> Model {
|
||||
let mut model = Model::new(screen, window_width, window_height, Some(screen.nav()));
|
||||
match screen {
|
||||
Screen::Instances => model.instances = instances::demo(),
|
||||
Screen::Download => model.download = download::demo(unlucky_i18n::Lang::En.catalog()),
|
||||
|
||||
@@ -107,6 +107,11 @@ pub struct Model {
|
||||
pub screen: Screen,
|
||||
/// 窗口宽度(**含外壳**:布局档位判据就是它)
|
||||
pub window_width: f32,
|
||||
/// 窗口高度(**含外壳**)。
|
||||
///
|
||||
/// 只有「矮窗口要换版面」这一类判据用它(M161:内容库在低高度下不能把列表压扁)——
|
||||
/// 宽度档位仍只看 [`Self::window_width`]。
|
||||
pub window_height: f32,
|
||||
/// 导航轨高亮项(`None` = 没有高亮,如 AI 独立页)
|
||||
pub active: Option<NavSection>,
|
||||
/// 实例页的数据(其它三页还是占位视觉,不读)
|
||||
@@ -134,10 +139,16 @@ pub struct Model {
|
||||
|
||||
impl Model {
|
||||
/// 空模型(只有外壳参数,页面数据全空)——窄窗退化与空态的构造入口。
|
||||
pub fn new(screen: Screen, window_width: f32, active: Option<NavSection>) -> Self {
|
||||
pub fn new(
|
||||
screen: Screen,
|
||||
window_width: f32,
|
||||
window_height: f32,
|
||||
active: Option<NavSection>,
|
||||
) -> Self {
|
||||
Self {
|
||||
screen,
|
||||
window_width,
|
||||
window_height,
|
||||
active,
|
||||
instances: Instances::default(),
|
||||
download: Download::loading(),
|
||||
|
||||
@@ -107,7 +107,7 @@ fn the_banner_priority_is_ready_then_applying_then_failure_then_available() {
|
||||
/// 演示模型里更新组能画(`pages_demo` 的 harness 路径):`Model.update` 有默认值,不是 `None` 才画。
|
||||
#[test]
|
||||
fn the_demo_model_carries_an_update_snapshot() {
|
||||
let model = crate::pages::demo_model(Screen::Settings, 1180.0);
|
||||
let model = crate::pages::demo_model(Screen::Settings, 1180.0, 760.0);
|
||||
assert_eq!(model.update, crate::pages::update::demo());
|
||||
assert!(
|
||||
model.update.available().is_some(),
|
||||
@@ -115,9 +115,73 @@ fn the_demo_model_carries_an_update_snapshot() {
|
||||
);
|
||||
// 其它页不掺演示更新状态(实例页/下载页的基线图不该多出一条提示条)。
|
||||
assert_eq!(
|
||||
crate::pages::demo_model(Screen::Instances, 1180.0).update,
|
||||
crate::pages::demo_model(Screen::Instances, 1180.0, 760.0).update,
|
||||
Update::default()
|
||||
);
|
||||
let catalog: Catalog = Lang::En.catalog();
|
||||
assert!(!catalog.text(Key::SettingsGroupUpdate).is_empty());
|
||||
}
|
||||
|
||||
/// **忙碌时按钮禁用,且禁用态与状态行同源**(M161 收的债:以前点了没反应)。
|
||||
///
|
||||
/// 三条判据:
|
||||
/// ① `Checking` / `applying` 时 `can_check()` 与 `can_apply()` 都是 false(按钮画成置灰);
|
||||
/// ② 这两态下设置页的状态行**必须**是「正在检查…」/「正在安装…」——否则用户看到一颗灰按钮
|
||||
/// 却没有任何解释;
|
||||
/// ③ 结论回来(失败也算)之后恢回可点:超时/网络失败不许把按钮永久钉死。
|
||||
#[test]
|
||||
fn the_buttons_are_disabled_exactly_while_something_is_running() {
|
||||
use super::super::update::status_line;
|
||||
|
||||
let catalog = Catalog::of(Lang::ZhCn);
|
||||
let available = UpdateStatus::Available {
|
||||
version: "0.2.3".to_string(),
|
||||
size: 1024,
|
||||
notes: String::new(),
|
||||
forced: false,
|
||||
};
|
||||
|
||||
// 静息:有候选 ⇒ 两颗按钮都能点。
|
||||
let idle = Update {
|
||||
status: available.clone(),
|
||||
..Update::default()
|
||||
};
|
||||
assert!(!idle.busy());
|
||||
assert!(idle.can_check(), "静息时「立即检查」可点");
|
||||
assert!(idle.can_apply(), "有候选且不忙 ⇒ 「下载并安装」可点");
|
||||
|
||||
// 正在查:两颗都置灰,状态行说「正在检查」。
|
||||
let checking = Update {
|
||||
status: UpdateStatus::Checking,
|
||||
..idle.clone()
|
||||
};
|
||||
assert!(checking.busy(), "Checking 就是忙碌");
|
||||
assert!(!checking.can_check(), "查的时候不许再点「立即检查」");
|
||||
assert!(!checking.can_apply(), "查的时候不许装(presenter 也拒)");
|
||||
assert_eq!(
|
||||
status_line(catalog, &checking).0,
|
||||
catalog.text(Key::SettingsUpdateChecking),
|
||||
"灰按钮旁边必须有「正在检查…」这句话"
|
||||
);
|
||||
|
||||
// 正在装:`applying` 也算忙碌(此时 status 可能仍是 Available)。
|
||||
let applying = Update {
|
||||
applying: true,
|
||||
..idle.clone()
|
||||
};
|
||||
assert!(applying.busy());
|
||||
assert!(!applying.can_apply(), "装的时候安装键置灰,不是消失");
|
||||
assert!(!applying.can_check(), "装的时候也不许再来一条检查");
|
||||
|
||||
// 结论回来(这里是最坏的结论:失败)⇒ 恢回可点。
|
||||
let failed = Update {
|
||||
status: UpdateStatus::Failed {
|
||||
reason: "连不上".to_string(),
|
||||
retryable: true,
|
||||
},
|
||||
..Update::default()
|
||||
};
|
||||
assert!(!failed.busy(), "失败 = 这一轮结束了");
|
||||
assert!(failed.can_check(), "失败之后必须能重试");
|
||||
assert!(!failed.can_apply(), "没有候选时安装键不可点");
|
||||
}
|
||||
@@ -73,7 +73,7 @@ pub(super) fn body<'a>(ui: &'a Ui, update: &'a Update, lang: Lang) -> Element<'a
|
||||
channel_label(catalog, &update.channel),
|
||||
));
|
||||
stacked = stacked.push(divider(ui));
|
||||
stacked = stacked.push(auto_check_row(ui, catalog, update.auto_check));
|
||||
stacked = stacked.push(auto_check_row(ui, catalog, update));
|
||||
stacked = stacked.push(divider(ui));
|
||||
stacked = stacked.push(status_block(ui, catalog, update));
|
||||
|
||||
@@ -117,23 +117,30 @@ fn info_row<'a>(ui: &'a Ui, label: &'a str, value: String) -> Element<'a, Messag
|
||||
}
|
||||
|
||||
/// 自动检查开关 + 「立即检查」按钮。
|
||||
fn auto_check_row<'a>(ui: &'a Ui, catalog: Catalog, auto_check: bool) -> Element<'a, Message> {
|
||||
///
|
||||
/// **忙碌时「立即检查」置灰**(M161):此前它永远可点,而 presenter 的 `begin_check` 在
|
||||
/// inflight 时静默 `return None`——用户点了没反应,还以为启动器卡了。禁用态与状态行同源
|
||||
/// (同一个 [`Update::busy`]):按钮灰着的时候,下面那句状态行一定是「正在检查…」/「正在安装…」。
|
||||
fn auto_check_row<'a>(ui: &'a Ui, catalog: Catalog, update: &Update) -> Element<'a, Message> {
|
||||
let check_now = catalog.text(Key::SettingsUpdateCheckNow);
|
||||
let check = if update.can_check() {
|
||||
buttons::text(
|
||||
ui,
|
||||
Button::new(check_now, Message::Update(UpdateAction::CheckNow)),
|
||||
)
|
||||
} else {
|
||||
buttons::text(ui, Button::disabled(check_now))
|
||||
};
|
||||
row![
|
||||
chip(
|
||||
ui,
|
||||
Chip::filter(
|
||||
catalog.text(Key::SettingsUpdateAutoCheck),
|
||||
auto_check,
|
||||
Message::Update(UpdateAction::SetAutoCheck(!auto_check)),
|
||||
),
|
||||
),
|
||||
buttons::text(
|
||||
ui,
|
||||
Button::new(
|
||||
catalog.text(Key::SettingsUpdateCheckNow),
|
||||
Message::Update(UpdateAction::CheckNow),
|
||||
update.auto_check,
|
||||
Message::Update(UpdateAction::SetAutoCheck(!update.auto_check)),
|
||||
),
|
||||
),
|
||||
check,
|
||||
]
|
||||
.spacing(ui.space(Space::X3))
|
||||
.width(Length::Fill)
|
||||
@@ -171,17 +178,21 @@ fn status_block<'a>(ui: &'a Ui, catalog: Catalog, update: &'a Update) -> Element
|
||||
});
|
||||
block = block.push(text_role_owned(ui, TypeRole::BodySmall, false, text, color));
|
||||
|
||||
if let Some((_version, _size, notes, forced)) = update.available().filter(|_| !update.applying)
|
||||
{
|
||||
let mut actions = row![buttons::filled(
|
||||
ui,
|
||||
Button::new(
|
||||
catalog.text(Key::SettingsUpdateApply),
|
||||
Message::Update(UpdateAction::Apply),
|
||||
),
|
||||
)]
|
||||
.spacing(ui.space(Space::X2))
|
||||
.align_y(Alignment::Center);
|
||||
if let Some((_version, _size, notes, forced)) = update.available() {
|
||||
// 有候选就**永远画出**这一颗按钮:忙碌时置灰(`can_apply` = false),而不是整颗消失。
|
||||
// 消失会让人以为「装到一半的功能没了」;灰着 + 状态行那句「正在安装…」才说得清。
|
||||
let apply_label = catalog.text(Key::SettingsUpdateApply);
|
||||
let apply = if update.can_apply() {
|
||||
buttons::filled(
|
||||
ui,
|
||||
Button::new(apply_label, Message::Update(UpdateAction::Apply)),
|
||||
)
|
||||
} else {
|
||||
buttons::filled(ui, Button::disabled(apply_label))
|
||||
};
|
||||
let mut actions = row![apply]
|
||||
.spacing(ui.space(Space::X2))
|
||||
.align_y(Alignment::Center);
|
||||
if forced {
|
||||
actions = actions.push(text_role_owned(
|
||||
ui,
|
||||
@@ -234,7 +245,8 @@ fn status_block<'a>(ui: &'a Ui, catalog: Catalog, update: &'a Update) -> Element
|
||||
/// 一条状态行(文案 + 是不是「错」那一类)。
|
||||
///
|
||||
/// 四种结论各写各的句子,**不共用**「已是最新」那句:失败/缺产物时那句就是撒谎。
|
||||
fn status_line(catalog: Catalog, update: &Update) -> (String, bool) {
|
||||
/// `pub(super)` 只为让 `settings/tests` 能断言「忙碌时状态行与按钮禁用态同源」。
|
||||
pub(super) fn status_line(catalog: Catalog, update: &Update) -> (String, bool) {
|
||||
let (key, args, error) = match &update.status {
|
||||
UpdateStatus::Idle => (Key::SettingsUpdateNever, Vec::new(), false),
|
||||
UpdateStatus::Checking => (Key::SettingsUpdateChecking, Vec::new(), false),
|
||||
|
||||
@@ -57,7 +57,7 @@ fn every_screen_builds_at_the_three_comparison_widths() {
|
||||
let form = demo_launch_form();
|
||||
for width in [1180.0, 900.0, 700.0] {
|
||||
for screen in Screen::ALL {
|
||||
let model = demo_model(screen, width);
|
||||
let model = demo_model(screen, width, 760.0);
|
||||
let _element: Element<'_, Message> = app(&ui, &model, &form);
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ fn an_empty_snapshot_still_builds() {
|
||||
let ui = ui();
|
||||
let form = demo_launch_form();
|
||||
for screen in Screen::ALL {
|
||||
let model = Model::new(screen, 1180.0, Some(screen.nav()));
|
||||
let model = Model::new(screen, 1180.0, 760.0, Some(screen.nav()));
|
||||
let _element: Element<'_, Message> = app(&ui, &model, &form);
|
||||
}
|
||||
}
|
||||
@@ -368,7 +368,7 @@ fn every_rail_item_points_at_a_route_that_highlights_it() {
|
||||
/// 演示模型:12 行 + 1 条选中详情(M84 的出图基线就靠这份数据)。
|
||||
#[test]
|
||||
fn the_demo_model_carries_the_m84_baseline() {
|
||||
let model = demo_model(Screen::Instances, 1180.0);
|
||||
let model = demo_model(Screen::Instances, 1180.0, 760.0);
|
||||
assert_eq!(model.instances.rows.len(), 12);
|
||||
let detail = model.instances.detail.as_ref().expect("演示数据有选中项");
|
||||
assert_eq!(detail.meta.len(), 6, "元信息 6 格");
|
||||
@@ -377,7 +377,7 @@ fn the_demo_model_carries_the_m84_baseline() {
|
||||
|
||||
// 其余三页不带实例数据(占位视觉不读它)
|
||||
for screen in [Screen::Download, Screen::Settings, Screen::Logs] {
|
||||
let model = demo_model(screen, 1180.0);
|
||||
let model = demo_model(screen, 1180.0, 760.0);
|
||||
assert!(
|
||||
model.instances.rows.is_empty(),
|
||||
"{} 不该带实例数据",
|
||||
|
||||
@@ -102,6 +102,8 @@ pub struct Update {
|
||||
pub silent: bool,
|
||||
}
|
||||
|
||||
mod busy;
|
||||
|
||||
impl Update {
|
||||
/// 有没有可装的候选(有的话设置页给「下载并安装」)。
|
||||
#[must_use]
|
||||
@@ -155,8 +157,37 @@ impl Update {
|
||||
/// 出图 / 单测用的演示快照(一个可装的新版本 + 一次成功的检查)。
|
||||
///
|
||||
/// **不是产品数据**:产品路径的更新状态只来自 presenter(`app/view/update.rs` 转换)。
|
||||
///
|
||||
/// 取证开关 `ULL_UPDATE_STATE`(M161,沿用 `ULL_CONTENT_*` 那套范式):不设 = 缺省那一态;
|
||||
/// `checking` / `applying` 用来出「按钮置灰 + 状态行说正在干活」的那两张图,
|
||||
/// `failed` / `up_to_date` 用来出另外两条结论。
|
||||
#[must_use]
|
||||
pub fn demo() -> Update {
|
||||
let mut snapshot = demo_available();
|
||||
match std::env::var("ULL_UPDATE_STATE")
|
||||
.unwrap_or_default()
|
||||
.as_str()
|
||||
{
|
||||
"checking" => snapshot.status = UpdateStatus::Checking,
|
||||
"applying" => snapshot.applying = true,
|
||||
"failed" => {
|
||||
snapshot.status = UpdateStatus::Failed {
|
||||
reason: "Could not fetch the release manifest: connection reset".to_string(),
|
||||
retryable: true,
|
||||
}
|
||||
}
|
||||
"up_to_date" => {
|
||||
snapshot.status = UpdateStatus::UpToDate {
|
||||
latest: Some("0.2.2".to_string()),
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
snapshot
|
||||
}
|
||||
|
||||
/// 缺省那一态(可装的新版本)。
|
||||
fn demo_available() -> Update {
|
||||
Update {
|
||||
current_version: "0.2.2".to_string(),
|
||||
channel: "stable".to_string(),
|
||||
@@ -332,60 +363,6 @@ pub fn banner<'a>(
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use unlucky_i18n::Lang;
|
||||
|
||||
/// 提示条的正文**同时**给体积与说明摘要(mission:提示条含版本号、体积、说明摘要)。
|
||||
#[test]
|
||||
fn the_available_banner_carries_both_size_and_notes() {
|
||||
for lang in [Lang::En, Lang::ZhCn] {
|
||||
let body = available_body(lang.catalog(), 21_500_000, "修掉启动崩溃");
|
||||
assert!(body.contains("20.5 MB"), "{lang:?} 缺体积:{body}");
|
||||
assert!(body.contains("修掉启动崩溃"), "{lang:?} 缺说明:{body}");
|
||||
}
|
||||
// 发布没写说明时只留体积,不留一个空尾巴。
|
||||
let bare = available_body(Lang::En.catalog(), 1024, " ");
|
||||
assert!(bare.contains("1.0 KB"), "{bare}");
|
||||
assert!(!bare.contains('·'), "没有说明时不该留分隔符:{bare}");
|
||||
}
|
||||
|
||||
/// 视图模型的提示条判据与 presenter 同序(就位 > 进行中 > 失败 > 新版本)。
|
||||
#[test]
|
||||
fn the_banner_priority_matches_the_presenter() {
|
||||
let mut update = Update {
|
||||
status: UpdateStatus::Available {
|
||||
version: "0.2.3".to_string(),
|
||||
size: 1,
|
||||
notes: String::new(),
|
||||
forced: false,
|
||||
},
|
||||
..Update::default()
|
||||
};
|
||||
assert!(matches!(update.banner(), Some(Banner::Available { .. })));
|
||||
|
||||
update.skipped = Some("0.2.3".to_string());
|
||||
assert!(update.banner().is_none(), "忽略之后不再打扰");
|
||||
|
||||
// 忽略的是**那一个版本**:同一次运行里冒出 0.2.4 仍然提示(与 presenter 同一语义)。
|
||||
update.status = UpdateStatus::Available {
|
||||
version: "0.2.4".to_string(),
|
||||
size: 1,
|
||||
notes: String::new(),
|
||||
forced: false,
|
||||
};
|
||||
assert!(
|
||||
matches!(update.banner(), Some(Banner::Available { version, .. }) if version == "0.2.4"),
|
||||
"0.2.3 被忽略不该压住 0.2.4"
|
||||
);
|
||||
|
||||
update.skipped = None;
|
||||
update.applying = true;
|
||||
assert!(matches!(update.banner(), Some(Banner::Applying)));
|
||||
|
||||
update.ready = Some("0.2.3".to_string());
|
||||
assert!(matches!(update.banner(), Some(Banner::Ready { .. })));
|
||||
}
|
||||
}
|
||||
#[path = "update/tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,43 @@
|
||||
//! 「这一条更新动作此刻能不能点」(M161:把「按钮亮着、点了没反应」收掉)。
|
||||
//!
|
||||
//! 判据只有一条:有没有检查/下载正在跑。三处必须同源——
|
||||
//!
|
||||
//! | 处 | 读的是 |
|
||||
//! |---|---|
|
||||
//! | presenter `Runtime::inflight()` | `begin_check` / `begin_apply` 置位,`adopt` 清位 |
|
||||
//! | 设置页两颗按钮 | [`Update::can_check`] / [`Update::can_apply`](本文件) |
|
||||
//! | 设置页状态行 | 「正在检查…」/「正在安装…」(同一份 `busy()` 判据) |
|
||||
//! | app 的消息入口 | `App::update_busy`(`app/update/update_action.rs`)——最后一道闸 |
|
||||
//!
|
||||
//! 为什么拆分到本文件:`pages/update.rs` 贴着 400 行硬线(AGENTS §3-1),
|
||||
//! 而这一组判据是「独立的一块问题」(能不能点),独立成文件后更好找。
|
||||
|
||||
use super::{Update, UpdateStatus};
|
||||
|
||||
impl Update {
|
||||
/// 有一条检查/下载正在跑。
|
||||
///
|
||||
/// 两个字段都要看:`status == Checking` 是「查版本」,`applying` 是「下载/校验/替换」。
|
||||
/// presenter 侧同一个判据是 `Runtime::inflight()`(`begin_check` / `begin_apply` 置位,
|
||||
/// `adopt` 清位),页面这层是它的**只读投影**——按钮的禁用态必须与它同源,
|
||||
/// 否则会出现「按钮亮着、点了没反应」。
|
||||
#[must_use]
|
||||
pub fn busy(&self) -> bool {
|
||||
self.applying || matches!(self.status, UpdateStatus::Checking)
|
||||
}
|
||||
|
||||
/// 「立即检查」此刻能点吗。
|
||||
///
|
||||
/// 忙碌时**禁用而不是消失**:入口消失会让人以为功能没了,禁用 + 状态行那句
|
||||
/// 「正在检查…」才说得清「它在干活,等一下」。
|
||||
#[must_use]
|
||||
pub fn can_check(&self) -> bool {
|
||||
!self.busy()
|
||||
}
|
||||
|
||||
/// 「下载并安装」此刻能点吗(要有候选,且不忙)。
|
||||
#[must_use]
|
||||
pub fn can_apply(&self) -> bool {
|
||||
self.available().is_some() && !self.busy()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
//! 自更新视图模型的单测(从 `pages/update.rs` 拆出,那边贴着 400 行硬线)。
|
||||
|
||||
use super::*;
|
||||
|
||||
use unlucky_i18n::Lang;
|
||||
|
||||
/// 提示条的正文**同时**给体积与说明摘要(mission:提示条含版本号、体积、说明摘要)。
|
||||
#[test]
|
||||
fn the_available_banner_carries_both_size_and_notes() {
|
||||
for lang in [Lang::En, Lang::ZhCn] {
|
||||
let body = available_body(lang.catalog(), 21_500_000, "修掉启动崩溃");
|
||||
assert!(body.contains("20.5 MB"), "{lang:?} 缺体积:{body}");
|
||||
assert!(body.contains("修掉启动崩溃"), "{lang:?} 缺说明:{body}");
|
||||
}
|
||||
// 发布没写说明时只留体积,不留一个空尾巴。
|
||||
let bare = available_body(Lang::En.catalog(), 1024, " ");
|
||||
assert!(bare.contains("1.0 KB"), "{bare}");
|
||||
assert!(!bare.contains('·'), "没有说明时不该留分隔符:{bare}");
|
||||
}
|
||||
|
||||
/// 视图模型的提示条判据与 presenter 同序(就位 > 进行中 > 失败 > 新版本)。
|
||||
#[test]
|
||||
fn the_banner_priority_matches_the_presenter() {
|
||||
let mut update = Update {
|
||||
status: UpdateStatus::Available {
|
||||
version: "0.2.3".to_string(),
|
||||
size: 1,
|
||||
notes: String::new(),
|
||||
forced: false,
|
||||
},
|
||||
..Update::default()
|
||||
};
|
||||
assert!(matches!(update.banner(), Some(Banner::Available { .. })));
|
||||
|
||||
update.skipped = Some("0.2.3".to_string());
|
||||
assert!(update.banner().is_none(), "忽略之后不再打扰");
|
||||
|
||||
// 忽略的是**那一个版本**:同一次运行里冒出 0.2.4 仍然提示(与 presenter 同一语义)。
|
||||
update.status = UpdateStatus::Available {
|
||||
version: "0.2.4".to_string(),
|
||||
size: 1,
|
||||
notes: String::new(),
|
||||
forced: false,
|
||||
};
|
||||
assert!(
|
||||
matches!(update.banner(), Some(Banner::Available { version, .. }) if version == "0.2.4"),
|
||||
"0.2.3 被忽略不该压住 0.2.4"
|
||||
);
|
||||
|
||||
update.skipped = None;
|
||||
update.applying = true;
|
||||
assert!(matches!(update.banner(), Some(Banner::Applying)));
|
||||
|
||||
update.ready = Some("0.2.3".to_string());
|
||||
assert!(matches!(update.banner(), Some(Banner::Ready { .. })));
|
||||
}
|
||||
Reference in new issue
Block a user