FIX: fix bug about checking version
This commit is contained in:
@@ -3,25 +3,24 @@ import { AppService, GitService } from "@bindings/firefly-launcher/internal";
|
|||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
import { sleep } from "./sleep";
|
import { sleep } from "./sleep";
|
||||||
|
|
||||||
export async function CheckUpdateLauncher() : Promise<{isUpdate: boolean, version: string}> {
|
export async function CheckUpdateLauncher(): Promise<{ isUpdate: boolean; isExists: boolean; version: string }> {
|
||||||
let isUpdateLauncher = false
|
const [currentOk, currentVersion] = await AppService.GetCurrentLauncherVersion()
|
||||||
let version = ""
|
if (!currentOk) {
|
||||||
const [launcherCurrentOk, launcherCurrentVersion] = await AppService.GetCurrentLauncherVersion()
|
|
||||||
if (!launcherCurrentOk) {
|
|
||||||
toast.error("Launcher error: cannot get current version")
|
toast.error("Launcher error: cannot get current version")
|
||||||
} else {
|
return { isUpdate: false, isExists: true, version: "" }
|
||||||
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 }
|
|
||||||
|
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> {
|
export async function UpdateLauncher(launcherVersion: string) : Promise<void> {
|
||||||
const {setDownloadType } = useLauncherStore.getState()
|
const {setDownloadType } = useLauncherStore.getState()
|
||||||
setDownloadType("update:launcher:downloading")
|
setDownloadType("update:launcher:downloading")
|
||||||
|
|||||||
@@ -3,18 +3,17 @@ import useSettingStore from "@/stores/settingStore";
|
|||||||
import { FSService, GitService } from "@bindings/firefly-launcher/internal";
|
import { FSService, GitService } from "@bindings/firefly-launcher/internal";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
export async function CheckUpdateProxy(proxyPath: string, proxyVersion: string) : Promise<{isUpdate: boolean, version: string}> {
|
export async function CheckUpdateProxy(proxyPath: string, proxyVersion: string) : Promise<{isUpdate: boolean, isExists: boolean, version: string}> {
|
||||||
let isUpdateProxy = false
|
const [ok, latestVersion, error] = await GitService.GetLatestProxyVersion()
|
||||||
let version = ""
|
const isExists = await FSService.FileExists(proxyPath)
|
||||||
const [proxyOk, proxyNewVersion, proxyError] = await GitService.GetLatestProxyVersion()
|
|
||||||
const proxyExists = await FSService.FileExists(proxyPath)
|
if (!ok) {
|
||||||
if (proxyOk && proxyNewVersion && proxyNewVersion !== proxyVersion || !proxyExists) {
|
toast.error("Proxy error: " + error)
|
||||||
isUpdateProxy = true
|
return { isUpdate: false, isExists, version: "" }
|
||||||
version = proxyNewVersion
|
|
||||||
} else if (!proxyOk) {
|
|
||||||
toast.error("Proxy error: " + proxyError)
|
|
||||||
}
|
}
|
||||||
return { isUpdate: isUpdateProxy, version: version }
|
|
||||||
|
const isUpdate = latestVersion !== proxyVersion
|
||||||
|
return { isUpdate, isExists, version: latestVersion }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function UpdateProxy(proxyVersion: string) : Promise<void> {
|
export async function UpdateProxy(proxyVersion: string) : Promise<void> {
|
||||||
|
|||||||
@@ -3,20 +3,23 @@ import useSettingStore from '@/stores/settingStore';
|
|||||||
import { FSService, GitService } from '@bindings/firefly-launcher/internal';
|
import { FSService, GitService } from '@bindings/firefly-launcher/internal';
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
|
|
||||||
export async function CheckUpdateServer(serverPath: string, serverVersion: string) : Promise<{isUpdate: boolean, version: string}> {
|
export async function CheckUpdateServer(
|
||||||
let isUpdateServer = false
|
serverPath: string,
|
||||||
let version = ""
|
serverVersion: string
|
||||||
const [serverOk, serverNewVersion, serverError] = await GitService.GetLatestServerVersion()
|
): Promise<{ isUpdate: boolean; isExists: boolean; version: string }> {
|
||||||
const serverExists = await FSService.FileExists(serverPath)
|
const [ok, latestVersion, error] = await GitService.GetLatestServerVersion()
|
||||||
if (serverOk && serverNewVersion && serverNewVersion !== serverVersion || !serverExists) {
|
const isExists = await FSService.FileExists(serverPath)
|
||||||
isUpdateServer = true
|
|
||||||
version = serverNewVersion
|
if (!ok) {
|
||||||
} else if (!serverOk) {
|
toast.error("Server error: " + error)
|
||||||
toast.error("Server error: " + serverError)
|
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> {
|
export async function UpdateServer(serverVersion: string) : Promise<void> {
|
||||||
const {setDownloadType } = useLauncherStore.getState()
|
const {setDownloadType } = useLauncherStore.getState()
|
||||||
const {setServerPath, setServerVersion} = useSettingStore.getState()
|
const {setServerPath, setServerVersion} = useSettingStore.getState()
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export default function LauncherPage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const check = async () => {
|
const check = async () => {
|
||||||
if (!serverPath || !proxyPath || !serverVersion || !proxyVersion) {
|
if (!serverVersion || !proxyVersion) {
|
||||||
setServerReady(false)
|
setServerReady(false)
|
||||||
setProxyReady(false)
|
setProxyReady(false)
|
||||||
return
|
return
|
||||||
@@ -74,17 +74,11 @@ export default function LauncherPage() {
|
|||||||
const checkStartUp = async (): Promise<void> => {
|
const checkStartUp = async (): Promise<void> => {
|
||||||
const [_, version] = await AppService.GetCurrentLauncherVersion()
|
const [_, version] = await AppService.GetCurrentLauncherVersion()
|
||||||
setLauncherVersion(version)
|
setLauncherVersion(version)
|
||||||
let isExists = false
|
|
||||||
if (serverPath && proxyPath && serverVersion && proxyVersion) {
|
|
||||||
isExists = true
|
|
||||||
setServerReady(true)
|
|
||||||
setProxyReady(true)
|
|
||||||
}
|
|
||||||
const launcherData = await CheckUpdateLauncher()
|
const launcherData = await CheckUpdateLauncher()
|
||||||
if (launcherData.isUpdate) {
|
if (launcherData.isUpdate) {
|
||||||
setUpdateData({
|
setUpdateData({
|
||||||
server: { isUpdate: false, version: "" },
|
server: { isUpdate: false, isExists: false, version: "" },
|
||||||
proxy: { isUpdate: false, version: "" },
|
proxy: { isUpdate: false, isExists: false, version: "" },
|
||||||
launcher: launcherData
|
launcher: launcherData
|
||||||
})
|
})
|
||||||
setIsOpenSelfUpdateModal(true)
|
setIsOpenSelfUpdateModal(true)
|
||||||
@@ -92,29 +86,33 @@ export default function LauncherPage() {
|
|||||||
}
|
}
|
||||||
const serverData = await CheckUpdateServer(serverPath, serverVersion)
|
const serverData = await CheckUpdateServer(serverPath, serverVersion)
|
||||||
const proxyData = await CheckUpdateProxy(proxyPath, proxyVersion)
|
const proxyData = await CheckUpdateProxy(proxyPath, proxyVersion)
|
||||||
|
setUpdateData({
|
||||||
|
server: serverData,
|
||||||
|
proxy: proxyData,
|
||||||
|
launcher: launcherData
|
||||||
|
})
|
||||||
const exitGame = await FSService.FileExists(gamePath)
|
const exitGame = await FSService.FileExists(gamePath)
|
||||||
if (!exitGame) {
|
if (!exitGame) {
|
||||||
setGameRunning(false)
|
setGameRunning(false)
|
||||||
setGamePath("")
|
setGamePath("")
|
||||||
setGameDir("")
|
setGameDir("")
|
||||||
}
|
}
|
||||||
if (!serverData.isUpdate && !proxyData.isUpdate) {
|
|
||||||
setServerReady(true)
|
if (!serverData.isExists || !proxyData.isExists) {
|
||||||
setProxyReady(true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!isExists) {
|
|
||||||
setUpdateData({
|
|
||||||
server: serverData,
|
|
||||||
proxy: proxyData,
|
|
||||||
launcher: launcherData
|
|
||||||
})
|
|
||||||
setServerReady(false)
|
setServerReady(false)
|
||||||
setProxyReady(false)
|
setProxyReady(false)
|
||||||
setIsOpenDownloadDataModal(true)
|
setIsOpenDownloadDataModal(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setIsOpenUpdateDataModal(true)
|
|
||||||
|
if (serverData.isUpdate || proxyData.isUpdate) {
|
||||||
|
setServerReady(true)
|
||||||
|
setProxyReady(true)
|
||||||
|
setIsOpenUpdateDataModal(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setServerReady(true)
|
||||||
|
setProxyReady(true)
|
||||||
}
|
}
|
||||||
checkStartUp()
|
checkStartUp()
|
||||||
}, []);
|
}, []);
|
||||||
@@ -196,31 +194,30 @@ export default function LauncherPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlerUpdateServer = async () => {
|
|
||||||
|
const handlerUpdateData = async () => {
|
||||||
setIsDownloading(true)
|
setIsDownloading(true)
|
||||||
for (const [key, value] of Object.entries(updateData)) {
|
if (updateData.launcher.isUpdate) {
|
||||||
if (!value.isUpdate) {
|
await UpdateLauncher(updateData.launcher.version)
|
||||||
if (key === "server") {
|
setUpdateData({...updateData, launcher: { isUpdate: false, isExists: true, version: updateData.launcher.version }})
|
||||||
setServerReady(true)
|
setIsOpenSelfUpdateModal(true)
|
||||||
} else if (key === "proxy") {
|
|
||||||
setProxyReady(true)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (key === "server") {
|
|
||||||
await UpdateServer(value.version)
|
|
||||||
setServerReady(true)
|
|
||||||
} else if (key === "proxy") {
|
|
||||||
await UpdateProxy(value.version)
|
|
||||||
setProxyReady(true)
|
|
||||||
} else if (key === "launcher") {
|
|
||||||
await UpdateLauncher(value.version)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (updateData.server.isUpdate || !updateData.server.isExists) {
|
||||||
|
await UpdateServer(updateData.server.version)
|
||||||
|
setServerReady(true)
|
||||||
|
setUpdateData({...updateData, server: { isUpdate: false, isExists: true, version: updateData.server.version }})
|
||||||
|
}
|
||||||
|
if (updateData.proxy.isUpdate || !updateData.proxy.isExists) {
|
||||||
|
await UpdateProxy(updateData.proxy.version)
|
||||||
|
setProxyReady(true)
|
||||||
|
setUpdateData({...updateData, proxy: { isUpdate: false, isExists: true, version: updateData.proxy.version }})
|
||||||
|
}
|
||||||
|
|
||||||
setDownloadType("")
|
setDownloadType("")
|
||||||
setIsDownloading(false)
|
setIsDownloading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handle ESC key to close modal
|
// Handle ESC key to close modal
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleEscKey = (event: KeyboardEvent) => {
|
const handleEscKey = (event: KeyboardEvent) => {
|
||||||
@@ -352,16 +349,24 @@ export default function LauncherPage() {
|
|||||||
const serverData = await CheckUpdateServer(serverPath, serverVersion)
|
const serverData = await CheckUpdateServer(serverPath, serverVersion)
|
||||||
const proxyData = await CheckUpdateProxy(proxyPath, proxyVersion)
|
const proxyData = await CheckUpdateProxy(proxyPath, proxyVersion)
|
||||||
const launcherData = await CheckUpdateLauncher()
|
const launcherData = await CheckUpdateLauncher()
|
||||||
if (serverData.isUpdate || proxyData.isUpdate || launcherData.isUpdate) {
|
setUpdateData({
|
||||||
setUpdateData({
|
server: serverData,
|
||||||
server: serverData,
|
proxy: proxyData,
|
||||||
proxy: proxyData,
|
launcher: launcherData
|
||||||
launcher: launcherData
|
})
|
||||||
})
|
if (launcherData.isUpdate) {
|
||||||
setIsOpenUpdateDataModal(true)
|
setIsOpenSelfUpdateModal(true)
|
||||||
} else {
|
return
|
||||||
toast.success("No updates available")
|
|
||||||
}
|
}
|
||||||
|
if (!serverData.isExists || !proxyData.isExists) {
|
||||||
|
setIsOpenDownloadDataModal(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (serverData.isUpdate || proxyData.isUpdate) {
|
||||||
|
setIsOpenUpdateDataModal(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
toast.success("No updates available")
|
||||||
}}>
|
}}>
|
||||||
Check for Updates
|
Check for Updates
|
||||||
</button></li>
|
</button></li>
|
||||||
@@ -388,7 +393,12 @@ export default function LauncherPage() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Downloading */}
|
{/* Downloading */}
|
||||||
{isDownloading && (updateData.proxy.isUpdate || updateData.server.isUpdate) && (
|
{isDownloading && (
|
||||||
|
updateData.proxy.isUpdate
|
||||||
|
|| updateData.server.isUpdate
|
||||||
|
|| !updateData.proxy.isExists
|
||||||
|
|| !updateData.server.isExists
|
||||||
|
) && (
|
||||||
<div className="fixed bottom-4 left-1/2 transform -translate-x-1/2 z-10 w-[60vw] bg-black/20 backdrop-blur-sm rounded-lg p-4 shadow-lg">
|
<div className="fixed bottom-4 left-1/2 transform -translate-x-1/2 z-10 w-[60vw] bg-black/20 backdrop-blur-sm rounded-lg p-4 shadow-lg">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex justify-center items-center text-sm text-white/80">
|
<div className="flex justify-center items-center text-sm text-white/80">
|
||||||
@@ -505,7 +515,7 @@ export default function LauncherPage() {
|
|||||||
className="btn btn-primary bg-gradient-to-r from-orange-200 to-red-400 border-none"
|
className="btn btn-primary bg-gradient-to-r from-orange-200 to-red-400 border-none"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setIsOpenUpdateDataModal(false)
|
setIsOpenUpdateDataModal(false)
|
||||||
await handlerUpdateServer()
|
await handlerUpdateData()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Yes
|
Yes
|
||||||
@@ -539,7 +549,7 @@ export default function LauncherPage() {
|
|||||||
className="btn btn-primary bg-gradient-to-r from-orange-200 to-red-400 border-none"
|
className="btn btn-primary bg-gradient-to-r from-orange-200 to-red-400 border-none"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setIsOpenDownloadDataModal(false)
|
setIsOpenDownloadDataModal(false)
|
||||||
await handlerUpdateServer()
|
await handlerUpdateData()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Download
|
Download
|
||||||
@@ -590,7 +600,7 @@ export default function LauncherPage() {
|
|||||||
className="btn btn-primary bg-gradient-to-r from-orange-200 to-red-400 border-none"
|
className="btn btn-primary bg-gradient-to-r from-orange-200 to-red-400 border-none"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setIsOpenSelfUpdateModal(false)
|
setIsOpenSelfUpdateModal(false)
|
||||||
await handlerUpdateServer()
|
await handlerUpdateData()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Yes
|
Yes
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ interface LauncherState {
|
|||||||
progressDownload: number;
|
progressDownload: number;
|
||||||
downloadSpeed: number;
|
downloadSpeed: number;
|
||||||
launcherVersion: string;
|
launcherVersion: string;
|
||||||
updateData: Record<'server' | 'proxy' | 'launcher', { isUpdate: boolean, version: string }>;
|
updateData: Record<'server' | 'proxy' | 'launcher', { isUpdate: boolean, isExists: boolean, version: string }>;
|
||||||
setDownloadType: (value: string) => void;
|
setDownloadType: (value: string) => void;
|
||||||
setServerReady: (value: boolean) => void;
|
setServerReady: (value: boolean) => void;
|
||||||
setProxyReady: (value: boolean) => void;
|
setProxyReady: (value: boolean) => void;
|
||||||
@@ -25,7 +25,7 @@ interface LauncherState {
|
|||||||
setProgressDownload: (value: number) => void;
|
setProgressDownload: (value: number) => void;
|
||||||
setLauncherVersion: (value: string) => void;
|
setLauncherVersion: (value: string) => void;
|
||||||
setDownloadSpeed: (value: number) => void;
|
setDownloadSpeed: (value: number) => void;
|
||||||
setUpdateData: (value: Record<'server' | 'proxy' | 'launcher', { isUpdate: boolean, version: string }>) => void;
|
setUpdateData: (value: Record<'server' | 'proxy' | 'launcher', { isUpdate: boolean, isExists: boolean, version: string }>) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useLauncherStore = create<LauncherState>((set, get) => ({
|
const useLauncherStore = create<LauncherState>((set, get) => ({
|
||||||
@@ -41,9 +41,9 @@ const useLauncherStore = create<LauncherState>((set, get) => ({
|
|||||||
downloadSpeed: 0,
|
downloadSpeed: 0,
|
||||||
launcherVersion: "",
|
launcherVersion: "",
|
||||||
updateData: {
|
updateData: {
|
||||||
server: { isUpdate: false, version: "" },
|
server: { isUpdate: false, isExists: false, version: "" },
|
||||||
proxy: { isUpdate: false, version: "" },
|
proxy: { isUpdate: false, isExists: false, version: "" },
|
||||||
launcher: { isUpdate: false, version: "" },
|
launcher: { isUpdate: false, isExists: true, version: "" },
|
||||||
},
|
},
|
||||||
setIsLoading: (value: boolean) => set({ isLoading: value }),
|
setIsLoading: (value: boolean) => set({ isLoading: value }),
|
||||||
setDownloadType: (value: string) => set({ downloadType: value }),
|
setDownloadType: (value: string) => set({ downloadType: value }),
|
||||||
@@ -56,7 +56,7 @@ const useLauncherStore = create<LauncherState>((set, get) => ({
|
|||||||
setProgressDownload: (value: number) => set({ progressDownload: value }),
|
setProgressDownload: (value: number) => set({ progressDownload: value }),
|
||||||
setLauncherVersion: (value: string) => set({ launcherVersion: value }),
|
setLauncherVersion: (value: string) => set({ launcherVersion: value }),
|
||||||
setDownloadSpeed: (value: number) => set({ downloadSpeed: value }),
|
setDownloadSpeed: (value: number) => set({ downloadSpeed: value }),
|
||||||
setUpdateData: (value: Record<'server' | 'proxy' | 'launcher', { isUpdate: boolean, version: string }>) => set({ updateData: value }),
|
setUpdateData: (value: Record<'server' | 'proxy' | 'launcher', { isUpdate: boolean, isExists: boolean, version: string }>) => set({ updateData: value }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default useLauncherStore;
|
export default useLauncherStore;
|
||||||
Reference in New Issue
Block a user