性能优化
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { moduleRegistry } from '@/modules/registry'
|
||||
import { useAppStore } from '@/stores/appStore'
|
||||
import { STORAGE_KEYS } from '@/lib/constants'
|
||||
// Rust 端通过 tauri-specta 生成的命令绑定(bindings.ts)
|
||||
import { commands } from '@/lib/bindings'
|
||||
|
||||
/** 快速面板状态:命令缓存与设置的跨窗口同步(写入 localStorage 供独立弹窗读取) */
|
||||
export const useQuickPanelStore = defineStore('quickpanel', () => {
|
||||
/** 将已启用模块的命令缓存写入 localStorage(供独立弹窗窗口读取) */
|
||||
const syncCommands = () => {
|
||||
const appStore = useAppStore()
|
||||
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(STORAGE_KEYS.quickpanelCommands, JSON.stringify(commands))
|
||||
}
|
||||
|
||||
/** 将快速面板设置写入 localStorage(供独立窗口的 web provider 读取搜索引擎) */
|
||||
const syncSettings = async () => {
|
||||
try {
|
||||
const s = await commands.quickpanelGetSettings()
|
||||
localStorage.setItem(STORAGE_KEYS.quickpanelSettings, JSON.stringify(s))
|
||||
} catch (e) {
|
||||
console.error('[quickpanel] 同步设置失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
return { syncCommands, syncSettings }
|
||||
})
|
||||
Reference in New Issue
Block a user