From 19788a8a3c4c7bda8ec8a5fd2bbe9516db82fff8 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Thu, 26 Feb 2026 23:22:16 -0700 Subject: [PATCH] Update launche to new API --- src-tauri/src/lib.rs | 1 + src/app/layout.tsx | 56 +++++++++++++++++++++---- src/componets/popups/Downloads.tsx | 2 +- src/componets/popups/VersionVersion.tsx | 15 ------- src/types/DownloadProgress.ts | 1 + src/types/GameVersion.ts | 6 +-- 6 files changed, 54 insertions(+), 27 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d980a68..07634e8 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -139,6 +139,7 @@ async fn download( } }; let total_size = resp.content_length().unwrap_or(0); + let _ = app.emit("download-size", format!("{}:{}", &name, &total_size)); let mut downloaded: u64 = 0; let mut stream = resp.bytes_stream(); diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 3830a8e..16a86ce 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -181,6 +181,21 @@ export default function RootLayout ({ useEffect(() => { let unlistenProgress: (() => void) | null = null + listen('download-size', event => { + const [displayName, sizeStr] = event.payload.split(':') + const size = Number(sizeStr) + setDownloadProgress(prev => { + const i = prev.findIndex(d => d.version === displayName) + if (i === -1) return prev + const copy = [...prev] + copy[i] = { + ...copy[i], + size + } + return copy + }) + }).then(f => (unlistenProgress = f)) + listen('download-progress', event => { const [displayName, progStr, totalSizeStr, speedStr, etaSecsStr] = event.payload.split(':') @@ -285,7 +300,18 @@ export default function RootLayout ({ const newDownloads = newVersions.map( version => - new DownloadProgress(version, 0, 0, false, true, false, false, 0, 0) + new DownloadProgress( + version, + 0, + 0, + false, + true, + false, + false, + 0, + 0, + 0 + ) ) setDownloadProgress(prev => [...prev, ...newDownloads]) @@ -322,17 +348,33 @@ export default function RootLayout ({ prev.map(d => (d.version === versionId ? { ...d, queued: false } : d)) ) - try { - await axios.get( - 'https://games.lncvrt.xyz/api/launcher/download?id=' + info.id + const downloadInfoRequest = await axios.get( + 'https://games.lncvrt.xyz/api/launcher/download?gameId=' + + info.id + + '&downloadId=' + + info.download + ) + if (!downloadInfoRequest.data.success) { + setDownloadProgress(prev => + prev.map(d => + d.version === versionId + ? { ...d, queued: false, failed: true, progress: 0 } + : d + ) ) - } catch {} + if (normalConfig?.settings.allowNotifications) + await notifyUser( + 'Download Failed', + `The download for version ${info.displayName} has failed.` + ) + return + } const res = await invoke('download', { - url: info.downloadUrl, + url: downloadInfoRequest.data.data.url, name: info.id, executable: info.executable, - hash: info.sha512sum + hash: downloadInfoRequest.data.data.hash }) if (res === '1') { diff --git a/src/componets/popups/Downloads.tsx b/src/componets/popups/Downloads.tsx index 3bf48aa..5db1598 100644 --- a/src/componets/popups/Downloads.tsx +++ b/src/componets/popups/Downloads.tsx @@ -70,7 +70,7 @@ export default function DownloadsPopup () { maximumFractionDigits: 1 })}{' '} of{' '} - {prettyBytes(getVersionInfo(v.version)?.size ?? 0, { + {prettyBytes(v.size, { minimumFractionDigits: 1, maximumFractionDigits: 1 })}{' '} diff --git a/src/componets/popups/VersionVersion.tsx b/src/componets/popups/VersionVersion.tsx index 1cae789..e73ac44 100644 --- a/src/componets/popups/VersionVersion.tsx +++ b/src/componets/popups/VersionVersion.tsx @@ -107,21 +107,6 @@ export default function VersionVersionPopup () { : 'N/A'}

-
{ diff --git a/src/types/DownloadProgress.ts b/src/types/DownloadProgress.ts index 7181648..eeafb03 100644 --- a/src/types/DownloadProgress.ts +++ b/src/types/DownloadProgress.ts @@ -8,6 +8,7 @@ export class DownloadProgress { public hash_checking: boolean, public finishing: boolean, public speed: number, + public size: number, public etaSecs: number ) {} } diff --git a/src/types/GameVersion.ts b/src/types/GameVersion.ts index a539f5d..25167db 100644 --- a/src/types/GameVersion.ts +++ b/src/types/GameVersion.ts @@ -3,13 +3,11 @@ export interface GameVersion { displayName: string releaseDate: number game: number - downloadUrl: string - executable: string - sha512sum: string - size: number place: number changelog: string wine: number | undefined category: number lastRevision: number + download: number + executable: string }