优化调整

This commit is contained in:
zhongluofeng
2026-08-14 17:47:06 +08:00
parent 6c7897bf47
commit 7d49a7395f
50 changed files with 2805 additions and 259 deletions
+34 -7
View File
@@ -14,8 +14,9 @@ import { useProcessStore } from '@/stores/processStore'
import { TooltipProvider } from '@/components/ui/tooltip'
import { moduleRegistry } from '@/modules/registry'
import type { ModuleMeta } from '@/types/module'
import { pendingNewDownload } from '@/lib/trayEvents'
import { pendingNewDownload, pendingShowDownloadTasks } from '@/lib/trayEvents'
import { EVENTS, STORAGE_KEYS } from '@/lib/constants'
import { commands } from '@/lib/bindings'
const appStore = useAppStore()
const screenshotStore = useScreenshotStore()
@@ -43,6 +44,9 @@ const activeModule = ref('')
const activeComponent = shallowRef<Component | null>(null)
/** 模块组件加载中(异步 import 未完成)标志,避免切换期间仍显示上一个模块内容 */
const moduleLoading = ref(false)
/** 当前可显示的模块(内置模块 + 已启用的用户模块),按用户排序显示 */
const availableModules = computed<NavModule[]>(() => {
const enabledIds = appStore.enabledModules.map(m => m.id)
@@ -67,10 +71,15 @@ const availableModules = computed<NavModule[]>(() => {
let moduleLoadSeq = 0
const loadModule = async (moduleId: string) => {
const seq = ++moduleLoadSeq
// 立即清空旧组件并进入加载态,避免异步 import 期间仍渲染上一个模块内容
// (否则 ModuleContainer 以 :key="activeModule" 重挂载旧组件,用户误以为切换失败)
activeComponent.value = null
moduleLoading.value = true
const component = await moduleRegistry.loadComponent(moduleId)
// 过期请求(期间用户又切换了模块)直接丢弃,不覆盖 activeComponent 也不触发钩子
if (seq !== moduleLoadSeq) return
activeComponent.value = component
moduleLoading.value = false
// 调用模块的 onActivate 生命周期钩子
const config = moduleRegistry.getConfig(moduleId)
@@ -151,16 +160,24 @@ onMounted(async () => {
// 快速面板:同步命令缓存与设置到 localStorage,供独立窗口读取
quickpanelStore.syncCommands()
quickpanelStore.syncSettings()
// 初始化文件索引 DB 并恢复增量监听(上次构建过索引时自动恢复,不重建)
commands.quickpanelInitFileIndex().catch(e => console.error('文件索引初始化失败:', e))
// 监听快速面板执行命令事件:显示主窗口 + 切换模块
trayUnlisteners.push(
await listen<{ moduleId: string }>('quickpanel-execute-command', async (e) => {
const win = getCurrentWindow()
// Rust 端强制置前(绕过 Windows 前台锁定,主窗口被遮挡时也能到前台)
try {
await win.show()
await win.unminimize()
await win.setFocus()
await commands.quickpanelFocusMainWindow()
} catch {
/* 忽略窗口操作失败 */
// 回退:前端 show + setFocus
const win = getCurrentWindow()
try {
await win.show()
await win.unminimize()
await win.setFocus()
} catch {
/* 忽略窗口操作失败 */
}
}
handleSearch(e.payload.moduleId)
})
@@ -179,6 +196,16 @@ onMounted(async () => {
}
})
)
// 浏览器扩展新增下载:直接切到下载模块的任务列表页(主窗口已由 Rust 端置前)
trayUnlisteners.push(
await listen(EVENTS.downloadExtensionAdded, () => {
const enabledIds = appStore.enabledModules.map(m => m.id)
if (enabledIds.includes('downloader') || moduleRegistry.getConfig('downloader')?.builtin) {
pendingShowDownloadTasks.value = true
handleModuleChange('downloader')
}
})
)
trayUnlisteners.push(
await listen(EVENTS.trayOpenSettings, () => {
handleModuleChange('settings')
@@ -210,7 +237,7 @@ onUnmounted(() => {
:active-module="activeModule"
@change="handleModuleChange"
/>
<ModuleContainer :active-component="activeComponent" :active-module="activeModule" />
<ModuleContainer :active-component="activeComponent" :active-module="activeModule" :loading="moduleLoading" />
</div>
</div>
<Toaster position="bottom-right" rich-colors close-button :style="{ zIndex: 99999 }" />