UPDATE: Add self update
This commit is contained in:
35
frontend/src/helper/proxy.ts
Normal file
35
frontend/src/helper/proxy.ts
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user