feat(agent): add reinstall JRE button in Driver Manager
This commit is contained in:
parent
ff80e767d6
commit
bc687cee7f
|
|
@ -93,6 +93,27 @@ pub async fn check_jre_installed(state: State<'_, Arc<AppState>>) -> Result<bool
|
|||
Ok(state.agent_manager.is_jre_installed())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn reinstall_jre(state: State<'_, Arc<AppState>>) -> 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<AgentRegistry, String> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(10))
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ interface AgentDriverInfo {
|
|||
const drivers = ref<AgentDriverInfo[]>([]);
|
||||
const jreInstalled = ref(false);
|
||||
const installing = ref<string | null>(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 {
|
|||
<div class="space-y-4 p-4">
|
||||
<h3 class="text-lg font-medium">驱动管理</h3>
|
||||
|
||||
<div class="text-sm text-muted-foreground">
|
||||
JRE: {{ jreInstalled ? "✓ 已安装" : "未安装" }}
|
||||
<span v-if="!jreInstalled" class="ml-2 text-xs">(首次安装驱动时自动下载)</span>
|
||||
<div class="flex items-center gap-3 text-sm text-muted-foreground">
|
||||
<span>JRE: {{ jreInstalled ? "✓ 已安装" : "未安装" }}</span>
|
||||
<span v-if="!jreInstalled" class="text-xs">(首次安装驱动时自动下载)</span>
|
||||
<Button
|
||||
v-if="jreInstalled"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
:disabled="reinstallingJre || installing !== null"
|
||||
@click="reinstallJre"
|
||||
>
|
||||
{{ reinstallingJre ? "重装中..." : "重新安装 JRE" }}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
|
|
|
|||
Loading…
Reference in New Issue