From bc687cee7fc7c82bf8ead44ac30d8a780f072f24 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Wed, 13 May 2026 05:05:00 +0800 Subject: [PATCH] feat(agent): add reinstall JRE button in Driver Manager --- src-tauri/src/commands/agents.rs | 21 +++++++++++++++++++ src-tauri/src/lib.rs | 1 + src/components/config/DriverManager.vue | 28 ++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/commands/agents.rs b/src-tauri/src/commands/agents.rs index 8832ad18a..cb76dc83f 100644 --- a/src-tauri/src/commands/agents.rs +++ b/src-tauri/src/commands/agents.rs @@ -93,6 +93,27 @@ pub async fn check_jre_installed(state: State<'_, Arc>) -> Result>) -> Result<(), String> { + let am = &state.agent_manager; + let jre_dir = am.base_dir().join("jre"); + if jre_dir.exists() { + std::fs::remove_dir_all(&jre_dir).map_err(|e| format!("Failed to remove old JRE: {e}"))?; + } + let registry = fetch_registry().await?; + let platform = AgentManager::current_platform(); + let jre_info = + registry.jre.platforms.get(platform).ok_or_else(|| format!("No JRE available for platform: {platform}"))?; + let jre_archive = am.base_dir().join("jre-download.tar.gz"); + download_with_proxy(&jre_info.url, &jre_archive).await?; + extract_archive(&jre_archive, &jre_dir)?; + std::fs::remove_file(&jre_archive).ok(); + let mut local_state = am.load_state(); + local_state.jre_version = Some(registry.jre.version.clone()); + am.save_state(&local_state)?; + Ok(()) +} + async fn fetch_registry() -> Result { let client = reqwest::Client::builder() .timeout(std::time::Duration::from_secs(10)) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a431131d4..45a306493 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -147,6 +147,7 @@ pub fn run() { commands::agents::install_agent, commands::agents::uninstall_agent, commands::agents::check_jre_installed, + commands::agents::reinstall_jre, ]) .build(tauri::generate_context!()) .expect("error while building tauri application") diff --git a/src/components/config/DriverManager.vue b/src/components/config/DriverManager.vue index 30c6dd303..66e22de60 100644 --- a/src/components/config/DriverManager.vue +++ b/src/components/config/DriverManager.vue @@ -16,6 +16,7 @@ interface AgentDriverInfo { const drivers = ref([]); const jreInstalled = ref(false); const installing = ref(null); +const reinstallingJre = ref(false); onMounted(async () => { await refresh(); @@ -47,6 +48,18 @@ async function uninstallDriver(dbType: string) { } } +async function reinstallJre() { + reinstallingJre.value = true; + try { + await invoke("reinstall_jre"); + await refresh(); + } catch (e: any) { + alert(e); + } finally { + reinstallingJre.value = false; + } +} + function formatSize(bytes: number): string { return `${(bytes / 1024 / 1024).toFixed(1)} MB`; } @@ -56,9 +69,18 @@ function formatSize(bytes: number): string {

驱动管理

-
- JRE: {{ jreInstalled ? "✓ 已安装" : "未安装" }} - (首次安装驱动时自动下载) +
+ JRE: {{ jreInstalled ? "✓ 已安装" : "未安装" }} + (首次安装驱动时自动下载) +