refactor(download): rebase 到 M93 之后 app/update.rs 破 400 → 下载页四支拆到 update/download.rs
M93(外观三件套接线)合入后 `app/update.rs` 从 348 涨到 410 行,再加上下载页的四个 arm
会顶破 ≤400 硬线。把下载页那几支(SelectVersion / InstallVersion / CancelInstall /
SetCategory / Action::RefreshSources)挪到 `app/update/download.rs`(`app/update/**` 在本
mission scope 内),`on_page` 入口只留一句 `if self.on_download(&message) { return; }`,
match 末尾补一条 `_ => {}` 做穷尽性。
行为零变化:指令、视图模型写法、`refresh_view` 顺序都照搬;M93 的 `Appearance` arm /
`env_start_route` / `on_appearance` 一行没动。
行数:update.rs 410 → 397,download.rs 57。
This commit is contained in:
1 parent
6453c76750
commit
5340908882
2 files changed
+69
-25
No files matched your search
@@ -0,0 +1,57 @@
|
||||
//! 下载页在 app 层的那几支(M94)。
|
||||
//!
|
||||
//! 为什么单独一个文件:M93(外观三件套接线)合入后 `update.rs` 已经贴到 400 行,下载页再往里塞
|
||||
//! 四个 arm 就顶破硬线;拆出来是既不动 M93 的代码、又能守住 ≤400 的办法(`app/update/**` 属本
|
||||
//! mission scope)。
|
||||
//!
|
||||
//! ## 四支各自的纪律
|
||||
//!
|
||||
//! | 消息 | 落点 | 为什么 |
|
||||
//! |---|---|---|
|
||||
//! | [`pages::Message::SelectVersion`] | **只改视图模型** | 选中是页面内状态,不是业务命令 |
|
||||
//! | [`pages::Message::InstallVersion`] | `AppCommand::InstallVersion` | 真指令,回事件后才画进度 |
|
||||
//! | [`pages::Message::CancelInstall`] | `AppCommand::CancelInstall` | 同上(host 侧对没在跑的任务是 no-op) |
|
||||
//! | [`pages::Message::SetCategory`] | 写分类 → 重建 → `AppCommand::ListVersions` | 见下 |
|
||||
//!
|
||||
//! [「刷新下载源」](pages::Action::RefreshSources) 也在这里:它不是占位动作,具体分类 → 重拉该分类、
|
||||
//! 「全部」→ 让 host 重扫一遍(`RefreshAll`)。
|
||||
//!
|
||||
//! ## 分类为什么既写视图模型、又派指令
|
||||
//!
|
||||
//! 真 host 的 `AppCommand::ListVersions(_)` 会丢掉分类参数、回全量清单(复审 P2-1),所以**过滤在
|
||||
//! 本页做**:写进视图模型 → 立刻 `refresh_view()`(它会把 category 带回去、按同一谓词过滤行)→
|
||||
//! 再派指令。这不是「乐观回显」:写的是**过滤条件本身**,chip 与列表用同一个
|
||||
//! [`Category::matches`](crate::pages::Category),于是不可能出现「chip 说正式版、列表是全量」的两份真相。
|
||||
|
||||
use super::*;
|
||||
|
||||
impl App {
|
||||
/// 下载页的消息。**处理了返回 `true`**(`on_page` 里就不用再写一遍这些 arm)。
|
||||
pub(super) fn on_download(&mut self, message: &pages::Message) -> bool {
|
||||
match message {
|
||||
pages::Message::SelectVersion(id) => {
|
||||
self.view.download.selected = Some(id.clone());
|
||||
}
|
||||
pages::Message::InstallVersion(id) => {
|
||||
self.dispatch(AppCommand::InstallVersion(id.clone()));
|
||||
}
|
||||
pages::Message::CancelInstall => self.dispatch(AppCommand::CancelInstall),
|
||||
pages::Message::SetCategory(category) => {
|
||||
self.view.download.category = *category;
|
||||
self.view_dirty = true;
|
||||
self.refresh_view();
|
||||
if let Some(kind) = category.command() {
|
||||
self.dispatch(AppCommand::ListVersions(kind));
|
||||
}
|
||||
}
|
||||
pages::Message::Action(pages::Action::RefreshSources) => {
|
||||
match self.view.download.category.command() {
|
||||
Some(kind) => self.dispatch(AppCommand::ListVersions(kind)),
|
||||
None => self.dispatch(AppCommand::RefreshAll),
|
||||
}
|
||||
}
|
||||
_ => return false,
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user