From 1592036b1a53d0b5e5de4bf8939d4d627ca3d8c3 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 11 Jan 2025 22:43:05 +0800 Subject: [PATCH] :sparkles: Refresh app record --- src/main/library.ts | 12 ++++++++-- src/renderer/src/pages/library/Details.tsx | 27 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/library.ts b/src/main/library.ts index acbe9b7..13b4a12 100644 --- a/src/main/library.ts +++ b/src/main/library.ts @@ -1,8 +1,8 @@ import { ipcMain, app, shell } from 'electron' -import { MaProduct, MaRelease } from 'solar-js-sdk' import { join } from 'path' -import * as fs from 'fs' import { spawn } from 'child_process' +import { MaRelease, MaProduct } from 'solar-js-sdk' +import * as fs from 'fs' export interface AppLibrary { apps: LocalAppRecord[] @@ -44,6 +44,14 @@ export function initLibrary(): void { JSON.stringify(getAppLibrary().filter((ele) => ele.id === id)[0]), ) + ipcMain.handle('sync-record-app', async (_, id: string, product: string, release: string) => { + const app = getAppLibrary().filter((ele) => ele.id === id)[0] + if (!app) return + app.product = JSON.parse(product) + app.release = JSON.parse(release) + setAppRecord(app) + }) + ipcMain.handle('uninstall-app', (_, id: string) => uninstallApp(id)) ipcMain.handle('launch-app', (_, id: string) => launchApp(id)) ipcMain.handle('open-path-app', (_, id: string) => openPathApp(id)) diff --git a/src/renderer/src/pages/library/Details.tsx b/src/renderer/src/pages/library/Details.tsx index abffd2c..27b2c65 100644 --- a/src/renderer/src/pages/library/Details.tsx +++ b/src/renderer/src/pages/library/Details.tsx @@ -13,11 +13,12 @@ import { } from '@mui/material' import { useEffect, useMemo, useState } from 'react' import { useNavigate, useParams } from 'react-router' -import { getAttachmentUrl } from 'solar-js-sdk' +import { getAttachmentUrl, MaProduct, MaRelease, sni } from 'solar-js-sdk' import { parseContent } from '@renderer/services/parser' 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' export default function LibraryDetails(): JSX.Element { @@ -54,6 +55,27 @@ export default function LibraryDetails(): JSX.Element { } }, [app]) + async function syncApp() { + setBusy(true) + try { + const { data: productData } = await sni.get('/cgi/ma/products/' + app?.product.id) + const { data: releaseData } = await sni.get( + '/cgi/ma/products/' + app?.product.id + '/releases/' + app?.release.id, + ) + + await window.electron.ipcRenderer.invoke( + 'sync-record-app', + app?.id, + JSON.stringify(productData), + JSON.stringify(releaseData), + ) + + fetchApp() + } finally { + setBusy(false) + } + } + async function uninstallApp() { const yes = confirm(`Are you sure to uninstall this app ${app?.product.name} version ${app?.release.version}?`) if (!yes) return @@ -147,6 +169,9 @@ export default function LibraryDetails(): JSX.Element { + + +