import { useEffect, useState } from 'react' import ReactDOM from 'react-dom/client' import Installs from './routes/Installs' import Settings from './routes/Settings' import Sidebar from './componets/Sidebar' import './Globals.css' import { LauncherVersion } from './types/LauncherVersion' import { DownloadProgress } from './types/DownloadProgress' import { platform } from '@tauri-apps/plugin-os' import { invoke } from '@tauri-apps/api/core' import { listen } from '@tauri-apps/api/event' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faAdd, faRemove, faX } from '@fortawesome/free-solid-svg-icons' import '@fontsource/roboto' function App () { const [hash, setHash] = useState(window.location.hash || '#installs') const [versionList, setVersionList] = useState(null); const [selectedVersionList, setSelectedVersionList] = useState([]); const [downloadProgress, setDownloadProgress] = useState([]); const [showPopup, setShowPopup] = useState(false) const [popupMode, setPopupMode] = useState(null) const [fadeOut, setFadeOut] = useState(false) listen('download-progress', (event) => { const [urlEnc, progStr] = event.payload.split(':') const url = atob(urlEnc) const prog = Number(progStr) setDownloadProgress(prev => { const i = prev.findIndex(d => d.version.downloadUrls[d.version.platforms.indexOf(platform())] === url) if (i === -1) return prev if (prog >= 100) return prev.filter((_, j) => j !== i) const copy = [...prev] copy[i] = { ...copy[i], progress: prog } return copy }) }) function downloadVersions(versions: LauncherVersion[]) { const newDownloads = versions.map(v => new DownloadProgress(v, 0, false)); setDownloadProgress(prev => [...prev, ...newDownloads]); newDownloads.forEach(download => { invoke('download', { url: download.version.downloadUrls[download.version.platforms.indexOf(platform())], name: download.version.version }); }); } function handleOverlayClick (e: React.MouseEvent) { if (e.target === e.currentTarget) { setFadeOut(true) setTimeout(() => setShowPopup(false), 200) } } useEffect(() => { const onHashChange = () => setHash(window.location.hash || '#installs') window.addEventListener('hashchange', onHashChange) return () => window.removeEventListener('hashchange', onHashChange) }, []) useEffect(() => { const handler = (e: MouseEvent) => e.preventDefault() document.addEventListener('contextmenu', handler) return () => document.removeEventListener('contextmenu', handler) }, []) function renderContent () { if (hash === '#installs') { return } else if (hash === '#settings') { return } return null } return ( <>
{renderContent()}
{showPopup && (
{popupMode === 0 ? ( <>

Select versions to download

{versionList == null ? (

Getting version list...

) : ( versionList.map((v, i) =>

Berry Dash v{v.displayName}

) )}
) : popupMode === 1 ? ( <>

Downloads

{downloadProgress.length === 0 ? (

Nothing here...

) : ( downloadProgress.map((v, i) => (

Berry Dash v{v.version.displayName}

{v.progress}% downloaded

)) )}
) : null} {popupMode == 0 && versionList != null && (
)}
)} ) } ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( )