删除缓存已安装应用的逻辑,更新为即时查询/jingrow/installed-app-names

This commit is contained in:
jingrow 2025-10-27 03:31:00 +08:00
parent e8c2bf23da
commit 794c0caf33
4 changed files with 94 additions and 16 deletions

View File

@ -12,7 +12,23 @@
</template>
{{ t('Back') }}
</n-button>
<n-button type="primary" @click="installApp" size="medium">
<n-button
v-if="isCurrentAppInstalled"
type="warning"
@click="installApp"
size="medium"
>
<template #icon>
<n-icon><Icon icon="tabler:download" /></n-icon>
</template>
{{ t('Update') }}
</n-button>
<n-button
v-else
type="primary"
@click="installApp"
size="medium"
>
<template #icon>
<n-icon><Icon icon="tabler:download" /></n-icon>
</template>
@ -151,6 +167,9 @@ const installMessage = ref('')
const installStatus = ref<'success' | 'error' | 'info'>('info')
const showProgressModal = ref(false)
//
const installedAppNames = ref<Set<string>>(new Set())
const appName = computed(() => route.params.name as string)
async function loadAppDetail() {
@ -261,6 +280,16 @@ async function performInstall() {
installMessage.value = t('应用安装成功!')
message.success(t('应用安装成功'))
// API
try {
const refreshResponse = await axios.get('/jingrow/installed-app-names')
if (refreshResponse.data.success) {
installedAppNames.value = new Set(refreshResponse.data.apps || [])
}
} catch (error) {
console.error('Refresh installed apps error:', error)
}
setTimeout(() => {
showProgressModal.value = false
}, 2000)
@ -280,8 +309,39 @@ async function performInstall() {
}
}
//
async function loadInstalledApps() {
try {
const response = await axios.get('/jingrow/installed-app-names')
if (response.data.success) {
const apps = response.data.apps || []
installedAppNames.value = new Set(apps)
}
} catch (error) {
console.error('Load installed apps error:', error)
}
}
//
function isAppInstalled(appName: string): boolean {
if (!appName) return false
return installedAppNames.value.has(appName.toLowerCase())
}
//
const isCurrentAppInstalled = computed(() => {
if (!app.value) return false
return isAppInstalled(app.value.app_name || app.value.name || '')
})
onMounted(() => {
loadAppDetail()
loadInstalledApps()
// window
window.addEventListener('installedAppsUpdated', () => {
loadInstalledApps()
})
})
</script>

View File

@ -314,8 +314,15 @@ async function performInstall(app: any) {
installMessage.value = t('应用安装成功!')
message.success(t('应用安装成功'))
//
loadInstalledApps()
// API
try {
const refreshResponse = await axios.get('/jingrow/installed-app-names')
if (refreshResponse.data.success) {
installedAppNames.value = new Set(refreshResponse.data.apps || [])
}
} catch (error) {
console.error('Refresh installed apps error:', error)
}
setTimeout(() => {
showProgressModal.value = false
@ -361,23 +368,10 @@ function truncateText(text: string, maxLength: number): string {
//
async function loadInstalledApps() {
try {
const cached = sessionStorage.getItem('installed_apps_names')
if (cached) {
const data = JSON.parse(cached)
if (Date.now() - data.timestamp < 30 * 60 * 1000) {
installedAppNames.value = new Set(data.apps || [])
return
}
}
const response = await axios.get('/jingrow/installed-app-names')
if (response.data.success) {
const apps = response.data.apps || []
installedAppNames.value = new Set(apps)
sessionStorage.setItem('installed_apps_names', JSON.stringify({
apps,
timestamp: Date.now()
}))
}
} catch (error) {
console.error('Load installed apps error:', error)
@ -393,6 +387,11 @@ function isAppInstalled(appName: string): boolean {
onMounted(() => {
loadApps()
loadInstalledApps()
// window
window.addEventListener('installedAppsUpdated', () => {
loadInstalledApps()
})
})
//

View File

@ -140,7 +140,24 @@ const uninstallApp = async (app: any) => {
if (response.data.success) {
message.success(t('App \'{0}\' uninstalled successfully').replace('{0}', app.name))
//
try {
const refreshResponse = await axios.get('/jingrow/installed-app-names', {
headers: get_session_api_headers()
})
if (refreshResponse.data.success) {
//
window.dispatchEvent(new Event('installedAppsUpdated'))
}
} catch (error) {
console.error('Refresh installed apps error:', error)
}
await loadInstalledApps()
// localStorage
localStorage.setItem('installed_apps_updated', Date.now().toString())
} else {
message.error(response.data.error || t('Failed to uninstall app'))
}

View File

@ -246,8 +246,10 @@ async def get_installed_app_names():
if pkg_name:
installed.add(pkg_name.lower())
print(f"[DEBUG] Installed apps from API: {list(installed)}")
return {'success': True, 'apps': list(installed)}
except Exception as e:
print(f"[DEBUG] Error in installed-app-names: {str(e)}")
return {'success': False, 'error': str(e), 'apps': []}