Fix: Windows Auto-Installer (WIP)

This commit is contained in:
Youwes09
2026-04-23 03:58:20 -05:00
parent 6634ad56d2
commit bd2fd7a6d7
2 changed files with 23 additions and 6 deletions
+9 -4
View File
@@ -660,7 +660,8 @@ async fn download_and_install_update(app: tauri::AppHandle, tag: String) -> Resu
#[derive(serde::Deserialize)] #[derive(serde::Deserialize)]
struct Release { assets: Vec<Asset> } struct Release { assets: Vec<Asset> }
let release: Release = resp.json().await.map_err(|e| e.to_string())?; let body = resp.text().await.map_err(|e| e.to_string())?;
let release: Release = serde_json::from_str(&body).map_err(|e| e.to_string())?;
let asset = release.assets let asset = release.assets
.into_iter() .into_iter()
@@ -682,12 +683,16 @@ async fn download_and_install_update(app: tauri::AppHandle, tag: String) -> Resu
} }
drop(file); drop(file);
// Launch the NSIS installer — it handles closing/replacing the running app. // Launch the NSIS installer silently without a visible cmd window.
std::process::Command::new("cmd") use std::os::windows::process::CommandExt;
.args(["/C", "start", "", &tmp_path.to_string_lossy()]) const CREATE_NO_WINDOW: u32 = 0x08000000;
std::process::Command::new(&tmp_path)
.creation_flags(CREATE_NO_WINDOW)
.spawn() .spawn()
.map_err(|e| e.to_string())?; .map_err(|e| e.to_string())?;
let _ = app.emit("update-launching", ());
Ok(()) Ok(())
} }
} }
@@ -5,7 +5,7 @@
import { open as openUrl } from "@tauri-apps/plugin-shell"; import { open as openUrl } from "@tauri-apps/plugin-shell";
interface ReleaseInfo { tag_name: string; name: string; body: string; published_at: string; html_url: string; } interface ReleaseInfo { tag_name: string; name: string; body: string; published_at: string; html_url: string; }
type UpdatePhase = "idle" | "downloading" | "ready" | "error"; type UpdatePhase = "idle" | "downloading" | "launching" | "ready" | "error";
const IS_WINDOWS = navigator.userAgent.includes("Windows"); const IS_WINDOWS = navigator.userAgent.includes("Windows");
let appVersion = $state("…"); let appVersion = $state("…");
@@ -33,6 +33,13 @@
return () => unlisten?.(); return () => unlisten?.();
}); });
$effect(() => {
let unlisten: (() => void) | undefined;
listen("update-launching", () => { updatePhase = "launching"; })
.then(fn => { unlisten = fn; });
return () => unlisten?.();
});
async function loadReleases() { async function loadReleases() {
releasesLoading = true; releasesError = null; releasesLoading = true; releasesError = null;
try { try {
@@ -81,7 +88,7 @@
try { try {
if (IS_WINDOWS) { if (IS_WINDOWS) {
try { await invoke("kill_server"); } catch {} try { await invoke("kill_server"); } catch {}
await invoke("download_and_install_update"); await invoke("download_and_install_update", { tag: release.tag_name });
updatePhase = "ready"; updatePhase = "ready";
} else { } else {
await openUrl(release.html_url); await openUrl(release.html_url);
@@ -134,6 +141,11 @@
</div> </div>
</div> </div>
{/if} {/if}
{#if updatePhase === "launching"}
<div class="s-update-ready">
<span class="s-update-ready-label">Launching installer for {targetTag}</span>
</div>
{/if}
{#if updatePhase === "ready"} {#if updatePhase === "ready"}
<div class="s-update-ready"> <div class="s-update-ready">
<span class="s-update-ready-label">{targetTag} downloaded — restart to finish installing.</span> <span class="s-update-ready-label">{targetTag} downloaded — restart to finish installing.</span>