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` 现在无输出。
74 lines
1.9 KiB
Rust
74 lines
1.9 KiB
Rust
//! 横幅通知 DTO:实例页/下载页顶部的「需要注意」提示条。
|
||
//!
|
||
//! 与 Toast 的分工:Toast 是「刚才发生了什么」(3 秒消失),通知条是
|
||
//! 「现在需要你处理」(用户点了才收)。隔离模式切换提示(M30 `ModeChangeWarning`)
|
||
//! 与启动失败都用它。
|
||
|
||
use serde::{Deserialize, Serialize};
|
||
|
||
/// 通知级别。
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub enum NoticeLevel {
|
||
/// 一般信息
|
||
Info,
|
||
/// 需要留意(黄条)
|
||
Warn,
|
||
/// 失败(红条)
|
||
Error,
|
||
}
|
||
|
||
impl NoticeLevel {
|
||
/// 级别文案(无障碍/测试用)。
|
||
pub fn label(self) -> &'static str {
|
||
match self {
|
||
Self::Info => "信息",
|
||
Self::Warn => "注意",
|
||
Self::Error => "错误",
|
||
}
|
||
}
|
||
}
|
||
|
||
/// 一条通知。
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||
pub struct NoticeView {
|
||
/// 稳定 id(关闭时按它移除)
|
||
pub id: String,
|
||
/// 级别
|
||
pub level: NoticeLevel,
|
||
/// 标题
|
||
pub title: String,
|
||
/// 正文
|
||
pub body: String,
|
||
}
|
||
|
||
impl NoticeView {
|
||
/// 建一条。
|
||
pub fn new(id: &str, level: NoticeLevel, title: &str, body: &str) -> Self {
|
||
Self {
|
||
id: id.to_string(),
|
||
level,
|
||
title: title.to_string(),
|
||
body: body.to_string(),
|
||
}
|
||
}
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
|
||
#[test]
|
||
fn notices_are_serde_round_trip_safe() {
|
||
let notice = NoticeView::new(
|
||
"isolation:demo",
|
||
NoticeLevel::Warn,
|
||
"隔离模式已切换",
|
||
"旧目录里还有 mods/saves",
|
||
);
|
||
let text = serde_json::to_string(¬ice).expect("序列化");
|
||
let back: NoticeView = serde_json::from_str(&text).expect("反序列化");
|
||
assert_eq!(back, notice);
|
||
assert_eq!(back.level.label(), "注意");
|
||
}
|
||
}
|