UPDATE: Add self update

This commit is contained in:
2025-07-26 20:59:35 +07:00
parent 95f8ed357d
commit 461dfd93ba
28 changed files with 597 additions and 173 deletions

View File

@@ -0,0 +1,35 @@
import useLauncherStore from "@/stores/launcherStore";
import useSettingStore from "@/stores/settingStore";
import { FSService, GitService } from "@bindings/firefly-launcher/internal";
import { toast } from "react-toastify";
export async function CheckUpdateProxy(proxyPath: string, proxyVersion: string) : Promise<{isUpdate: boolean, version: string}> {
let isUpdateProxy = false
let version = ""
const [proxyOk, proxyNewVersion, proxyError] = await GitService.GetLatestProxyVersion()
const proxyExists = await FSService.FileExists(proxyPath)
if (proxyOk && proxyNewVersion && proxyNewVersion !== proxyVersion || !proxyExists) {
isUpdateProxy = true
version = proxyNewVersion
} else if (!proxyOk) {
toast.error("Proxy error: " + proxyError)
}
return { isUpdate: isUpdateProxy, version: version }
}
export async function UpdateProxy(proxyVersion: string) : Promise<void> {
const {setDownloadType } = useLauncherStore.getState()
const {setProxyPath, setProxyVersion} = useSettingStore.getState()
setDownloadType("Downloading proxy...")
const [ok, error] = await GitService.DownloadProxyProgress(proxyVersion)
if (ok) {
setDownloadType("Unzipping proxy...")
GitService.UnzipProxy()
setDownloadType("Download proxy successfully")
setProxyVersion(proxyVersion)
setProxyPath("./proxy/FireflyProxy.exe")
} else {
toast.error(error)
setDownloadType("Download proxy failed")
}
}