diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1be8255..33629ba 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -148,7 +148,7 @@ async fn download( url: String, name: String, hash: String, - download_type: i8 + download_type: i8, ) -> String { println!("[download] Starting download for '{}' from '{}'", name, url); let _ = app.emit("download-start", format!("{}", name)); diff --git a/src/app/game/page.tsx b/src/app/game/page.tsx index 8488b53..c4b8597 100644 --- a/src/app/game/page.tsx +++ b/src/app/game/page.tsx @@ -387,6 +387,10 @@ export default function Installs () { } return } + setManagingVersion(entry) + setPopupMode(3) + setShowPopup(true) + setFadeOut(false) }} hidden={!getVersionInfo(entry)?.modSupportDownload} > diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 510d894..4df8b1d 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,8 +1,8 @@ 'use client' +import './Globals.css' import { useCallback, useEffect, useRef, useState } from 'react' import Sidebar from '@/componets/Sidebar' -import './Globals.css' import { DownloadProgress } from '@/types/DownloadProgress' import { invoke } from '@tauri-apps/api/core' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' @@ -30,14 +30,15 @@ import { requestPermission } from '@tauri-apps/plugin-notification' import { BaseDirectory, exists, remove } from '@tauri-apps/plugin-fs' +import { fetch } from '@tauri-apps/plugin-http' +import { verifySignature } from '@/lib/Util' +import { getCurrentWindow, UserAttentionType } from '@tauri-apps/api/window' import VersionsDownloadPopup from '@/componets/popups/VersionsDownload' import GamesDownloadPopup from '@/componets/popups/GamesDownload' import DownloadsPopup from '@/componets/popups/Downloads' import ManageVersionPopup from '@/componets/popups/ManageVersion' -import { fetch } from '@tauri-apps/plugin-http' -import { verifySignature } from '@/lib/Util' -import { getCurrentWindow, UserAttentionType } from '@tauri-apps/api/window' +import ModDownloadsPopup from '@/componets/popups/ModDownloads' const roboto = Roboto({ subsets: ['latin'] @@ -717,6 +718,8 @@ export default function RootLayout ({ ) : popupMode === 2 ? ( + ) : popupMode === 3 ? ( + ) : null} diff --git a/src/componets/popups/ModDownloads.tsx b/src/componets/popups/ModDownloads.tsx new file mode 100644 index 0000000..09e3b5b --- /dev/null +++ b/src/componets/popups/ModDownloads.tsx @@ -0,0 +1,103 @@ +'use client' + +import { useGlobal } from '@/app/GlobalProvider' +import { verifySignature } from '@/lib/Util' +import { Mod } from '@/types/Mod' +import { faDownload, faGlobe } from '@fortawesome/free-solid-svg-icons' +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { arch, platform } from '@tauri-apps/plugin-os' +import { useEffect, useState } from 'react' + +export default function ModDownloadsPopup () { + const { getGameInfo, getVersionInfo, managingVersion } = useGlobal() + + const [mods, setMods] = useState(0) + const [tab, setTab] = useState(0) + + useEffect(() => { + ;(async () => { + const response = await fetch( + `https://games.lncvrt.xyz/api/launcher/mods?platform=${platform()}&arch=${arch()}&version=${managingVersion}` + ) + const signature = response.headers.get('x-signature') ?? '' + const data = await response.json() + if (await verifySignature(JSON.stringify(data), signature)) { + setMods(data as Mod[]) + } else { + setMods(1) + } + })() + }, [managingVersion]) + + if (!managingVersion) return <> + + const versionInfo = getVersionInfo(managingVersion) + const gameInfo = getGameInfo(versionInfo?.game) + + return ( + <> +

+ {versionInfo?.displayName} Mod Manager +

+ {typeof mods != 'number' ? ( +
+ + +
+ ) : null} +
+ {typeof mods == 'number' ? ( +

+ {mods == 0 ? 'Loading' : 'Failed to load mods'} +

+ ) : ( +
+ {tab == 0 + ? null + : mods.map(v => { + return ( +
+
+

+ {v.name}{' '} + + v{v.latestVersion} + +

+

+ Made by {v.creators[0]} + {v.creators.length < 2 + ? ' + ' + v.creators.length + ' more' + : null} +

+
+
+

+ {v.downloads} +

+ +
+
+ ) + })} +
+ )} +
+ + ) +} diff --git a/src/types/Mod.ts b/src/types/Mod.ts new file mode 100644 index 0000000..ea8c3b1 --- /dev/null +++ b/src/types/Mod.ts @@ -0,0 +1,12 @@ +export interface Mod { + id: number + name: string + description: string | null + creators: string[] + downloads: number + released: number + updated: number + latestVersion: string + latestDownload: number + changelog: string | null +}