mirror of
https://github.com/Novattz/creamlinux-installer.git
synced 2026-01-24 20:32:51 -05:00
index and update screen
This commit is contained in:
18
src/App.tsx
18
src/App.tsx
@@ -1,11 +1,10 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
import { useAppContext } from '@/contexts/useAppContext'
|
import { useAppContext } from '@/contexts/useAppContext'
|
||||||
import { UpdateNotifier } from '@/components/updater'
|
|
||||||
import { useAppLogic } from '@/hooks'
|
import { useAppLogic } from '@/hooks'
|
||||||
import './styles/main.scss'
|
import './styles/main.scss'
|
||||||
|
|
||||||
// Layout components
|
// Layout components
|
||||||
import { Header, Sidebar, InitialLoadingScreen, ErrorBoundary } from '@/components/layout'
|
import { Header, Sidebar, InitialLoadingScreen, ErrorBoundary, UpdateScreen, AnimatedBackground } from '@/components/layout'
|
||||||
import AnimatedBackground from '@/components/layout/AnimatedBackground'
|
|
||||||
|
|
||||||
// Dialog components
|
// Dialog components
|
||||||
import { ProgressDialog, DlcSelectionDialog, SettingsDialog } from '@/components/dialogs'
|
import { ProgressDialog, DlcSelectionDialog, SettingsDialog } from '@/components/dialogs'
|
||||||
@@ -17,6 +16,7 @@ import { GameList } from '@/components/games'
|
|||||||
* Main application component
|
* Main application component
|
||||||
*/
|
*/
|
||||||
function App() {
|
function App() {
|
||||||
|
const [updateComplete, setUpdateComplete] = useState(false)
|
||||||
// Get application logic from hook
|
// Get application logic from hook
|
||||||
const {
|
const {
|
||||||
filter,
|
filter,
|
||||||
@@ -29,7 +29,7 @@ function App() {
|
|||||||
handleRefresh,
|
handleRefresh,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
} = useAppLogic({ autoLoad: true })
|
} = useAppLogic({ autoLoad: updateComplete })
|
||||||
|
|
||||||
// Get action handlers from context
|
// Get action handlers from context
|
||||||
const {
|
const {
|
||||||
@@ -45,7 +45,12 @@ function App() {
|
|||||||
handleSettingsClose,
|
handleSettingsClose,
|
||||||
} = useAppContext()
|
} = useAppContext()
|
||||||
|
|
||||||
// Show loading screen during initial load
|
// Show update screen first
|
||||||
|
if (!updateComplete) {
|
||||||
|
return <UpdateScreen onComplete={() => setUpdateComplete(true)} />
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then show initial loading screen
|
||||||
if (isInitialLoad) {
|
if (isInitialLoad) {
|
||||||
return <InitialLoadingScreen message={scanProgress.message} progress={scanProgress.progress} />
|
return <InitialLoadingScreen message={scanProgress.message} progress={scanProgress.progress} />
|
||||||
}
|
}
|
||||||
@@ -114,9 +119,6 @@ function App() {
|
|||||||
visible ={settingsDialog.visible}
|
visible ={settingsDialog.visible}
|
||||||
onClose={handleSettingsClose}
|
onClose={handleSettingsClose}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Simple update notifier that uses toast - no UI component */}
|
|
||||||
<UpdateNotifier />
|
|
||||||
</div>
|
</div>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export { default as LoadingIndicator } from './LoadingIndicator'
|
export { default as LoadingIndicator } from './LoadingIndicator'
|
||||||
|
export { default as ProgressBar } from './ProgressBar'
|
||||||
|
|
||||||
export type { LoadingSize, LoadingType } from './LoadingIndicator'
|
export type { LoadingSize, LoadingType } from './LoadingIndicator'
|
||||||
|
|||||||
94
src/components/layout/UpdateScreen.tsx
Normal file
94
src/components/layout/UpdateScreen.tsx
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import { useState, useEffect, useCallback } from 'react'
|
||||||
|
import { check } from '@tauri-apps/plugin-updater'
|
||||||
|
import { relaunch } from '@tauri-apps/plugin-process'
|
||||||
|
import { ProgressBar } from '@/components/common'
|
||||||
|
|
||||||
|
interface UpdateScreenProps {
|
||||||
|
onComplete: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update screen displayed before the initial loading screen
|
||||||
|
* Checks for updates and installs them automatically
|
||||||
|
*/
|
||||||
|
const UpdateScreen = ({ onComplete }: UpdateScreenProps) => {
|
||||||
|
const [checking, setChecking] = useState(true)
|
||||||
|
const [downloading, setDownloading] = useState(false)
|
||||||
|
const [progress, setProgress] = useState(0)
|
||||||
|
const [version, setVersion] = useState('')
|
||||||
|
|
||||||
|
const checkForUpdates = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
setChecking(true)
|
||||||
|
const update = await check()
|
||||||
|
|
||||||
|
// Check if update exists (null means no update available)
|
||||||
|
if (update) {
|
||||||
|
setChecking(false)
|
||||||
|
setDownloading(true)
|
||||||
|
setVersion(update.version)
|
||||||
|
|
||||||
|
// Download and install the update
|
||||||
|
await update.downloadAndInstall((event) => {
|
||||||
|
switch (event.event) {
|
||||||
|
case 'Started': {
|
||||||
|
const contentLength = event.data.contentLength
|
||||||
|
console.log(`Started downloading ${contentLength} bytes`)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'Progress': {
|
||||||
|
const { chunkLength } = event.data
|
||||||
|
// Calculate cumulative progress
|
||||||
|
setProgress((prev) => {
|
||||||
|
const newProgress = prev + chunkLength
|
||||||
|
return Math.min(newProgress, 100)
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'Finished':
|
||||||
|
console.log('Download finished, installing...')
|
||||||
|
setProgress(100)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Relaunch the app
|
||||||
|
await relaunch()
|
||||||
|
} else {
|
||||||
|
// No update available (update is null), proceed to normal loading
|
||||||
|
setChecking(false)
|
||||||
|
onComplete()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Update check failed:', error)
|
||||||
|
// On error, just continue to the app
|
||||||
|
setChecking(false)
|
||||||
|
onComplete()
|
||||||
|
}
|
||||||
|
}, [onComplete])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
checkForUpdates()
|
||||||
|
}, [checkForUpdates])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="initial-loading-screen">
|
||||||
|
<div className="loading-content">
|
||||||
|
<h1>CreamLinux</h1>
|
||||||
|
|
||||||
|
<div className="loading-animation">
|
||||||
|
{checking && <div className="loading-spinner"></div>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="loading-message">
|
||||||
|
{checking && 'Checking for updates...'}
|
||||||
|
{downloading && `Downloading update v${version}...`}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{downloading && <ProgressBar progress={progress} />}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UpdateScreen
|
||||||
@@ -4,3 +4,4 @@ export { default as Sidebar } from './Sidebar'
|
|||||||
export { default as AnimatedBackground } from './AnimatedBackground'
|
export { default as AnimatedBackground } from './AnimatedBackground'
|
||||||
export { default as InitialLoadingScreen } from './InitialLoadingScreen'
|
export { default as InitialLoadingScreen } from './InitialLoadingScreen'
|
||||||
export { default as ErrorBoundary } from './ErrorBoundary'
|
export { default as ErrorBoundary } from './ErrorBoundary'
|
||||||
|
export { default as UpdateScreen } from './UpdateScreen'
|
||||||
|
|||||||
Reference in New Issue
Block a user