* 注册仅允许内置插件访问的 IPC 能力。
()
| 83 | * 注册仅允许内置插件访问的 IPC 能力。 |
| 84 | */ |
| 85 | private setupIPC(): void { |
| 86 | // ==================== 数据库 API (ZTOOLS/ 命名空间) ==================== |
| 87 | ipcMain.handle('internal:db-put', (event, key: string, value: any) => { |
| 88 | if (!requireInternalPlugin(this.pluginManager, event)) { |
| 89 | throw new PermissionDeniedError('internal:db-put') |
| 90 | } |
| 91 | return databaseAPI.dbPut(key, value) |
| 92 | }) |
| 93 | |
| 94 | ipcMain.handle('internal:db-get', (event, key: string) => { |
| 95 | if (!requireInternalPlugin(this.pluginManager, event)) { |
| 96 | throw new PermissionDeniedError('internal:db-get') |
| 97 | } |
| 98 | return databaseAPI.dbGet(key) |
| 99 | }) |
| 100 | |
| 101 | // ==================== 应用启动 API ==================== |
| 102 | ipcMain.handle('internal:launch', async (event, options: any) => { |
| 103 | if (!requireInternalPlugin(this.pluginManager, event)) { |
| 104 | throw new PermissionDeniedError('internal:launch') |
| 105 | } |
| 106 | console.log('[Internal] 启动应用', options) |
| 107 | return await commandsAPI.launch(options) |
| 108 | }) |
| 109 | |
| 110 | ipcMain.handle('internal:quit-app', async (event) => { |
| 111 | if (!requireInternalPlugin(this.pluginManager, event)) { |
| 112 | throw new PermissionDeniedError('internal:quit-app') |
| 113 | } |
| 114 | // 与托盘「退出」一致:设置退出标志后再 quit,否则 before-quit 会阻止并只隐藏窗口 |
| 115 | windowManager.setQuitting(true) |
| 116 | app.quit() |
| 117 | return { success: true } |
| 118 | }) |
| 119 | |
| 120 | // ==================== 指令管理 API ==================== |
| 121 | ipcMain.handle('internal:get-commands', async (event) => { |
| 122 | if (!requireInternalPlugin(this.pluginManager, event)) { |
| 123 | throw new PermissionDeniedError('internal:get-commands') |
| 124 | } |
| 125 | |
| 126 | // 设置页使用这份 canonical commands 构建 alias 目标列表,不在这里展开 alias 搜索字段。 |
| 127 | console.log('[Internal] 收到获取指令列表请求(设置页 alias 目标)') |
| 128 | const result = await commandsAPI.getCommands() |
| 129 | console.log('[Internal] 返回指令列表摘要:', { |
| 130 | commands: result.commands?.length || 0, |
| 131 | regexCommands: result.regexCommands?.length || 0, |
| 132 | plugins: result.plugins?.length || 0 |
| 133 | }) |
| 134 | return result |
| 135 | }) |
| 136 | |
| 137 | ipcMain.handle('internal:update-command-aliases', async (event, aliases: CommandAliasStore) => { |
| 138 | if (!requireInternalPlugin(this.pluginManager, event)) { |
| 139 | throw new PermissionDeniedError('internal:update-command-aliases') |
| 140 | } |
| 141 | |
| 142 | const inputCommandCount = Object.keys(aliases || {}).length |
no test coverage detected