feat(app-iced): M109 CONTENTDL —— 内容库页(整合包/Mod/资源包/光影)

用户令「下载页只负责下载整合包和Mod/光影」:新开一页做**内容发现与装入**,
检索走 Modrinth(优先,无需 key)/ CurseForge(`ULL_CF_API_KEY` 环境变量,日志只打
set/unset),装入走 core 的下载引擎真下到实例目录,进度/取消/失败复用下载页那块安装面板。

- **入口(B1)**:`Route::Content` 是新顶层路由,但 `Route::nav()` 复用 `NavSection::Download`
  ——导航轨仍五项,页头右上是「版本管理 | 内容库」一级切换(版本管理页也加了同一个切换,
  否则内容库只有 `ULL_START_ROUTE` 能到)
- **页内四条一级侧栏**(`pages/content/layout.rs` 四档几何:992/856/648 三个门槛都是
  「Σ栏宽 + 间距」算出来的):整合包 / Mod / 资源包 / 光影;标签栏 200(`Resource packs`
  比 M107 的版本类型名长,140 会切字,已登记偏离)
- **筛选**:关键词(草稿 + 显式「搜索」按钮,不逐字打网络)、来源、游戏版本、加载器
  (Fabric/Forge/NeoForge/Quilt)、排序;**分页**(「加载更多」)而不是无限滚动——快照只有一个槽、
  翻页要看得见、状态要可截图复现
- **四态**:加载 / 空 / 失败 / 有数据 + 「没有更多了」;筛选条在任何状态下都在(加载中藏筛选条
  等于把入口收走)
- **一键装入**:`Content::blockers()` 是纯函数——版本不匹配、加载器不匹配、没有目标实例、
  整合包缺管线**四条原因逐条**给出,按钮点之前就禁用;判定与画法分开(model/tests 直接钉)
- **整合包今天不可装**:`ContentKind::Modpack.dir()` 是 `None`,UI 禁用 + 说明,host 侧再挡
  一次(绕过 UI 也只会回一条 Failed)。真流程是 M111 的导入管线
- **零 UI 网络**:`presenter/host/addon.rs` + `addon/{sources,http,install}.rs`;无 header 的请求走
  core 的 `download_bytes`(信号量限流 + 健康度 + 退避全现成),带 `X-API-KEY` 的只有 CF 一条,
  自带 429/5xx 退避(优先吃 `Retry-After`,封顶 30s);密钥不进 DTO/日志/仓库
- 文案 41 条中英进 `crates/i18n`(新域接在装配链末尾 ⇒ `Key::ALL` 与金表只追加)
- 演示数据 `ContentHit → Hit::of` 与产品路径同源(格式化不会两套),`ULL_CONTENT_KIND` /
  `ULL_CONTENT_STATE` 供出图矩阵选类型与状态

取证:`DevDocs/artifacts/m109/`(10 张:四类内容 × 浅/深 + 搜索无结果 + 加载器不兼容禁用)

门禁:fmt ✓ / clippy `-D warnings`(三 crate)✓ / app-iced 450+6、presenter 170、i18n 24 全绿;
`cargo tree` 两条零 UI 门禁仍空;全部改动文件 ≤400 行。
This commit is contained in:
AskaEth committed 2026-11-05 03:20:21 +08:00
1 parent 5adac230fe
commit 6b161227d8
42 files changed
+4071 -25

No files matched your search

+2 -1
View File
@@ -89,7 +89,8 @@ pub(super) fn route_of(nav: NavItem) -> Route {
pub(super) fn nav_item_of(route: &Route) -> NavItem {
match route {
Route::Instances | Route::Detail(_) => NavItem::Instances,
Route::Download => NavItem::Download,
// M109:内容库与版本管理共用「下载」那一个导航项(B1 裁定)
Route::Download | Route::Content => NavItem::Download,
Route::Logs => NavItem::Logs,
Route::Settings => NavItem::Settings,
Route::Agent => NavItem::Ai,
+8
View File
@@ -146,6 +146,12 @@ pub struct App {
/// 已经提示过的取消次数(M105):`AppState::install_cancelled` 是「发生过几次取消」,
/// 这里是「其中几次已经弹过提示」。两者不等 ⇒ 弹一次 i18n 提示。
pub(super) install_cancelled_seen: u64,
/// 内容库页的页面内选择(M109):内容类型 / 选中项目 / 目标实例 / 关键词草稿。
///
/// 为什么在 `App` 而不是 presenter:这四样是「用户在这一屏上点了什么」,重建快照不该冲掉;
/// 而检索条件与结果(会跨页存活、要被事件写)在 `AppState::content`。放进 `view` 模型也
/// 不行——`refresh_view` 每次都用快照重建模型,选择会被冲回默认值。
pub(super) content: pages::content::PageState,
}
impl App {
@@ -246,6 +252,7 @@ impl App {
// 下载页安装草稿(M105):出厂态 = 没选中、原版、两个空串
download_draft: pages::InstallDraft::default(),
install_cancelled_seen: 0,
content: pages::content::PageState::default(),
};
// 配色来源档可能已经指向一张背景图:那时 `Ui` 必须由解析出的方案构造,而不是 baseline。
app.rebuild_ui();
@@ -338,6 +345,7 @@ impl App {
category,
&draft,
self.lang(),
&self.content,
);
self.view_dirty = false;
self.refreshes += 1;
+6 -1
View File
@@ -43,6 +43,7 @@ use super::state::{App, IDLE_TICK, TICK, TICK_MS, WATCH_WINDOW};
use super::CAPTURE_AT_FRAME;
mod agent;
mod content;
mod download;
mod page_messages;
mod settings;
@@ -173,6 +174,8 @@ impl App {
self.state.navigate(route);
// 直达某一页时不要再被「自动选中第一条实例」拉回详情页。
self.auto_selected = true;
// M109:直达内容库时补一次检索(与页面内切换同一个入口)
self.ensure_content_loaded();
}
self.auto_select();
@@ -364,7 +367,7 @@ fn heartbeat() -> Task<Message> {
})
}
/// 取证开关 `ULL_START_ROUTE` 的取值解析(`settings` / `instances` / `download` / `logs`)。
/// 取证开关 `ULL_START_ROUTE` 的取值解析(`settings` / `instances` / `download` / `content` / `logs`)。
///
/// 为什么是环境变量:`crates/app-iced/src/cli.rs` 不在 M93 的 scope,而外观矩阵必须在**设置页**上
/// 出图。语义与 `ULL_APPEARANCE_*` / `ULL_TICK_TRACE` 一致:只影响这一次进程。
@@ -376,6 +379,8 @@ fn env_start_route() -> Option<Route> {
"settings" => Some(Route::Settings),
// M104:AI 独立页也要能直达(三态矩阵的 Detached 那张)
"agent" => Some(Route::Agent),
// M109:内容库(截图矩阵要能直达;页面内的四条侧栏不在路由里)
"content" => Some(Route::Content),
_ => None,
}
}
+163
View File
@@ -0,0 +1,163 @@
//! 内容库页的消息落点(M109):`pages::Message::Content(..)` 的穷尽分发。
//!
//! ## 两件事分开(与 `update/download.rs` 同一条纪律)
//!
//! | 意图 | 谁改状态 | 派指令吗 |
//! |---|---|---|
//! | 关键词草稿 / 选中项目 / 目标实例 | `App::content`(页面内选择) | 不派 |
//! | 检索条件(类型/来源/排序/版本/加载器/关键词提交/翻页/重试) | `AppState::content`(presenter) | 派 `SearchContent` |
//! | 装入 | 谁都不改 | 派 `InstallContent` |
//!
//! 「装入」不改本地状态是关键:装上的证据是 `InstallProgress` 事件回流到安装面板
//! (`pages/download::install_panel`),页面自己不做乐观回显。
//!
//! ## 为什么条件写进 presenter 再派
//!
//! `AppState::content.query` 是「当前结果对应哪份条件」的唯一真相:结果回来时
//! `apply_content` 用它判「迟到的事件要不要丢」。页面自己存一份就会有两份真相。
use unlucky_presenter::dto::{AppCommand, ContentInstallRequest, ContentQuery, ContentSource};
use crate::pages::content::{Blocker, Content};
use super::*;
impl App {
/// 进入内容库页时补一次检索(首个用户动作不该是「再点一下搜索」)。
///
/// 判据是 `AppState::content` 里还没有结果、也没有请求在飞:重复进出不重复打网络。
pub(super) fn ensure_content_loaded(&mut self) {
if self.state.content.results.is_some() || self.state.content.pending {
return;
}
let query = ContentQuery::first(self.content.kind);
self.search_content(query);
}
/// 页面消息(穷尽分发:漏一支报 E0004)。
pub(super) fn on_content(&mut self, message: pages::content::Message) -> Task<Message> {
match message {
pages::content::Message::SetKind(kind) => {
// 换类型 = 换一份条件(facet 全变):选中项作废,条件回到该类型的首页
self.content.kind = kind;
self.content.selected = None;
let mut query = ContentQuery::first(kind);
// 保留用户已经选好的来源/排序/版本/加载器:换成默认值会让筛选条自己跳回去
query.source = self.state.content.query.source;
query.sort = self.state.content.query.sort;
query.game_version = self.state.content.query.game_version.clone();
query.loader = self.state.content.query.loader;
self.search_content(query);
}
pages::content::Message::QueryChanged(text) => {
self.content.draft = text;
self.view_dirty = true;
}
pages::content::Message::Search => {
let mut query = self.state.content.query.clone();
query.text = self.content.draft.trim().to_string();
query.offset = 0;
self.search_content(query);
}
pages::content::Message::SetSource(source) => {
if source == ContentSource::Curseforge && !self.curseforge_available() {
// 筛选条那条本来就是禁用的;这里再挡一次(防绕过 UI 的消息)
return Task::none();
}
self.with_query(|query| query.source = source);
}
pages::content::Message::SetSort(sort) => self.with_query(|query| query.sort = sort),
pages::content::Message::SetVersion(version) => {
self.with_query(|query| query.game_version = version);
}
pages::content::Message::SetLoader(loader) => {
self.with_query(|query| query.loader = loader)
}
pages::content::Message::Select(id) => {
self.content.selected = Some(id);
self.view_dirty = true;
}
pages::content::Message::SetTarget(id) => {
self.content.target = Some(id);
self.view_dirty = true;
}
pages::content::Message::LoadMore => {
let next = self.state.content.query.next_page();
self.search_content(next);
}
pages::content::Message::Retry => {
let mut query = self.state.content.query.clone();
query.offset = 0;
self.search_content(query);
}
pages::content::Message::Install => {
if let Some(request) = self.content_install_request() {
self.dispatch(AppCommand::InstallContent(Box::new(request)));
}
}
}
Task::none()
}
/// 改一个筛选字段并**立刻重查**(第一页)。
fn with_query(&mut self, change: impl FnOnce(&mut ContentQuery)) {
let mut query = self.state.content.query.clone();
change(&mut query);
query.offset = 0;
self.search_content(query);
}
/// 提交一次检索:条件先落进 presenter(迟到事件的判据),再派指令。
fn search_content(&mut self, query: ContentQuery) {
self.state.set_content_query(query.clone());
self.view_dirty = true;
self.dispatch(AppCommand::SearchContent(query));
}
/// CF 源可用吗(结果里带回的那一位;还没拉过 ⇒ `false`)。
fn curseforge_available(&self) -> bool {
self.state
.content
.results
.as_ref()
.is_some_and(|results| results.curseforge)
}
/// 组一份内容库的「装入」请求;闸门与页面上的按钮**同一个判据**(`Content::can_install`)。
///
/// 名字带 `content_`:M105 的版本安装已经占了 `install_request`(版本 → `CreateRequest`),
/// 两者语义完全不同,撞名会被编译器拦下(本轮 rebase 撞过)。
///
/// 这里再判一次不是重复劳动:页面禁用的只是那一个按钮,消息仍然可能从别的路径进来,
/// 而 host 侧对整合包会直接回失败——三道闸门同一个结论,才不会出现「有的路能过」。
fn content_install_request(&self) -> Option<ContentInstallRequest> {
let catalog = unlucky_i18n::Lang::En.catalog();
let model = Content::from_snapshot(&self.state, &self.content, catalog);
if !model.can_install() {
// 有原因就打印出来(取证用);没有选中项时什么都不做
for reason in model.blocker_reasons(catalog) {
eprintln!("[content] 装入被挡下:{reason}");
}
if model.blockers.contains(&Blocker::NeedsPipeline) {
eprintln!("[content] 整合包装入未实现(M111)");
}
return None;
}
let hit = model.selected_hit()?;
let target = model
.targets
.iter()
.find(|target| Some(&target.id) == model.target.as_ref())?;
Some(ContentInstallRequest {
project: hit.id.clone(),
title: hit.title.clone(),
// 整合包走不到这里:`ContentKind::Modpack` 的 `dir()` 是 `None` ⇒ 必然带
// `Blocker::NeedsPipeline` ⇒ `can_install()` 为假。所以这里就是「单文件」那一类。
kind: model.kind,
source: hit.source,
instance: target.id.clone(),
game_version: target.mc_version.clone(),
loader: target.loader,
})
}
}
@@ -43,9 +43,15 @@ impl App {
match message {
pages::Message::Navigate(route) => {
// M109:进内容库时补一次检索(首个动作不该是「再点一下搜索」)。
// 判据在 `ensure_content_loaded` 里(已有结果/请求在飞就不重复打网络)。
let entering_content = route == Route::Content;
self.state.navigate(route);
self.view_dirty = true;
self.refresh_view();
if entering_content {
self.ensure_content_loaded();
}
}
pages::Message::Launch(id) => self.dispatch(AppCommand::LaunchInstance(id)),
pages::Message::Stop(id) => self.dispatch(AppCommand::StopInstance(id)),
@@ -57,6 +63,8 @@ impl App {
// 这是**唯一**一处绕开 M101 投递口的页面消息:语言档位不是「某一组的状态」,
// 它要落盘到 `ui.language` 并重建整棵视图模型(设置页的语言行只是它的第一个出口)。
pages::Message::Language(choice) => self.set_language(choice),
// M109:内容库那一套意图在自己的文件里穷尽分发(`update/content.rs`)
pages::Message::Content(message) => return self.on_content(message),
// M95:摘要落剪贴板(文本由页面造,这里只搬)
pages::Message::CopySummary(text) => return iced::clipboard::write(text),
// 下面四支已由 `on_download` 提前消化;显式列出而不是 `_ => {}`,见模块文档
+13 -1
View File
@@ -111,6 +111,7 @@ pub(super) fn model(
category: pages::Category,
draft: &pages::InstallDraft,
lang: Lang,
content: &pages::content::PageState,
) -> pages::Model {
let route = state.route().clone();
let screen = pages::Screen::of(&route).unwrap_or(pages::Screen::Instances);
@@ -141,6 +142,8 @@ pub(super) fn model(
active: route.nav(),
instances: pages::Instances { rows, detail },
download: pages::Download::from_snapshot(state, category, draft, lang.catalog()),
// M109:检索条件/结果来自快照,页面内选择(类型/选中/目标/草稿)来自 `App::content`
content: pages::content::Content::from_snapshot(state, content, lang.catalog()),
logs: logs_model(state).with_status(lang),
lang,
forced: forced.map(|state| match state {
@@ -280,7 +283,16 @@ mod tests {
/// 测试用的薄包装:默认宽度 / 默认分类 / 空草稿。
fn at(state: &AppState, forced: Option<crate::cli::ForcedState>) -> pages::Model {
let (draft, lang) = (pages::InstallDraft::default(), Lang::En);
model(state, 1180.0, forced, pages::Category::All, &draft, lang)
let page = pages::content::PageState::default();
model(
state,
1180.0,
forced,
pages::Category::All,
&draft,
lang,
&page,
)
}
#[test]