* 获取所有指令(供 AllCommands 页面和设置页 alias 目标选择使用) * 返回处理后的 commands、regexCommands 和 plugins * 结果会被缓存,直到应用列表、插件状态或 alias 映射发生变化时清除
()
| 1051 | * 结果会被缓存,直到应用列表、插件状态或 alias 映射发生变化时清除 |
| 1052 | */ |
| 1053 | public async getCommands(): Promise<{ |
| 1054 | commands: any[] |
| 1055 | regexCommands: any[] |
| 1056 | plugins: any[] |
| 1057 | }> { |
| 1058 | // 命中缓存直接返回 |
| 1059 | if (this.cachedCommandsResult) { |
| 1060 | console.log('[Commands] 命中指令缓存,直接返回 getCommands 结果') |
| 1061 | return this.cachedCommandsResult |
| 1062 | } |
| 1063 | |
| 1064 | console.log('[Commands] 指令缓存未命中,开始重建 getCommands 结果') |
| 1065 | try { |
| 1066 | const rawApps = await this.getApps() |
| 1067 | |
| 1068 | // 调用 pluginsAPI 获取所有插件列表(包括 system 插件) |
| 1069 | const plugins = await pluginsAPI.getAllPlugins() |
| 1070 | |
| 1071 | const commands: any[] = [] |
| 1072 | const regexCommands: any[] = [] |
| 1073 | |
| 1074 | // 处理应用指令 |
| 1075 | for (const app of rawApps) { |
| 1076 | commands.push({ |
| 1077 | name: app.name, |
| 1078 | path: app.path, |
| 1079 | icon: app.icon, |
| 1080 | type: 'direct', |
| 1081 | subType: 'app' |
| 1082 | }) |
| 1083 | } |
| 1084 | |
| 1085 | // 调用 systemSettingsAPI 获取系统设置指令 |
| 1086 | const systemSettings = await systemSettingsAPI.getSystemSettings() |
| 1087 | for (const setting of systemSettings) { |
| 1088 | commands.push({ |
| 1089 | name: setting.name, |
| 1090 | path: setting.uri, |
| 1091 | icon: undefined, // 图标由前端统一渲染 |
| 1092 | type: 'direct', |
| 1093 | subType: 'system-setting' |
| 1094 | }) |
| 1095 | } |
| 1096 | |
| 1097 | // 处理本地启动项 |
| 1098 | try { |
| 1099 | const localShortcuts = databaseAPI.dbGet('local-shortcuts') |
| 1100 | if (localShortcuts && Array.isArray(localShortcuts)) { |
| 1101 | for (const shortcut of localShortcuts) { |
| 1102 | commands.push({ |
| 1103 | name: shortcut.alias || shortcut.name, |
| 1104 | path: shortcut.path, |
| 1105 | icon: shortcut.icon || '', |
| 1106 | type: 'direct', |
| 1107 | subType: 'local-shortcut' |
| 1108 | }) |
| 1109 | } |
| 1110 | } |
no test coverage detected