From 09766a437700b4e9c1bcc17ca69fee38e88735e0 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Thu, 3 Dec 2026 13:03:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(xiaoyi):=20=E4=BF=AE=E5=A4=8D=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E9=A1=B5=E6=A3=80=E6=9F=A5=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=A0=E5=93=8D=E5=BA=94=E4=B8=8E=E7=BC=A9=E7=9F=AD?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=A3=80=E6=9F=A5=E9=97=B4=E9=9A=94=20(1.261?= =?UTF-8?q?2.114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/detail-photocraft/client-version.txt | 2 +- .../crates/ui-egui/src/jiansun.rs | 2 + .../crates/ui-egui/src/jiansun/agent_panel.rs | 6 +- .../ui-egui/src/jiansun/client_update.rs | 53 ++++++++++++++- .../ui-egui/src/jiansun/client_update_ui.rs | 67 ++++++++++++++++++- .../ui-egui/src/jiansun/project_browser.rs | 2 + 6 files changed, 127 insertions(+), 5 deletions(-) diff --git a/apps/detail-photocraft/client-version.txt b/apps/detail-photocraft/client-version.txt index a45eafd2..2c77594b 100644 --- a/apps/detail-photocraft/client-version.txt +++ b/apps/detail-photocraft/client-version.txt @@ -1 +1 @@ -1.2612.113 +1.2612.114 diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs index c16671f8..289f2b20 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun.rs @@ -3182,6 +3182,7 @@ impl Workspace { if let Ok(receipt) = result { self.client_update.receive(receipt); } + ctx.request_repaint(); return; } if matches!( @@ -4099,6 +4100,7 @@ impl Workspace { } if self.exit_admission_closed.load(std::sync::atomic::Ordering::Acquire) { return; } self.client_update.tick(&self.account, &self.origin, &self.tx, ctx, Instant::now()); + self.flush_client_update_request(app); if !self.tick_context(app, ctx) { self.tick_parked_projects(app, ctx); return; diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/agent_panel.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/agent_panel.rs index 36424246..0583c378 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/agent_panel.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/agent_panel.rs @@ -3304,7 +3304,10 @@ impl Workspace { if ultra { if super::stitch_ui::command_menu_item(ui, "sparkles", "生图", self.can_send_with(app, true)).clicked() { self.send_image_once(app); ui.close(); } if super::stitch_ui::command_menu_item(ui, "sliders-horizontal", "连接设置、通知与警告", true).clicked() { - self.model_settings = true; self.prompt_library.close(); ui.close(); + self.model_settings = true; + self.prompt_library.close(); + self.maybe_check_update_on_settings_open(); + ui.close(); } } }); @@ -3355,6 +3358,7 @@ impl Workspace { self.model_settings = !self.model_settings; if self.model_settings { self.prompt_library.close(); + self.maybe_check_update_on_settings_open(); } if !self.model_settings { self.api_key.clear(); diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update.rs index 7cbdf592..43001df3 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update.rs @@ -1,6 +1,7 @@ use super::*; -const CHECK_INTERVAL: Duration = Duration::from_secs(6 * 60 * 60); +const CHECK_INTERVAL: Duration = Duration::from_secs(15 * 60); +const SETTINGS_OPEN_CHECK_COOLDOWN: Duration = Duration::from_secs(60); const PORTABLE: &str = "当前从便携目录启动,请使用小壹发布包安装后更新"; type ApplyUpdate = fn(&Value) -> Result<(), String>; @@ -123,6 +124,16 @@ impl ClientUpdate { ctx.request_repaint_after(CHECK_INTERVAL - elapsed); } } + + pub(super) fn should_check_on_settings_open(&self, account: &Value, now: Instant) -> bool { + if self.apply.is_none() || account["id"].is_null() { + return false; + } + if matches!(self.state["status"].as_str(), Some("checking" | "downloading" | "ready")) { + return false; + } + self.last_check.is_none_or(|at| now.saturating_duration_since(at) >= SETTINGS_OPEN_CHECK_COOLDOWN) + } } impl Workspace { @@ -130,6 +141,12 @@ impl Workspace { self.client_update.version["version"].as_str() } + pub(super) fn maybe_check_update_on_settings_open(&mut self) { + if self.client_update.should_check_on_settings_open(&self.account, Instant::now()) { + self.client_update_ui.requested = Some("check"); + } + } + pub fn configure_client_update(&mut self, version: Value, installed: bool, apply: ApplyUpdate) { self.client_update.version = version; @@ -208,7 +225,8 @@ mod tests { } #[test] - fn client_update_checks_on_login_then_waits_six_hours_after_an_error() { + fn client_update_checks_on_login_then_waits_check_interval_after_an_error() { + assert_eq!(CHECK_INTERVAL, Duration::from_secs(15 * 60)); let (tx, requests) = mpsc::channel(); let mut update = ClientUpdate { apply: Some(|_| Ok(())), ..ClientUpdate::default() }; let ctx = egui::Context::default(); @@ -223,7 +241,38 @@ mod tests { assert_eq!(update.state["status"], "error"); assert!(requests.try_recv().is_err()); let next_check = update.last_check.unwrap() + CHECK_INTERVAL; + update.tick(&account, "local", &tx, &ctx, next_check - Duration::from_secs(1)); + assert!(requests.try_recv().is_err()); update.tick(&account, "local", &tx, &ctx, next_check); assert!(requests.try_recv().is_ok()); } + + #[test] + fn settings_open_triggers_check_only_after_cooldown_and_not_when_ready_or_busy() { + let base = Instant::now(); + let account = json!({"id":"qa"}); + let mut update = ClientUpdate::default(); + assert!(!update.should_check_on_settings_open(&account, base)); + update.apply = Some(|_| Ok(())); + assert!(!update.should_check_on_settings_open(&Value::Null, base)); + assert!(update.should_check_on_settings_open(&account, base)); + + for status in ["checking", "downloading", "ready"] { + update.state["status"] = json!(status); + assert!(!update.should_check_on_settings_open(&account, base), "{status} should not trigger"); + } + + update.last_check = Some(base); + for status in ["up-to-date", "available", "error"] { + update.state["status"] = json!(status); + assert!( + !update.should_check_on_settings_open(&account, base + Duration::from_secs(59)), + "{status} before cooldown should not trigger", + ); + assert!( + update.should_check_on_settings_open(&account, base + Duration::from_secs(60)), + "{status} at cooldown should trigger", + ); + } + } } diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update_ui.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update_ui.rs index 57b11c17..64694895 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update_ui.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/client_update_ui.rs @@ -11,7 +11,7 @@ pub(super) struct UpdateUi { /// 最近一次动作的错误:动作名、原文、出错时的更新状态。状态变了就不再显示。 error: Option<(&'static str, String, Value)>, /// 设置浮层里点了"检查更新"。设置浮层拿不到 app,由输入框区域随后派发。 - requested: Option<&'static str>, + pub(super) requested: Option<&'static str>, preference_id: Option, dismissed_version: Option, dialog_open: bool, @@ -241,6 +241,7 @@ impl Workspace { let label = if checking { "检查中…" } else { "检查更新" }; if stitch_ui::action_button(ui, label, ButtonRole::Quiet, !checking && status != "downloading").clicked() { self.client_update_ui.requested = Some("check"); + ui.ctx().request_repaint(); } if capsule(state).is_some() { let label = if status == "ready" { "重启更新" } else { "查看更新" }; @@ -836,4 +837,68 @@ mod tests { harness.run_steps(6); harness.render().unwrap().save(directory.join(format!("{name}.png"))).unwrap(); } + + #[test] + fn project_library_settings_check_update_dispatches_without_agent_panel() { + struct LibraryState { + workspace: Workspace, + app: PhotocraftApp, + } + + let (mut w, requests) = workspace(); + w.library = true; + w.model_settings = true; + let state = LibraryState { + workspace: w, + app: PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()), + }; + let mut harness = Harness::builder() + .with_context_setup(crate::cjk_fonts::install_system_provider_for_tests) + .with_size(vec2(1280.0, 960.0)) + .build_ui_state(|ui, state: &mut LibraryState| { + if stitch_ui::ui_fonts_ready(ui) { + state.workspace.library_ui(&mut state.app, ui); + } + }, state); + PhotocraftApp::setup_context(&harness.ctx, crate::theme::ThemeKind::ProMedium); + harness.run_steps(4); + assert!(update_requests(&requests).is_empty()); + + let body = &harness.state().workspace.panel_geometry["settingsBody"]; + let center = egui::pos2( + (body[0].as_f64().unwrap() + body[2].as_f64().unwrap() * 0.5) as f32, + (body[1].as_f64().unwrap() + body[3].as_f64().unwrap() * 0.5) as f32, + ); + harness.event(egui::Event::PointerMoved(center)); + harness.event(egui::Event::MouseWheel { + source: egui::MouseWheelSource::Unknown, + phase: egui::TouchPhase::Move, + unit: egui::MouseWheelUnit::Point, + delta: vec2(0.0, -600.0), + modifiers: egui::Modifiers::NONE, + }); + harness.run_steps(4); + + harness.get_by_label("检查更新").click(); + harness.run_steps(2); + let sent = update_requests(&requests); + assert_eq!(sent.len(), 1, "one check request from project library: {sent:?}"); + assert_eq!(sent[0]["op"], "check"); + assert!(harness.state().workspace.client_update_ui.requested.is_none()); + } + + #[test] + fn workspace_tick_flushes_pending_client_update_request() { + let (mut w, requests) = workspace(); + w.library = true; + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + w.client_update_ui.requested = Some("check"); + let ctx = egui::Context::default(); + let output = ctx.run_ui(egui::RawInput::default(), |ui| w.tick(&mut app, ui.ctx())); + output.drop_without_applying_deltas(); + assert!(w.client_update_ui.requested.is_none()); + let sent = update_requests(&requests); + assert_eq!(sent.len(), 1, "Workspace::tick should flush requested check: {sent:?}"); + assert_eq!(sent[0]["op"], "check"); + } } diff --git a/apps/detail-photocraft/crates/ui-egui/src/jiansun/project_browser.rs b/apps/detail-photocraft/crates/ui-egui/src/jiansun/project_browser.rs index f7ad546b..5b715c9f 100644 --- a/apps/detail-photocraft/crates/ui-egui/src/jiansun/project_browser.rs +++ b/apps/detail-photocraft/crates/ui-egui/src/jiansun/project_browser.rs @@ -320,12 +320,14 @@ impl Workspace { self.model_settings = !self.model_settings; if self.model_settings { self.prompt_library.close(); + self.maybe_check_update_on_settings_open(); } else { self.api_key.clear(); self.key_settings = false; } } self.settings_popup(ui, &settings_btn); + self.flush_client_update_request(app); if stitch_ui::icon_button(ui, "rotate-cw", 30.0, false, "刷新项目").clicked() { self.cover_errors.clear(); self.send("projects", json!({}));