feat(presenter): 新建 unlucky-presenter,把 host/状态/DTO/设置桥从 app 迁出(M85 第 1 块)
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` 现在无输出。
This commit is contained in:
1 parent
00f132d8ce
commit
f159529936
69 files changed
+441
-129
No files matched your search
+12
-30
@@ -14,27 +14,18 @@ use std::time::Duration;
|
||||
|
||||
use slint::{ComponentHandle, ModelRc, VecModel};
|
||||
|
||||
use crate::backend::{build_backend, config_path, AppOptions};
|
||||
use crate::bg_image::BackgroundLayers;
|
||||
use crate::conv;
|
||||
use crate::dto::{AppCommand, Backend};
|
||||
use crate::prefs::BgFill;
|
||||
use crate::settings_bridge::SettingsBridge;
|
||||
use crate::state::AppState;
|
||||
use crate::{MainWindow, PageState, SettingSection};
|
||||
use unlucky_presenter::backend::{build_backend, config_path, AppOptions};
|
||||
use unlucky_presenter::dto::{AppCommand, Backend};
|
||||
use unlucky_presenter::settings_bridge::SettingsBridge;
|
||||
use unlucky_presenter::state::AppState;
|
||||
use unlucky_presenter::theme::BackgroundKey;
|
||||
|
||||
/// 定时器节拍:33ms ≈ 30fps(磁贴进度环 / 流式文本 / Toast TTL 的刷新下限)。
|
||||
const TICK_MS: u64 = 33;
|
||||
|
||||
/// 配置热切轮询间隔(拍数):约 1s 一次 `mtime` 比对,AI/CLI 改完下一拍即生效。
|
||||
pub(crate) const CONFIG_POLL_TICKS: u64 = 30;
|
||||
|
||||
/// 系统主题兜底轮询间隔(拍数):只在 `auto` 且后端不认识系统主题时启动(约 3s)。
|
||||
pub(crate) const SYSTEM_THEME_POLL_TICKS: u64 = 90;
|
||||
|
||||
/// tile 模式重建画布的窗口尺寸粒度(像素):避免拖动窗口时反复重算平铺画布。
|
||||
pub(crate) const TILE_REGENERATE_STEP: u32 = 128;
|
||||
|
||||
/// 应用外壳:持有窗口、状态与后端,把三者缝在一起。
|
||||
pub struct AppUi {
|
||||
inner: Rc<Inner>,
|
||||
@@ -57,15 +48,6 @@ pub(crate) struct Inner {
|
||||
pub(crate) system_theme_probed: Cell<bool>,
|
||||
}
|
||||
|
||||
/// 背景图加工输入(值相同就不重新解码)。
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct BackgroundKey {
|
||||
pub(crate) path: String,
|
||||
pub(crate) fill: BgFill,
|
||||
/// tile 用的窗口尺寸(按 [`TILE_REGENERATE_STEP`] 量化;cover/contain 恒为 (0, 0))
|
||||
pub(crate) viewport: (u32, u32),
|
||||
}
|
||||
|
||||
impl AppUi {
|
||||
/// 建状态 + 真实后端、读配置、接全部回调、灌初始事件并做第一次同步。
|
||||
pub fn new(ui: MainWindow) -> Self {
|
||||
@@ -136,7 +118,7 @@ impl AppUi {
|
||||
self.inner
|
||||
.state
|
||||
.borrow_mut()
|
||||
.navigate(crate::router::Route::Settings);
|
||||
.navigate(unlucky_presenter::router::Route::Settings);
|
||||
self.inner.sync();
|
||||
self.inner
|
||||
.ui
|
||||
@@ -147,11 +129,11 @@ impl AppUi {
|
||||
/// 直接跳到一个页面(截图验收用:每页一张)。
|
||||
pub fn open_page(&self, page: &str) {
|
||||
let route = match page {
|
||||
"download" | "java" => crate::router::Route::Download,
|
||||
"logs" => crate::router::Route::Logs,
|
||||
"settings" | "account" | "appearance" => crate::router::Route::Settings,
|
||||
"agent" => crate::router::Route::Agent,
|
||||
_ => crate::router::Route::Instances,
|
||||
"download" | "java" => unlucky_presenter::router::Route::Download,
|
||||
"logs" => unlucky_presenter::router::Route::Logs,
|
||||
"settings" | "account" | "appearance" => unlucky_presenter::router::Route::Settings,
|
||||
"agent" => unlucky_presenter::router::Route::Agent,
|
||||
_ => unlucky_presenter::router::Route::Instances,
|
||||
};
|
||||
{
|
||||
let mut state = self.inner.state.borrow_mut();
|
||||
@@ -184,7 +166,7 @@ impl AppUi {
|
||||
|
||||
/// 打开新建实例向导(截图验收用)。
|
||||
pub fn open_wizard(&self) {
|
||||
self.inner.state.borrow_mut().wizard = crate::wizard::WizardState::open();
|
||||
self.inner.state.borrow_mut().wizard = unlucky_presenter::wizard::WizardState::open();
|
||||
self.inner.sync();
|
||||
slint::platform::update_timers_and_animations();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user