From fbe3feec9d1dad4a2904cff29059bd279a44ec6d Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Wed, 4 Feb 2026 16:47:54 -0700 Subject: [PATCH] Fix some issues --- src/app/layout.tsx | 166 +++++++++++++++++----------------- src/app/settings/page.tsx | 181 ++++++++++++++++++++------------------ 2 files changed, 182 insertions(+), 165 deletions(-) diff --git a/src/app/layout.tsx b/src/app/layout.tsx index fdff406..aaac465 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,6 @@ 'use client' -import { useEffect, useRef, useState } from 'react' +import { useCallback, useEffect, useRef, useState } from 'react' import Sidebar from './componets/Sidebar' import './Globals.css' import { DownloadProgress } from './types/DownloadProgress' @@ -111,15 +111,21 @@ export default function RootLayout ({ }) } - function getVersionInfo (id: string | undefined): GameVersion | undefined { - if (!id) return undefined - return serverVersionList?.versions.find(v => v.id === id) - } + const getVersionInfo = useCallback( + (id: string | undefined): GameVersion | undefined => { + if (!id) return undefined + return serverVersionList?.versions.find(v => v.id === id) + }, + [serverVersionList] + ) - function getGameInfo (game: number | undefined): Game | undefined { - if (!game) return undefined - return serverVersionList?.games.find(g => g.id === game) - } + const getGameInfo = useCallback( + (game: number | undefined): Game | undefined => { + if (!game) return undefined + return serverVersionList?.games.find(g => g.id === game) + }, + [serverVersionList] + ) function getListOfGames (): Game[] { if (!downloadedVersionsConfig?.list) return [] @@ -292,89 +298,89 @@ export default function RootLayout ({ return () => document.removeEventListener('contextmenu', handler) }, []) - async function downloadVersions ( - list: string[], - currentConfig: VersionsConfig - ): Promise { - if (list.length === 0) return - setSelectedVersionList([]) + const downloadVersions = useCallback( + async (list: string[], currentConfig: VersionsConfig): Promise => { + if (list.length === 0) return + setSelectedVersionList([]) - const newDownloads = list.map( - version => - new DownloadProgress(version, 0, 0, false, true, false, false, 0, 0) - ) - - setDownloadProgress(newDownloads) - - for (const download of newDownloads) { - const info = getVersionInfo(download.version) - if (!info) { - setDownloadProgress(prev => - prev.filter(d => d.version !== download.version) - ) - continue - } - - const gameInfo = getGameInfo(info.game) - if (!gameInfo) { - setDownloadProgress(prev => - prev.filter(d => d.version !== download.version) - ) - continue - } - - setDownloadProgress(prev => - prev.map(d => - d.version === download.version ? { ...d, queued: false } : d - ) + const newDownloads = list.map( + version => + new DownloadProgress(version, 0, 0, false, true, false, false, 0, 0) ) - try { - await axios.get( - 'https://games.lncvrt.xyz/api/launcher/download?id=' + info.id - ) - } catch {} + setDownloadProgress(newDownloads) - const res = await invoke('download', { - url: info.downloadUrl, - name: info.id, - executable: info.executable, - hash: info.sha512sum - }) - - if (res === '1') { - setDownloadProgress(prev => - prev.filter(d => d.version !== download.version) - ) - const date = Date.now() - const newConfig = { - ...currentConfig, - list: { ...currentConfig.list, [download.version]: date } + for (const download of newDownloads) { + const info = getVersionInfo(download.version) + if (!info) { + setDownloadProgress(prev => + prev.filter(d => d.version !== download.version) + ) + continue } - setDownloadedVersionsConfig(newConfig) - writeVersionsConfig(newConfig) - } else { + + const gameInfo = getGameInfo(info.game) + if (!gameInfo) { + setDownloadProgress(prev => + prev.filter(d => d.version !== download.version) + ) + continue + } + setDownloadProgress(prev => prev.map(d => - d.version === download.version - ? { ...d, queued: false, failed: true, progress: 0 } - : d + d.version === download.version ? { ...d, queued: false } : d ) ) - if (normalConfig?.settings.allowNotifications) - await notifyUser( - 'Download Failed', - `The download for version ${info.displayName} has failed.` + + try { + await axios.get( + 'https://games.lncvrt.xyz/api/launcher/download?id=' + info.id ) + } catch {} + + const res = await invoke('download', { + url: info.downloadUrl, + name: info.id, + executable: info.executable, + hash: info.sha512sum + }) + + if (res === '1') { + setDownloadProgress(prev => + prev.filter(d => d.version !== download.version) + ) + const date = Date.now() + const newConfig = { + ...currentConfig, + list: { ...currentConfig.list, [download.version]: date } + } + setDownloadedVersionsConfig(newConfig) + writeVersionsConfig(newConfig) + } else { + setDownloadProgress(prev => + prev.map(d => + d.version === download.version + ? { ...d, queued: false, failed: true, progress: 0 } + : d + ) + ) + if (normalConfig?.settings.allowNotifications) + await notifyUser( + 'Download Failed', + `The download for version ${info.displayName} has failed.` + ) + } } - } - if (normalConfig?.settings.allowNotifications) - await notifyUser('Downloads Finished', 'All downloads have finished.') + if (normalConfig?.settings.allowNotifications) + await notifyUser('Downloads Finished', 'All downloads have finished.') - setFadeOut(true) - setTimeout(() => setShowPopup(false), 200) - } + setFadeOut(true) + setTimeout(() => setShowPopup(false), 200) + }, + [getGameInfo, getVersionInfo, normalConfig] + ) useEffect(() => { if (revisionCheck.current) return @@ -404,7 +410,7 @@ export default function RootLayout ({ await downloadVersions(versionsToSelect, newConfig) })() - }, [serverVersionList, downloadedVersionsConfig]) + }, [serverVersionList, downloadedVersionsConfig, downloadVersions]) return ( <> diff --git a/src/app/settings/page.tsx b/src/app/settings/page.tsx index 0f28389..704ebf4 100644 --- a/src/app/settings/page.tsx +++ b/src/app/settings/page.tsx @@ -50,24 +50,22 @@ export default function Settings () { label='Allow sending notifications' value={allowNotifications} onChange={async () => { - while (normalConfig != null) { - setAllowNotifications(!allowNotifications) - setNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - allowNotifications: !allowNotifications - } - }) - writeNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - allowNotifications: !allowNotifications - } - }) - break - } + if (!normalConfig) return + setAllowNotifications(!allowNotifications) + setNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + allowNotifications: !allowNotifications + } + }) + await writeNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + allowNotifications: !allowNotifications + } + }) }} title='This setting does as you expect, allow the launcher to send notifications for when stuff like downloading is done.' /> @@ -75,24 +73,22 @@ export default function Settings () { label='Always show games in sidebar' value={alwaysShowGamesInSidebar} onChange={async () => { - while (normalConfig != null) { - setAlwaysShowGamesInSidebar(!alwaysShowGamesInSidebar) - setNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar - } - }) - writeNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar - } - }) - break - } + if (!normalConfig) return + setAlwaysShowGamesInSidebar(!alwaysShowGamesInSidebar) + setNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar + } + }) + await writeNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + alwaysShowGamesInSidebar: !alwaysShowGamesInSidebar + } + }) }} title="This setting will make it so when you are on a page like this, the games won't disappear." /> @@ -100,24 +96,22 @@ export default function Settings () { label='Show Installs/Launch/Manage Buttons' value={useLegacyInteractButtons} onChange={async () => { - while (normalConfig != null) { - setUseLegacyInteractButtons(!useLegacyInteractButtons) - setNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - useLegacyInteractButtons: !useLegacyInteractButtons - } - }) - writeNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - useLegacyInteractButtons: !useLegacyInteractButtons - } - }) - break - } + if (!normalConfig) return + setUseLegacyInteractButtons(!useLegacyInteractButtons) + setNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + useLegacyInteractButtons: !useLegacyInteractButtons + } + }) + await writeNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + useLegacyInteractButtons: !useLegacyInteractButtons + } + }) }} title='Enable the legacy method of using the installs/launch/manage buttons. In the future this setting may be removed so try and get used to the new method.' /> @@ -125,13 +119,22 @@ export default function Settings () { label='Use wine when needed to launch games' value={useWineOnUnixWhenNeeded} onChange={async () => { - while (normalConfig != null) { - setUseWineOnUnixWhenNeeded(!useWineOnUnixWhenNeeded) - normalConfig.settings.useWineOnUnixWhenNeeded = - !useWineOnUnixWhenNeeded - await writeNormalConfig(normalConfig) - break - } + if (!normalConfig) return + setUseWineOnUnixWhenNeeded(!useWineOnUnixWhenNeeded) + setNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + useWineOnUnixWhenNeeded: !useWineOnUnixWhenNeeded + } + }) + await writeNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + useWineOnUnixWhenNeeded: !useWineOnUnixWhenNeeded + } + }) }} className={platform() == 'linux' ? '' : 'hidden'} /> @@ -142,12 +145,22 @@ export default function Settings () { type='text' value={wineOnUnixCommand} onChange={async e => { - while (normalConfig != null) { - setWineOnUnixCommand(e.target.value) - normalConfig.settings.wineOnUnixCommand = e.target.value - await writeNormalConfig(normalConfig) - break - } + if (!normalConfig) return + setWineOnUnixCommand(e.target.value) + setNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + wineOnUnixCommand: e.target.value + } + }) + await writeNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + wineOnUnixCommand: e.target.value + } + }) }} className={`input-field my-1 ${ platform() == 'linux' && useWineOnUnixWhenNeeded ? '' : 'hidden' @@ -159,25 +172,23 @@ export default function Settings () { className='ml-2 bg-(--col2) border border-(--col4) rounded-md' value={theme} onChange={async e => { + if (!normalConfig) return const newTheme = parseInt(e.target.value) - while (normalConfig != null) { - setTheme(newTheme) - setNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - theme: newTheme - } - }) - writeNormalConfig({ - ...normalConfig, - settings: { - ...normalConfig.settings, - theme: newTheme - } - }) - break - } + setTheme(newTheme) + setNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + theme: newTheme + } + }) + await writeNormalConfig({ + ...normalConfig, + settings: { + ...normalConfig.settings, + theme: newTheme + } + }) }} >