D26(iced 重写)的关键一次性动作:UI 框架无关的宿主层独立成 crate, Slint 版(crates/app)与 iced 版(crates/app-iced)共用,Slint 退役后不再重写一遍。 - 新建 crates/presenter(package `unlucky-presenter` / lib `unlucky_presenter`), workspace 登记 + crate 文档头写清「这层为什么存在」、对外表面、UI 侧允许/禁止、 iced 接线骨架、以及哪些东西留在了 crates/app 及为什么。 - `git mv`(保留文件历史)迁入:host/(25 文件)、dto/(11 文件)、state.rs(+tests)、 prefs.rs、settings_bridge.rs、toast.rs、router.rs、dialogs.rs、wizard.rs、 mock.rs、mock_data.rs、backend.rs。模块路径与公开 API 名称不变(`host::install` 等), 内部实现零改动。 - 新增 `theme`:把原本混在 ui_bind/theme_runtime 里的**纯判据**(CONFIG_POLL_TICKS / SYSTEM_THEME_POLL_TICKS / TILE_REGENERATE_STEP / BackgroundKey / tile_viewport / system_theme_value / 两个 poll 判据)抽出来,附 5 个单测;app 侧改成调用它们。 - crates/app 改为消费者:删掉迁走的文件,`crate::host|state|dto|prefs|settings_bridge| toast|router|dialogs|wizard|mock|mock_data|backend` 全部改写为 `unlucky_presenter::*` (64 处),backend.rs 的 config_path/build_backend 提为 pub。 - crates/app-iced 只登记 unlucky-presenter 依赖,本 mission 不接线。 - prefs.rs 的 2 处 slint 文档引用改写;`grep -rn slint crates/presenter` 现在无输出。
106 lines
3.8 KiB
Rust
106 lines
3.8 KiB
Rust
//! 版本列表与下载分类映射(下载页)。
|
|
|
|
use crate::{UiVersion, VersionKind};
|
|
use unlucky_presenter::dto::{
|
|
AncientKind, VersionCategory, VersionKind as DtoVersionKind, VersionSummary,
|
|
};
|
|
use unlucky_presenter::state::AppState;
|
|
|
|
/// 分类侧栏 → 该分类下的版本(远古版按子类细分)。
|
|
pub fn in_category(category: VersionCategory, kind: DtoVersionKind) -> bool {
|
|
match (category, kind) {
|
|
(VersionCategory::Release, DtoVersionKind::Release) => true,
|
|
(VersionCategory::Snapshot, DtoVersionKind::Snapshot) => true,
|
|
(VersionCategory::Ancient(expected), DtoVersionKind::Ancient(actual)) => expected == actual,
|
|
// 未接线的分类(整合包 / Mod)不显示任何版本,而不是把全部版本倒进去
|
|
(VersionCategory::Modpack | VersionCategory::Mod, _) => false,
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
/// 版本行(下载页与新建向导共用)。
|
|
pub fn version_rows(versions: &[VersionSummary]) -> Vec<UiVersion> {
|
|
versions
|
|
.iter()
|
|
.map(|version| UiVersion {
|
|
id: version.id.clone().into(),
|
|
kind: version_kind(version.kind),
|
|
released: version.released.clone().into(),
|
|
installed: version.installed,
|
|
ancient: version.kind.is_ancient(),
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
/// 下载页版本行(按当前分类 + 「仅已装」+ 版本号筛选词过滤)。
|
|
pub fn versions(state: &AppState) -> Vec<UiVersion> {
|
|
let query = state.download_query.trim().to_lowercase();
|
|
let filtered: Vec<VersionSummary> = state
|
|
.versions
|
|
.iter()
|
|
.filter(|version| in_category(state.prefs.download_category, version.kind))
|
|
.filter(|version| !state.installed_only || version.installed)
|
|
.filter(|version| query.is_empty() || version.id.to_lowercase().contains(&query))
|
|
.cloned()
|
|
.collect();
|
|
version_rows(&filtered)
|
|
}
|
|
|
|
fn version_kind(kind: DtoVersionKind) -> VersionKind {
|
|
match kind {
|
|
DtoVersionKind::Release => VersionKind::Release,
|
|
DtoVersionKind::Snapshot => VersionKind::Snapshot,
|
|
DtoVersionKind::Ancient(AncientKind::Classic) => VersionKind::AncientClassic,
|
|
DtoVersionKind::Ancient(AncientKind::OldAlpha) => VersionKind::AncientAlpha,
|
|
DtoVersionKind::Ancient(AncientKind::OldBeta) => VersionKind::AncientBeta,
|
|
DtoVersionKind::Ancient(AncientKind::Unlisted) => VersionKind::AncientUnlisted,
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::versions;
|
|
use unlucky_presenter::dto::{VersionKind, VersionSummary};
|
|
use unlucky_presenter::state::AppState;
|
|
|
|
fn state_with_versions() -> AppState {
|
|
let mut state = AppState::new();
|
|
let row = |id: &str, installed: bool| VersionSummary {
|
|
id: id.to_string(),
|
|
kind: VersionKind::Release,
|
|
released: "2026-01-01".to_string(),
|
|
installed,
|
|
};
|
|
state.versions = vec![
|
|
row("1.21.9", false),
|
|
row("1.20.4", true),
|
|
row("1.20.1", true),
|
|
];
|
|
state
|
|
}
|
|
|
|
#[test]
|
|
fn installed_only_filter_hides_uninstalled_versions() {
|
|
let mut state = state_with_versions();
|
|
assert_eq!(versions(&state).len(), 3);
|
|
|
|
state.installed_only = true;
|
|
let filtered = versions(&state);
|
|
assert_eq!(filtered.len(), 2);
|
|
assert!(filtered.iter().all(|version| version.installed));
|
|
}
|
|
|
|
#[test]
|
|
fn query_filters_by_version_id_substring() {
|
|
let mut state = state_with_versions();
|
|
state.download_query = "1.20".to_string();
|
|
let filtered = versions(&state);
|
|
assert_eq!(filtered.len(), 2);
|
|
|
|
state.download_query = "1.21".to_string();
|
|
state.installed_only = true;
|
|
// 「仅已装」优先:1.21.9 未安装 → 空列表
|
|
assert!(versions(&state).is_empty());
|
|
}
|
|
}
|