fix(xiaoyi): 修复项目列表页检查更新无响应与缩短自动检查间隔 (1.2612.114)
This commit is contained in:
parent
4a9ed3031c
commit
09766a4377
@ -1 +1 @@
|
||||
1.2612.113
|
||||
1.2612.114
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Id>,
|
||||
dismissed_version: Option<String>,
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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!({}));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user