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
@@ -7,15 +7,16 @@ use slint::ComponentHandle;
|
||||
|
||||
use crate::bg_image::{self, BackgroundLayers};
|
||||
use crate::conv;
|
||||
use crate::prefs::{AppearancePrefs, BgFill, ThemeMode};
|
||||
use crate::toast::ToastKind;
|
||||
use crate::ui_bind::{
|
||||
BackgroundKey, Inner, CONFIG_POLL_TICKS, SYSTEM_THEME_POLL_TICKS, TILE_REGENERATE_STEP,
|
||||
use crate::ui_bind::Inner;
|
||||
use unlucky_presenter::prefs::{AppearancePrefs, BgFill, ThemeMode};
|
||||
use unlucky_presenter::theme::{
|
||||
config_poll_due, system_theme_poll_due, system_theme_value, BackgroundKey,
|
||||
};
|
||||
use unlucky_presenter::toast::ToastKind;
|
||||
|
||||
impl Inner {
|
||||
pub(crate) fn poll_settings(&self) {
|
||||
if !self.ticks.get().is_multiple_of(CONFIG_POLL_TICKS) {
|
||||
if !config_poll_due(self.ticks.get()) {
|
||||
return;
|
||||
}
|
||||
let Some((appearance, theme)) = self.bridge.borrow_mut().reload_if_changed() else {
|
||||
@@ -35,17 +36,17 @@ impl Inner {
|
||||
pub(crate) fn poll_system_theme(&self) {
|
||||
let auto = matches!(self.state.borrow().prefs.theme, ThemeMode::Auto);
|
||||
let backend_known = self.ui.get_system_theme_known();
|
||||
let due = !self.system_theme_probed.get()
|
||||
|| (auto && !backend_known && self.ticks.get().is_multiple_of(SYSTEM_THEME_POLL_TICKS));
|
||||
let due = system_theme_poll_due(
|
||||
self.system_theme_probed.get(),
|
||||
auto,
|
||||
backend_known,
|
||||
self.ticks.get(),
|
||||
);
|
||||
if !due {
|
||||
return;
|
||||
}
|
||||
self.system_theme_probed.set(true);
|
||||
let value = match unlucky_core::platform::theme_probe::probe() {
|
||||
unlucky_core::platform::theme_probe::SystemTheme::Light => 1,
|
||||
unlucky_core::platform::theme_probe::SystemTheme::Dark => 2,
|
||||
unlucky_core::platform::theme_probe::SystemTheme::Unknown => 0,
|
||||
};
|
||||
let value = system_theme_value();
|
||||
if self.ui.get_system_theme() != value {
|
||||
self.ui.set_system_theme(value);
|
||||
}
|
||||
@@ -124,16 +125,15 @@ impl Inner {
|
||||
}
|
||||
}
|
||||
|
||||
/// tile 画布的窗口尺寸(量化到 [`TILE_REGENERATE_STEP`],避免拖动窗口时反复重算)。
|
||||
/// tile 画布的窗口尺寸(量化到 `TILE_REGENERATE_STEP`,避免拖动窗口时反复重算)。
|
||||
///
|
||||
/// 判据在 [`unlucky_presenter::theme::tile_viewport`](两侧 UI 共用一份);这里只负责
|
||||
/// 提供窗口物理尺寸。
|
||||
fn tile_viewport(&self, fill: BgFill) -> (u32, u32) {
|
||||
if fill != BgFill::Tile {
|
||||
return (0, 0);
|
||||
}
|
||||
let (width, height) = self.window_physical_size();
|
||||
(
|
||||
width / TILE_REGENERATE_STEP * TILE_REGENERATE_STEP,
|
||||
height / TILE_REGENERATE_STEP * TILE_REGENERATE_STEP,
|
||||
)
|
||||
unlucky_presenter::theme::tile_viewport(fill, self.window_physical_size())
|
||||
}
|
||||
|
||||
/// 窗口物理像素尺寸(取不到时 (0, 0),tile 退化为单块)。
|
||||
|
||||
Reference in new issue
Block a user