删除缓存已安装应用的逻辑,更新为即时查询/jingrow/installed-app-names
This commit is contained in:
parent
e8c2bf23da
commit
794c0caf33
@ -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>
|
||||
|
||||
|
||||
@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
// 监听搜索和排序变化
|
||||
|
||||
@ -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'))
|
||||
}
|
||||
|
||||
@ -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': []}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user