快速面板模块

This commit is contained in:
zhongluofeng
2026-08-04 13:37:42 +08:00
parent 5656193b5c
commit 126f8896b6
23 changed files with 4048 additions and 52 deletions
+60
View File
@@ -1,6 +1,8 @@
<script setup lang="ts">
import { ref, onMounted, onUnmounted, shallowRef, computed, watch, type Component } from 'vue'
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
import { invoke } from '@tauri-apps/api/core'
import { getCurrentWindow } from '@tauri-apps/api/window'
import TitleBar from '@/components/layout/TitleBar.vue'
import Sidebar from '@/components/layout/Sidebar.vue'
import ModuleContainer from '@/components/layout/ModuleContainer.vue'
@@ -105,8 +107,48 @@ watch(() => appStore.enabledModules.length, () => {
activeModule.value = fallback
loadModule(fallback)
}
// 模块启用/禁用变化时重新同步快速面板命令缓存
syncQuickPanelCommands()
})
/** 同步快速面板命令缓存到 localStorage(供独立窗口读取) */
function syncQuickPanelCommands() {
const enabledIds = appStore.enabledModules.map(m => m.id)
const all = moduleRegistry.getAllSearchItems()
const commands: Array<{
moduleId: string
moduleName: string
title: string
description?: string
keywords: string[]
}> = []
for (const { moduleId, items } of all) {
const config = moduleRegistry.getConfig(moduleId)
// 内置模块或已启用模块的搜索项才收录
if (!config?.builtin && !enabledIds.includes(moduleId)) continue
for (const item of items) {
commands.push({
moduleId,
moduleName: config?.name ?? moduleId,
title: item.title,
description: item.description,
keywords: item.keywords,
})
}
}
localStorage.setItem('thing_quickpanel_commands', JSON.stringify(commands))
}
/** 同步快速面板设置到 localStorage(供独立窗口的 web provider 读取搜索引擎) */
async function syncQuickPanelSettings() {
try {
const s = await invoke<{ shortcut: string; popupPosition: string; searchEngine: string; indexDirs: string[]; customCommands: unknown[] }>('quickpanel_get_settings')
localStorage.setItem('thing_quickpanel_settings', JSON.stringify(s))
} catch (e) {
console.error('[quickpanel] 同步设置失败:', e)
}
}
/** 计算启动时应打开的默认模块:优先上次记忆,其次排序第一个 */
const resolveDefaultModule = (): string => {
const enabledIds = appStore.enabledModules.map(m => m.id)
@@ -140,6 +182,24 @@ onMounted(async () => {
activeModule.value = defaultModule
loadModule(defaultModule)
// 快速面板:同步命令缓存与设置到 localStorage,供独立窗口读取
syncQuickPanelCommands()
syncQuickPanelSettings()
// 监听快速面板执行命令事件:显示主窗口 + 切换模块
trayUnlisteners.push(
await listen<{ moduleId: string }>('quickpanel-execute-command', async (e) => {
const win = getCurrentWindow()
try {
await win.show()
await win.unminimize()
await win.setFocus()
} catch {
/* 忽略窗口操作失败 */
}
handleSearch(e.payload.moduleId)
})
)
// 监听托盘菜单事件
// tray:toggle-osd 由 MonitorModule 直接监听(预渲染实例始终挂载)
trayUnlisteners.push(