MCPcopy
hub / github.com/ZToolsCenter/ZTools / loadHistoryData

Function loadHistoryData

src/renderer/src/stores/commandDataStore.ts:576–629  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

574
575 // 加载历史记录数据
576 async function loadHistoryData(): Promise<void> {
577 try {
578 const data = await window.ztools.dbGet(HISTORY_DOC_ID)
579
580 if (data && Array.isArray(data)) {
581 // 创建当前所有指令的 path Set(用于验证历史记录是否仍然有效)
582 const currentCommandPaths = new Set(commands.value.map((cmd) => cmd.path))
583
584 // 过滤掉已卸载的插件、无效的指令,并清理系统设置的旧图标路径
585 const filteredData = data
586 .filter((item: any) => {
587 // 特殊指令不检查,直接保留
588 if (item.path === 'special:last-match') {
589 return true
590 }
591
592 // 检查所有类型的历史记录(包括插件、应用、系统设置等)
593 // 如果在当前指令列表中找不到,就清理掉
594 if (!currentCommandPaths.has(item.path)) return false
595
596 return true
597 })
598 .map((item: any) => {
599 const cleanedItem = { ...item }
600
601 // 1. 迁移旧的系统设置数据格式:type: "system-setting" -> type: "direct", subType: "system-setting"
602 if (item.type === 'system-setting') {
603 cleanedItem.type = 'direct'
604 cleanedItem.subType = 'system-setting'
605 }
606
607 // 2. 清理系统设置和特殊指令的旧图标路径
608 if (
609 (cleanedItem.type === 'direct' && cleanedItem.subType === 'system-setting') ||
610 cleanedItem.path?.startsWith('special:')
611 ) {
612 if (cleanedItem.icon) {
613 delete cleanedItem.icon
614 }
615 }
616
617 return cleanedItem
618 })
619
620 // 直接赋值,避免先清空再设置导致的闪烁
621 history.value = filteredData
622 } else {
623 history.value = []
624 }
625 } catch (error) {
626 console.error('加载历史记录失败:', error)
627 history.value = []
628 }
629 }
630
631 // 加载固定列表数据
632 async function loadPinnedData(): Promise<void> {

Callers 2

initializeDataFunction · 0.85
reloadUserDataFunction · 0.85

Calls 1

dbGetMethod · 0.45

Tested by

no test coverage detected