This commit is contained in:
zhongluofeng
2026-07-30 09:09:29 +08:00
parent 74902c4cec
commit f452322aad
32 changed files with 4586 additions and 115 deletions
+50 -1
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ref, onMounted, shallowRef, computed, watch, type Component } from 'vue'
import { ref, onMounted, onUnmounted, shallowRef, computed, watch, type Component } from 'vue'
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
import TitleBar from '@/components/layout/TitleBar.vue'
import Sidebar from '@/components/layout/Sidebar.vue'
import ModuleContainer from '@/components/layout/ModuleContainer.vue'
@@ -8,6 +9,7 @@ import { useAppStore } from '@/stores/appStore'
import { TooltipProvider } from '@/components/ui/tooltip'
import { moduleRegistry } from '@/modules/registry'
import type { ModuleMeta } from '@/types/module'
import { pendingNewDownload, pendingOpenSettings } from '@/lib/trayEvents'
const appStore = useAppStore()
@@ -31,6 +33,14 @@ const activeModule = ref('')
const activeComponent = shallowRef<Component | null>(null)
/** 预加载的监控模块组件(用于隐藏预渲染,确保 OSD 在启动时创建) */
const monitorComponent = shallowRef<Component | null>(null)
/** 监控模块是否已启用 */
const monitorEnabled = computed(() =>
appStore.modules.find(m => m.id === 'monitor')?.enabled ?? false
)
/** 当前可显示的模块(内置模块 + 已启用的用户模块),按用户排序显示 */
const availableModules = computed<NavModule[]>(() => {
const enabledIds = appStore.enabledModules.map(m => m.id)
@@ -116,9 +126,43 @@ const resolveDefaultModule = (): string => {
onMounted(async () => {
await appStore.init().catch(e => console.error('App init error:', e))
// 预加载监控模块组件,用于隐藏预渲染
// 这样即使启动时默认模块不是监控,MonitorModule 的 onMounted 也会执行
// 从而在应用启动时自动创建 OSD 窗口(如果 OSD 配置已开启)
if (monitorEnabled.value) {
monitorComponent.value = await moduleRegistry.loadComponent('monitor')
}
const defaultModule = resolveDefaultModule()
activeModule.value = defaultModule
loadModule(defaultModule)
// 监听托盘菜单事件
// tray:toggle-osd 由 MonitorModule 直接监听(预渲染实例始终挂载)
trayUnlisteners.push(
await listen('tray:new-download', () => {
// 设置标志位,DownloaderModule 挂载后消费
pendingNewDownload.value = true
// 切换到下载模块(如果未启用则切换到设置)
const enabledIds = appStore.enabledModules.map(m => m.id)
if (enabledIds.includes('downloader') || moduleRegistry.getConfig('downloader')?.builtin) {
handleModuleChange('downloader')
}
})
)
trayUnlisteners.push(
await listen('tray:open-settings', () => {
pendingOpenSettings.value = true
handleModuleChange('settings')
})
)
})
const trayUnlisteners: UnlistenFn[] = []
onUnmounted(() => {
trayUnlisteners.forEach(fn => fn())
})
</script>
@@ -136,5 +180,10 @@ onMounted(async () => {
</div>
</div>
<Toaster position="bottom-right" rich-colors close-button :style="{ zIndex: 99999 }" />
<!-- 预渲染监控模块隐藏确保 OSD 窗口在应用启动时创建不依赖用户切换到监控模块
activeModule === 'monitor' 时不渲染 ModuleContainer 正常渲染避免重复实例 -->
<div v-if="monitorComponent && monitorEnabled && activeModule !== 'monitor'" style="display:none">
<component :is="monitorComponent" />
</div>
</TooltipProvider>
</template>