✨ Refresh app record
This commit is contained in:
parent
257884145e
commit
1592036b1a
@ -1,8 +1,8 @@
|
|||||||
import { ipcMain, app, shell } from 'electron'
|
import { ipcMain, app, shell } from 'electron'
|
||||||
import { MaProduct, MaRelease } from 'solar-js-sdk'
|
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import * as fs from 'fs'
|
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
|
import { MaRelease, MaProduct } from 'solar-js-sdk'
|
||||||
|
import * as fs from 'fs'
|
||||||
|
|
||||||
export interface AppLibrary {
|
export interface AppLibrary {
|
||||||
apps: LocalAppRecord[]
|
apps: LocalAppRecord[]
|
||||||
@ -44,6 +44,14 @@ export function initLibrary(): void {
|
|||||||
JSON.stringify(getAppLibrary().filter((ele) => ele.id === id)[0]),
|
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('uninstall-app', (_, id: string) => uninstallApp(id))
|
||||||
ipcMain.handle('launch-app', (_, id: string) => launchApp(id))
|
ipcMain.handle('launch-app', (_, id: string) => launchApp(id))
|
||||||
ipcMain.handle('open-path-app', (_, id: string) => openPathApp(id))
|
ipcMain.handle('open-path-app', (_, id: string) => openPathApp(id))
|
||||||
|
@ -13,11 +13,12 @@ import {
|
|||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { useEffect, useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { useNavigate, useParams } from 'react-router'
|
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 { parseContent } from '@renderer/services/parser'
|
||||||
|
|
||||||
import PlayIcon from '@mui/icons-material/PlayArrow'
|
import PlayIcon from '@mui/icons-material/PlayArrow'
|
||||||
import UninstallIcon from '@mui/icons-material/Delete'
|
import UninstallIcon from '@mui/icons-material/Delete'
|
||||||
|
import RefreshIcon from '@mui/icons-material/Refresh'
|
||||||
import ArrowBackwardIcon from '@mui/icons-material/ArrowBack'
|
import ArrowBackwardIcon from '@mui/icons-material/ArrowBack'
|
||||||
|
|
||||||
export default function LibraryDetails(): JSX.Element {
|
export default function LibraryDetails(): JSX.Element {
|
||||||
@ -54,6 +55,27 @@ export default function LibraryDetails(): JSX.Element {
|
|||||||
}
|
}
|
||||||
}, [app])
|
}, [app])
|
||||||
|
|
||||||
|
async function syncApp() {
|
||||||
|
setBusy(true)
|
||||||
|
try {
|
||||||
|
const { data: productData } = await sni.get<MaProduct>('/cgi/ma/products/' + app?.product.id)
|
||||||
|
const { data: releaseData } = await sni.get<MaRelease>(
|
||||||
|
'/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() {
|
async function uninstallApp() {
|
||||||
const yes = confirm(`Are you sure to uninstall this app ${app?.product.name} version ${app?.release.version}?`)
|
const yes = confirm(`Are you sure to uninstall this app ${app?.product.name} version ${app?.release.version}?`)
|
||||||
if (!yes) return
|
if (!yes) return
|
||||||
@ -147,6 +169,9 @@ export default function LibraryDetails(): JSX.Element {
|
|||||||
<Grid size={4}>
|
<Grid size={4}>
|
||||||
<Stack spacing={2} alignItems="end" sx={{ mx: -1.5 }}>
|
<Stack spacing={2} alignItems="end" sx={{ mx: -1.5 }}>
|
||||||
<Box>
|
<Box>
|
||||||
|
<IconButton disabled={busy} color="warning" onClick={syncApp}>
|
||||||
|
<RefreshIcon />
|
||||||
|
</IconButton>
|
||||||
<IconButton disabled={busy} color="error" onClick={uninstallApp}>
|
<IconButton disabled={busy} color="error" onClick={uninstallApp}>
|
||||||
<UninstallIcon />
|
<UninstallIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user