* 启动应用或插件(统一接口)
(options: {
path: string
type?: 'direct' | 'plugin' | 'builtin' | 'file'
featureCode?: string
param?: any
name?: string // cmd 名称(用于历史记录显示)
cmdType?: string // cmd 类型(用于判断是否添加历史记录)
confirmDialog?: ConfirmDialogOptions // 确认对话框配置
})
| 368 | * 启动应用或插件(统一接口) |
| 369 | */ |
| 370 | public async launch(options: { |
| 371 | path: string |
| 372 | type?: 'direct' | 'plugin' | 'builtin' | 'file' |
| 373 | featureCode?: string |
| 374 | param?: any |
| 375 | name?: string // cmd 名称(用于历史记录显示) |
| 376 | cmdType?: string // cmd 类型(用于判断是否添加历史记录) |
| 377 | confirmDialog?: ConfirmDialogOptions // 确认对话框配置 |
| 378 | }): Promise<any> { |
| 379 | const { path: appPath, type, param, name, cmdType, confirmDialog } = options |
| 380 | let { featureCode } = options |
| 381 | this.launchParam = param || {} |
| 382 | |
| 383 | try { |
| 384 | // 判断是插件还是直接启动 |
| 385 | if (type === 'plugin') { |
| 386 | if (pluginsAPI.isPluginDisabled(appPath)) { |
| 387 | return { success: false, error: '插件已禁用' } |
| 388 | } |
| 389 | // 如果没有传 featureCode,自动查找第一个非匹配 feature |
| 390 | if (!featureCode) { |
| 391 | const result = await this.getDefaultFeatureCode(appPath) |
| 392 | if (!result.success) { |
| 393 | // 返回错误给前端 |
| 394 | return { success: false, error: result.error } |
| 395 | } |
| 396 | featureCode = result.featureCode |
| 397 | } |
| 398 | |
| 399 | // 插件启动参数中添加 featureCode |
| 400 | this.launchParam.code = featureCode || '' |
| 401 | |
| 402 | console.log('[Commands] 启动插件:', { |
| 403 | path: appPath, |
| 404 | featureCode, |
| 405 | name, |
| 406 | launchParam: this.launchParam |
| 407 | }) |
| 408 | |
| 409 | // 更新指令使用统计(所有指令都统计,用于匹配推荐排序) |
| 410 | this.updateUsageStats({ path: appPath, type, featureCode, name }) |
| 411 | |
| 412 | // 判断命令类型并决定是否添加历史记录 |
| 413 | if (cmdType === 'window') { |
| 414 | // window 类型:不记录历史,不保存状态(仅用于窗口匹配) |
| 415 | console.log('[Commands] window 类型命令,跳过历史记录') |
| 416 | } else if (['img', 'over', 'files', 'regex'].includes(cmdType || '')) { |
| 417 | // 匹配指令:保存状态并添加"上次匹配"到历史记录 |
| 418 | // 从param中提取完整的输入状态 |
| 419 | const inputState = param?.inputState || {} |
| 420 | |
| 421 | if (param?.inputState) { |
| 422 | // 保存上次匹配状态(内存+数据库) |
| 423 | this.lastMatchState = { |
| 424 | searchQuery: inputState.searchQuery || '', |
| 425 | pastedImage: inputState.pastedImage || null, |
| 426 | pastedFiles: inputState.pastedFiles || null, |
| 427 | pastedText: inputState.pastedText || null, |
no test coverage detected