refactor 5
This commit is contained in:
@@ -74,6 +74,7 @@ pub struct TaskEventPayload {
|
|||||||
pub progress: f32,
|
pub progress: f32,
|
||||||
pub target_version: Option<String>,
|
pub target_version: Option<String>,
|
||||||
pub message: Option<String>,
|
pub message: Option<String>,
|
||||||
|
pub software_info: Option<Software>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ use winreg::enums::*;
|
|||||||
use winreg::RegKey;
|
use winreg::RegKey;
|
||||||
|
|
||||||
use crate::domain::models::{InstallProgress, InstallTask, TaskEventPayload};
|
use crate::domain::models::{InstallProgress, InstallTask, TaskEventPayload};
|
||||||
|
use crate::providers::winget_client;
|
||||||
use crate::services::essentials_service;
|
use crate::services::essentials_service;
|
||||||
use crate::services::log_service::emit_log;
|
use crate::services::log_service::emit_log;
|
||||||
use crate::winget::PostInstallStep;
|
use crate::winget::{PostInstallStep, Software};
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub install_tx: mpsc::Sender<InstallTask>,
|
pub install_tx: mpsc::Sender<InstallTask>,
|
||||||
@@ -47,6 +48,7 @@ pub fn create_install_state(handle: AppHandle) -> AppState {
|
|||||||
0.0,
|
0.0,
|
||||||
task_version.clone(),
|
task_version.clone(),
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut args = vec!["install".to_string()];
|
let mut args = vec!["install".to_string()];
|
||||||
@@ -66,6 +68,7 @@ pub fn create_install_state(handle: AppHandle) -> AppState {
|
|||||||
0.0,
|
0.0,
|
||||||
task_version.clone(),
|
task_version.clone(),
|
||||||
Some("Downloading remote manifest".to_string()),
|
Some("Downloading remote manifest".to_string()),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
emit_log(
|
emit_log(
|
||||||
&runtime_handle,
|
&runtime_handle,
|
||||||
@@ -116,6 +119,7 @@ pub fn create_install_state(handle: AppHandle) -> AppState {
|
|||||||
0.0,
|
0.0,
|
||||||
task_version.clone(),
|
task_version.clone(),
|
||||||
Some("Failed to download or save manifest".to_string()),
|
Some("Failed to download or save manifest".to_string()),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -162,6 +166,7 @@ pub fn create_install_state(handle: AppHandle) -> AppState {
|
|||||||
0.0,
|
0.0,
|
||||||
task_version.clone(),
|
task_version.clone(),
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
let child = Command::new("winget")
|
let child = Command::new("winget")
|
||||||
@@ -280,6 +285,7 @@ pub fn create_install_state(handle: AppHandle) -> AppState {
|
|||||||
1.0,
|
1.0,
|
||||||
task_version.clone(),
|
task_version.clone(),
|
||||||
Some("Starting post-installation configuration".to_string()),
|
Some("Starting post-installation configuration".to_string()),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
emit_log(
|
emit_log(
|
||||||
&runtime_handle,
|
&runtime_handle,
|
||||||
@@ -316,11 +322,18 @@ pub fn create_install_state(handle: AppHandle) -> AppState {
|
|||||||
0.0,
|
0.0,
|
||||||
task_version.clone(),
|
task_version.clone(),
|
||||||
Some(e.to_string()),
|
Some(e.to_string()),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
"error"
|
"error"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let resolved_software_info = if status_result == "success" {
|
||||||
|
winget_client::get_package_by_id(&runtime_handle, &task_id)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
emit_task_event(
|
emit_task_event(
|
||||||
&runtime_handle,
|
&runtime_handle,
|
||||||
&log_id,
|
&log_id,
|
||||||
@@ -331,6 +344,7 @@ pub fn create_install_state(handle: AppHandle) -> AppState {
|
|||||||
1.0,
|
1.0,
|
||||||
task_version.clone(),
|
task_version.clone(),
|
||||||
Some(format!("Execution finished: {}", status_result)),
|
Some(format!("Execution finished: {}", status_result)),
|
||||||
|
resolved_software_info,
|
||||||
);
|
);
|
||||||
emit_log(
|
emit_log(
|
||||||
&runtime_handle,
|
&runtime_handle,
|
||||||
@@ -369,6 +383,7 @@ pub async fn install_software(
|
|||||||
0.0,
|
0.0,
|
||||||
task.version.clone(),
|
task.version.clone(),
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
state.install_tx.send(task).await.map_err(|e| e.to_string())
|
state.install_tx.send(task).await.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
@@ -415,6 +430,7 @@ fn spawn_install_stream_reader<R: Read + Send + 'static>(
|
|||||||
progress: p_val / 100.0,
|
progress: p_val / 100.0,
|
||||||
target_version: None,
|
target_version: None,
|
||||||
message: None,
|
message: None,
|
||||||
|
software_info: None,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
is_progress = true;
|
is_progress = true;
|
||||||
@@ -442,6 +458,7 @@ fn spawn_install_stream_reader<R: Read + Send + 'static>(
|
|||||||
progress: (current / total).min(1.0),
|
progress: (current / total).min(1.0),
|
||||||
target_version: None,
|
target_version: None,
|
||||||
message: None,
|
message: None,
|
||||||
|
software_info: None,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
is_progress = true;
|
is_progress = true;
|
||||||
@@ -469,6 +486,7 @@ fn emit_task_event(
|
|||||||
progress: f32,
|
progress: f32,
|
||||||
target_version: Option<String>,
|
target_version: Option<String>,
|
||||||
message: Option<String>,
|
message: Option<String>,
|
||||||
|
software_info: Option<Software>,
|
||||||
) {
|
) {
|
||||||
let _ = handle.emit(
|
let _ = handle.emit(
|
||||||
"task-event",
|
"task-event",
|
||||||
@@ -481,6 +499,7 @@ fn emit_task_event(
|
|||||||
progress,
|
progress,
|
||||||
target_version: target_version.clone(),
|
target_version: target_version.clone(),
|
||||||
message,
|
message,
|
||||||
|
software_info,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -123,18 +123,27 @@ export const useTaskRuntimeStore = defineStore('task-runtime', {
|
|||||||
|
|
||||||
if (payload.status === 'completed' || payload.status === 'failed') {
|
if (payload.status === 'completed' || payload.status === 'failed') {
|
||||||
if (payload.status === 'completed') {
|
if (payload.status === 'completed') {
|
||||||
try {
|
const latestInfo = payload.software_info
|
||||||
const latestInfo = await invoke('get_software_info', { id: payload.software_id }) as Record<string, unknown> | null
|
if (latestInfo) {
|
||||||
if (latestInfo) {
|
const installedIndex = catalog.allSoftware.findIndex(s => s.id.toLowerCase() === payload.software_id.toLowerCase())
|
||||||
const index = catalog.allSoftware.findIndex(s => s.id.toLowerCase() === payload.software_id.toLowerCase())
|
if (installedIndex !== -1) {
|
||||||
if (index !== -1) {
|
catalog.allSoftware[installedIndex] = { ...catalog.allSoftware[installedIndex], ...latestInfo }
|
||||||
catalog.allSoftware[index] = { ...catalog.allSoftware[index], ...latestInfo }
|
} else {
|
||||||
} else {
|
catalog.allSoftware.push(latestInfo)
|
||||||
catalog.allSoftware.push(latestInfo as never)
|
}
|
||||||
|
|
||||||
|
const essentialIndex = catalog.essentials.findIndex(s => s.id.toLowerCase() === payload.software_id.toLowerCase())
|
||||||
|
if (essentialIndex !== -1) {
|
||||||
|
catalog.essentials[essentialIndex] = {
|
||||||
|
...catalog.essentials[essentialIndex],
|
||||||
|
version: latestInfo.version,
|
||||||
|
available_version: undefined,
|
||||||
|
action_label: '已安装',
|
||||||
|
target_version: undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
console.error('Partial refresh failed:', err)
|
catalog.updates = catalog.updates.filter(item => item.id.toLowerCase() !== payload.software_id.toLowerCase())
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectedEssentialIds = this.selectedEssentialIds.filter(item => item !== payload.software_id)
|
this.selectedEssentialIds = this.selectedEssentialIds.filter(item => item !== payload.software_id)
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ export interface TaskEventPayload {
|
|||||||
progress: number
|
progress: number
|
||||||
target_version?: string | null
|
target_version?: string | null
|
||||||
message?: string | null
|
message?: string | null
|
||||||
|
software_info?: SoftwareListItem | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppSettings {
|
export interface AppSettings {
|
||||||
|
|||||||
Reference in New Issue
Block a user