From 90cd5b23a0f39c76ffa59ee643c898eb84e0fd62 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 11 Jan 2025 23:08:20 +0800 Subject: [PATCH] :sparkles: Update app --- src/main/installer.ts | 12 ++-- src/main/tasks.ts | 1 + src/renderer/src/pages/Tasks.tsx | 6 +- src/renderer/src/pages/library/Details.tsx | 65 ++++++++++++++++++++++ 4 files changed, 76 insertions(+), 8 deletions(-) diff --git a/src/main/installer.ts b/src/main/installer.ts index feedc6d..ef6f8d2 100644 --- a/src/main/installer.ts +++ b/src/main/installer.ts @@ -14,17 +14,19 @@ export function initInstaller(): void { } function submitInstallTask(task: InstallTask, contents: WebContents): void { - task.id = randomUUID() + task.id = task.id ?? randomUUID() task.progress = { value: 0, period: InstallProgressPeriod.Initializing, done: false, error: null } task.emitter = contents if (!statSync(task.basePath).isDirectory()) { return } - if (readdirSync(task.basePath).length > 0) { - const newPath = join(task.basePath, task.product.name) - mkdirSync(newPath) - task.basePath = newPath + if (!task.isOverwrite) { + if (readdirSync(task.basePath).length > 0) { + const newPath = join(task.basePath, task.product.name) + mkdirSync(newPath) + task.basePath = newPath + } } installTasks[task.id] = task diff --git a/src/main/tasks.ts b/src/main/tasks.ts index 397c22e..131620a 100644 --- a/src/main/tasks.ts +++ b/src/main/tasks.ts @@ -8,6 +8,7 @@ export interface InstallTask { basePath: string progress?: InstallProgress emitter?: WebContents + isOverwrite?: boolean } export enum InstallProgressPeriod { diff --git a/src/renderer/src/pages/Tasks.tsx b/src/renderer/src/pages/Tasks.tsx index 8b267c5..7126e17 100644 --- a/src/renderer/src/pages/Tasks.tsx +++ b/src/renderer/src/pages/Tasks.tsx @@ -58,14 +58,14 @@ export default function Tasks(): JSX.Element { {t.progress?.value ? ( ) : ( )} diff --git a/src/renderer/src/pages/library/Details.tsx b/src/renderer/src/pages/library/Details.tsx index 27b2c65..7d2033d 100644 --- a/src/renderer/src/pages/library/Details.tsx +++ b/src/renderer/src/pages/library/Details.tsx @@ -3,6 +3,9 @@ import { Avatar, Box, Button, + Card, + CardContent, + Collapse, Container, Divider, Grid2 as Grid, @@ -16,10 +19,12 @@ import { useNavigate, useParams } from 'react-router' import { getAttachmentUrl, MaProduct, MaRelease, sni } from 'solar-js-sdk' import { parseContent } from '@renderer/services/parser' +import UpdateIcon from '@mui/icons-material/Download' import PlayIcon from '@mui/icons-material/PlayArrow' import UninstallIcon from '@mui/icons-material/Delete' import RefreshIcon from '@mui/icons-material/Refresh' import ArrowBackwardIcon from '@mui/icons-material/ArrowBack' +import { InstallTask } from '@main/tasks' export default function LibraryDetails(): JSX.Element { const { id } = useParams() @@ -55,6 +60,40 @@ export default function LibraryDetails(): JSX.Element { } }, [app]) + const [remoteReleases, setRemoteReleases] = useState([]) + + const hasUpdate = useMemo( + () => app && remoteReleases.length > 0 && remoteReleases[0].version != app?.release?.version, + [app, remoteReleases], + ) + + async function fetchRemoteReleases() { + const { data: resp } = await sni.get<{ data: MaRelease[] }>('/cgi/ma/products/' + app?.product.id + '/releases', { + params: { + take: 1, + }, + }) + + setRemoteReleases(resp.data) + } + + useEffect(() => { + if (!app) return + fetchRemoteReleases() + }, [app]) + + async function updateApp() { + const task: InstallTask = { + id: app!.id, + release: remoteReleases[0], + product: app!.product, + basePath: app!.basePath, + isOverwrite: true, + } + window.electron.ipcRenderer.invoke('install-product-release', JSON.stringify(task)) + navigate('/tasks') + } + async function syncApp() { setBusy(true) try { @@ -181,6 +220,32 @@ export default function LibraryDetails(): JSX.Element { + + + + + Update Available + + + {remoteReleases[0]?.meta.title} {remoteReleases[0]?.version} + + + {remoteReleases[0]?.meta.description} + + + + + +