fix: make hosted downloads controllable and failures diagnosable
Sync source to CNB / Sync Git ref (push) Skipped
Axolotl desktop CI / guardrails (push) Canceled after 0s
Axolotl desktop CI / desktop (macos-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (ubuntu-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (windows-latest) (push) Canceled after 0s
Axolotl desktop CI / website (push) Canceled after 0s
Repository checks / typos (push) Canceled after 0s
Repository checks / tombi (push) Canceled after 0s
Rust checks / shear (push) Canceled after 0s

This commit is contained in:
Disy committed 2026-10-20 21:25:19 +08:00
1 parent 1838afce56
commit bf95d715a4
17 files changed
+848 -72

No files matched your search

+79 -2
View File
@@ -232,8 +232,24 @@ pub fn fail_hosted_loading(key: &LoadingBarId, error: &str) {
&& let Some(mut bar) = state.loading_bars.get_mut(&key.0)
{
match &mut bar.bar_type {
LoadingBarType::HostedPackSync { error: failure, .. }
| LoadingBarType::HostedModDownload { error: failure, .. } => {
LoadingBarType::HostedPackSync {
error: failure,
state,
can_pause,
can_cancel,
..
} => {
use crate::api::pack::hosted::HostedTaskState;
*state = if *state == HostedTaskState::Canceling {
HostedTaskState::Canceled
} else {
HostedTaskState::Failed
};
*can_pause = false;
*can_cancel = false;
*failure = Some(error.to_owned());
}
LoadingBarType::HostedModDownload { error: failure, .. } => {
*failure = Some(error.to_owned())
}
_ => {}
@@ -241,6 +257,67 @@ pub fn fail_hosted_loading(key: &LoadingBarId, error: &str) {
}
}
/// Update the authoritative snapshot and notify observers even while all
/// transfer futures are paused and no byte-progress event can be produced.
pub fn set_hosted_loading_state(
instance_id: &str,
next: crate::api::pack::hosted::HostedTaskState,
) {
use crate::api::pack::hosted::HostedTaskState;
let Ok(event_state) = crate::EventState::get() else {
return;
};
for mut bar in event_state.loading_bars.iter_mut() {
let LoadingBarType::HostedPackSync {
instance_id: id,
state,
can_pause,
can_cancel,
..
} = &mut bar.bar_type
else {
continue;
};
if id != instance_id {
continue;
}
*state = next;
let controllable =
matches!(next, HostedTaskState::Running | HostedTaskState::Paused);
*can_pause = controllable;
*can_cancel = controllable;
match next {
HostedTaskState::Paused => {
bar.message = "已暂停,点击继续以恢复下载".into()
}
HostedTaskState::Canceling => {
bar.message = "正在停止整合包下载".into()
}
HostedTaskState::Running => {
bar.message = "正在继续整合包下载".into()
}
_ => {}
}
#[cfg(feature = "tauri")]
{
let _ = event_state.app.emit(
"loading",
LoadingPayload {
fraction: Some(if bar.total > 0.0 {
bar.current / bar.total
} else {
0.0
}),
message: bar.message.clone(),
event: bar.bar_type.clone(),
loader_uuid: bar.loading_bar_uuid,
total: Some(bar.total),
},
);
}
}
}
// emit_warning(message)
pub async fn emit_warning(message: &str) -> crate::Result<()> {
#[cfg(feature = "tauri")]
+6
View File
@@ -142,6 +142,12 @@ pub enum LoadingBarType {
instance_id: String,
instance_name: String,
error: Option<String>,
#[serde(default)]
state: crate::api::pack::hosted::HostedTaskState,
#[serde(default)]
can_pause: bool,
#[serde(default)]
can_cancel: bool,
},
HostedModDownload {
instance_id: String,