性能优化
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, onUnmounted, watch, nextTick } from 'vue'
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { open } from '@tauri-apps/plugin-dialog'
|
||||
import { toast } from 'vue-sonner'
|
||||
// Rust 端通过 tauri-specta 生成的命令绑定(bindings.ts)
|
||||
import { commands } from '@/lib/bindings'
|
||||
import { Command, Zap, Keyboard, Globe, Monitor, MousePointer2, FolderTree, RefreshCw, Plus, X, Loader2, Terminal, Pencil, Check } from '@lucide/vue'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useModuleTabsStore } from '@/stores/moduleTabsStore'
|
||||
import { setFileIndexReady, invalidateCustomCommandsCache } from './providers'
|
||||
import { STORAGE_KEYS } from '@/lib/constants'
|
||||
|
||||
interface CustomCommand {
|
||||
id: string
|
||||
@@ -44,7 +46,7 @@ const building = ref(false)
|
||||
|
||||
async function refreshStats() {
|
||||
try {
|
||||
indexStats.value = await invoke<IndexStats>('quickpanel_file_index_stats')
|
||||
indexStats.value = await commands.quickpanelFileIndexStats()
|
||||
// 索引存在(total > 0)即标记为就绪
|
||||
setFileIndexReady((indexStats.value?.total ?? 0) > 0)
|
||||
} catch (e) {
|
||||
@@ -56,7 +58,7 @@ async function buildIndex() {
|
||||
if (building.value) return
|
||||
building.value = true
|
||||
try {
|
||||
const count = await invoke<number>('quickpanel_build_file_index')
|
||||
const count = await commands.quickpanelBuildFileIndex()
|
||||
toast.success(`索引完成,共 ${count} 条`)
|
||||
await refreshStats()
|
||||
} catch (e) {
|
||||
@@ -88,7 +90,7 @@ function formatTime(t: number): string {
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const s = await invoke<QuickPanelSettings>('quickpanel_get_settings')
|
||||
const s = await commands.quickpanelGetSettings()
|
||||
Object.assign(form, s)
|
||||
} catch (e) {
|
||||
console.error('[quickpanel] 读取设置失败:', e)
|
||||
@@ -99,9 +101,9 @@ onMounted(async () => {
|
||||
// ===== 保存 =====
|
||||
async function saveSettings() {
|
||||
try {
|
||||
await invoke('quickpanel_save_settings', { settings: { ...form } })
|
||||
await commands.quickpanelSaveSettings({ ...form })
|
||||
// 同步到 localStorage 供独立窗口读取
|
||||
localStorage.setItem('thing_quickpanel_settings', JSON.stringify({ ...form }))
|
||||
localStorage.setItem(STORAGE_KEYS.quickpanelSettings, JSON.stringify({ ...form }))
|
||||
// 清除自定义命令缓存,使下次搜索重新加载
|
||||
invalidateCustomCommandsCache()
|
||||
toast.success('设置已保存')
|
||||
@@ -231,12 +233,14 @@ async function clearShortcut() {
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('keydown', onRecordKey, true)
|
||||
// 注销保存处理函数与标签状态,防止其他模块 activeTab=settings 时误执行本模块 saveSettings
|
||||
tabsStore.unregisterTabs()
|
||||
})
|
||||
|
||||
// ===== 唤起测试 =====
|
||||
async function testPopup() {
|
||||
try {
|
||||
await invoke('quickpanel_show_popup')
|
||||
await commands.quickpanelShowPopup()
|
||||
} catch (e) {
|
||||
console.error('[quickpanel] 唤起失败:', e)
|
||||
toast.error('唤起失败')
|
||||
|
||||
Reference in New Issue
Block a user