UPDATE: Add self update
This commit is contained in:
4
frontend/src/helper/index.ts
Normal file
4
frontend/src/helper/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from "./server"
|
||||
export * from "./proxy"
|
||||
export * from "./launcher"
|
||||
export * from "./sleep"
|
||||
38
frontend/src/helper/launcher.ts
Normal file
38
frontend/src/helper/launcher.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import useLauncherStore from "@/stores/launcherStore";
|
||||
import { AppService, GitService } from "@bindings/firefly-launcher/internal";
|
||||
import { toast } from "react-toastify";
|
||||
import { sleep } from "./sleep";
|
||||
|
||||
export async function CheckUpdateLauncher() : Promise<{isUpdate: boolean, version: string}> {
|
||||
let isUpdateLauncher = false
|
||||
let version = ""
|
||||
const [launcherCurrentOk, launcherCurrentVersion] = await AppService.GetCurrentLauncherVersion()
|
||||
if (!launcherCurrentOk) {
|
||||
toast.error("Launcher error: cannot get current version")
|
||||
} else {
|
||||
const [launcherNewOk, launcherNewVersion, launcherNewError] = await GitService.GetLatestLauncherVersion()
|
||||
version = launcherCurrentVersion
|
||||
if (launcherNewOk && launcherNewVersion && launcherNewVersion !== launcherCurrentVersion) {
|
||||
isUpdateLauncher = true
|
||||
version = launcherNewVersion
|
||||
} else if (!launcherNewOk) {
|
||||
toast.error("Launcher error: " + launcherNewError)
|
||||
}
|
||||
}
|
||||
return { isUpdate: isUpdateLauncher, version: version }
|
||||
}
|
||||
|
||||
export async function UpdateLauncher(launcherVersion: string) : Promise<void> {
|
||||
const {setDownloadType } = useLauncherStore.getState()
|
||||
setDownloadType("update:launcher:downloading")
|
||||
const [ok, error] = await GitService.UpdateLauncherProgress(launcherVersion)
|
||||
if (ok) {
|
||||
setDownloadType("update:launcher:success")
|
||||
|
||||
} else {
|
||||
toast.error(error)
|
||||
setDownloadType("update:launcher:failed")
|
||||
}
|
||||
AppService.CloseAppAfterTimeout(5)
|
||||
await sleep(5000)
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
35
frontend/src/helper/server.ts
Normal file
35
frontend/src/helper/server.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 CheckUpdateServer(serverPath: string, serverVersion: string) : Promise<{isUpdate: boolean, version: string}> {
|
||||
let isUpdateServer = false
|
||||
let version = ""
|
||||
const [serverOk, serverNewVersion, serverError] = await GitService.GetLatestServerVersion()
|
||||
const serverExists = await FSService.FileExists(serverPath)
|
||||
if (serverOk && serverNewVersion && serverNewVersion !== serverVersion || !serverExists) {
|
||||
isUpdateServer = true
|
||||
version = serverNewVersion
|
||||
} else if (!serverOk) {
|
||||
toast.error("Server error: " + serverError)
|
||||
}
|
||||
return { isUpdate: isUpdateServer, version: version }
|
||||
}
|
||||
|
||||
export async function UpdateServer(serverVersion: string) : Promise<void> {
|
||||
const {setDownloadType } = useLauncherStore.getState()
|
||||
const {setServerPath, setServerVersion} = useSettingStore.getState()
|
||||
setDownloadType("Downloading server...")
|
||||
const [ok, error] = await GitService.DownloadServerProgress(serverVersion)
|
||||
if (ok) {
|
||||
setDownloadType("Unzipping server...")
|
||||
GitService.UnzipServer()
|
||||
setDownloadType("Download server successfully")
|
||||
setServerVersion(serverVersion)
|
||||
setServerPath("./server/firefly-go_win.exe")
|
||||
} else {
|
||||
toast.error(error)
|
||||
setDownloadType("Download server failed")
|
||||
}
|
||||
}
|
||||
3
frontend/src/helper/sleep.ts
Normal file
3
frontend/src/helper/sleep.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function sleep(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
Reference in New Issue
Block a user