FIX: fix bug about checking version

This commit is contained in:
2025-07-26 22:07:28 +07:00
parent 461dfd93ba
commit fb1cd82434
5 changed files with 107 additions and 96 deletions

View File

@@ -3,25 +3,24 @@ 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) {
export async function CheckUpdateLauncher(): Promise<{ isUpdate: boolean; isExists: boolean; version: string }> {
const [currentOk, currentVersion] = await AppService.GetCurrentLauncherVersion()
if (!currentOk) {
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: false, isExists: true, version: "" }
}
return { isUpdate: isUpdateLauncher, version: version }
const [latestOk, latestVersion, latestError] = await GitService.GetLatestLauncherVersion()
if (!latestOk) {
toast.error("Launcher error: " + latestError)
return { isUpdate: false, isExists: true, version: currentVersion }
}
const isUpdate = latestVersion !== currentVersion
return { isUpdate, isExists: true, version: latestVersion }
}
export async function UpdateLauncher(launcherVersion: string) : Promise<void> {
const {setDownloadType } = useLauncherStore.getState()
setDownloadType("update:launcher:downloading")

View File

@@ -3,18 +3,17 @@ 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)
export async function CheckUpdateProxy(proxyPath: string, proxyVersion: string) : Promise<{isUpdate: boolean, isExists: boolean, version: string}> {
const [ok, latestVersion, error] = await GitService.GetLatestProxyVersion()
const isExists = await FSService.FileExists(proxyPath)
if (!ok) {
toast.error("Proxy error: " + error)
return { isUpdate: false, isExists, version: "" }
}
return { isUpdate: isUpdateProxy, version: version }
const isUpdate = latestVersion !== proxyVersion
return { isUpdate, isExists, version: latestVersion }
}
export async function UpdateProxy(proxyVersion: string) : Promise<void> {

View File

@@ -3,20 +3,23 @@ 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)
export async function CheckUpdateServer(
serverPath: string,
serverVersion: string
): Promise<{ isUpdate: boolean; isExists: boolean; version: string }> {
const [ok, latestVersion, error] = await GitService.GetLatestServerVersion()
const isExists = await FSService.FileExists(serverPath)
if (!ok) {
toast.error("Server error: " + error)
return { isUpdate: false, isExists, version: "" }
}
return { isUpdate: isUpdateServer, version: version }
const isUpdate = latestVersion !== serverVersion
return { isUpdate, isExists, version: latestVersion }
}
export async function UpdateServer(serverVersion: string) : Promise<void> {
const {setDownloadType } = useLauncherStore.getState()
const {setServerPath, setServerVersion} = useSettingStore.getState()