@huyooo/ai-chat-bridge-electron 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/index.cjs +243 -23
- package/dist/main/index.d.cts +31 -5
- package/dist/main/index.d.ts +31 -5
- package/dist/main/index.js +235 -24
- package/dist/preload/index.cjs +58 -4
- package/dist/preload/index.d.cts +152 -19
- package/dist/preload/index.d.ts +152 -19
- package/dist/preload/index.js +58 -4
- package/dist/renderer/index.cjs +90 -17
- package/dist/renderer/index.d.cts +282 -46
- package/dist/renderer/index.d.ts +282 -46
- package/dist/renderer/index.js +90 -17
- package/package.json +9 -4
- package/src/main/index.ts +611 -0
- package/src/preload/index.ts +457 -0
- package/src/renderer/index.ts +507 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Electron Preload 桥接
|
|
3
|
+
*
|
|
4
|
+
* 在 preload 脚本中调用,暴露 API 给渲染进程
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { contextBridge, ipcRenderer } from 'electron';
|
|
8
|
+
|
|
9
|
+
/** 发送消息参数 */
|
|
10
|
+
interface SendMessageParams {
|
|
11
|
+
message: string;
|
|
12
|
+
images?: string[];
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
options?: {
|
|
15
|
+
mode?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
provider?: string;
|
|
18
|
+
enableWebSearch?: boolean;
|
|
19
|
+
thinkingMode?: string;
|
|
20
|
+
thinkingBudget?: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 模型配置 */
|
|
25
|
+
interface ModelOption {
|
|
26
|
+
modelId: string;
|
|
27
|
+
displayName: string;
|
|
28
|
+
/** 分组名称(由后端决定,前端只负责渲染,必填) */
|
|
29
|
+
group: string;
|
|
30
|
+
/** 是否来自 OpenRouter(保留用于兼容,后续可能移除) */
|
|
31
|
+
isOpenRouter?: boolean;
|
|
32
|
+
/** 提供商名称(保留用于兼容,后续可能移除) */
|
|
33
|
+
provider?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 会话记录 */
|
|
37
|
+
interface SessionRecord {
|
|
38
|
+
id: string;
|
|
39
|
+
appId: string | null;
|
|
40
|
+
userId: string | null;
|
|
41
|
+
title: string;
|
|
42
|
+
model: string;
|
|
43
|
+
mode: 'agent' | 'plan' | 'ask';
|
|
44
|
+
webSearchEnabled: boolean;
|
|
45
|
+
thinkingEnabled: boolean;
|
|
46
|
+
/** 是否在 tab 栏隐藏(关闭但不删除) */
|
|
47
|
+
hidden: boolean;
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
updatedAt: Date;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 消息记录 */
|
|
53
|
+
interface MessageRecord {
|
|
54
|
+
id: string;
|
|
55
|
+
sessionId: string;
|
|
56
|
+
role: 'user' | 'assistant';
|
|
57
|
+
content: string;
|
|
58
|
+
/** 生成此消息时使用的模型 */
|
|
59
|
+
model?: string | null;
|
|
60
|
+
/** 生成此消息时使用的模式 (ask/agent) */
|
|
61
|
+
mode?: string | null;
|
|
62
|
+
/** 生成此消息时是否启用 web 搜索 */
|
|
63
|
+
webSearchEnabled?: boolean | null;
|
|
64
|
+
/** 生成此消息时是否启用深度思考 */
|
|
65
|
+
thinkingEnabled?: boolean | null;
|
|
66
|
+
/** 执行步骤列表 JSON */
|
|
67
|
+
steps?: string | null;
|
|
68
|
+
operationIds?: string | null;
|
|
69
|
+
timestamp: Date;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 操作记录 */
|
|
73
|
+
interface OperationRecord {
|
|
74
|
+
id: string;
|
|
75
|
+
sessionId: string;
|
|
76
|
+
messageId?: string | null;
|
|
77
|
+
command: string;
|
|
78
|
+
operationType: string;
|
|
79
|
+
affectedFiles: string;
|
|
80
|
+
status: string;
|
|
81
|
+
timestamp: Date;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** 回收站记录 */
|
|
85
|
+
interface TrashRecord {
|
|
86
|
+
id: string;
|
|
87
|
+
sessionId: string;
|
|
88
|
+
originalPath: string;
|
|
89
|
+
trashPath: string;
|
|
90
|
+
deletedAt: Date;
|
|
91
|
+
autoDeleteAt: Date;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 文件信息 */
|
|
95
|
+
interface FileInfo {
|
|
96
|
+
name: string;
|
|
97
|
+
path: string;
|
|
98
|
+
isDirectory: boolean;
|
|
99
|
+
size: number;
|
|
100
|
+
modifiedAt: Date;
|
|
101
|
+
extension: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface AiChatBridge {
|
|
105
|
+
// ============ Chat API ============
|
|
106
|
+
/** 获取可用模型 */
|
|
107
|
+
getModels(): Promise<ModelOption[]>;
|
|
108
|
+
/** 发送消息 */
|
|
109
|
+
send(params: SendMessageParams): Promise<void>;
|
|
110
|
+
/** 取消当前请求 */
|
|
111
|
+
cancel(): Promise<void>;
|
|
112
|
+
// 无状态架构:历史通过 ChatOptions.history 传入
|
|
113
|
+
/** 设置当前工作目录 */
|
|
114
|
+
setCwd(dir: string): Promise<void>;
|
|
115
|
+
/** 获取配置 */
|
|
116
|
+
getConfig(): Promise<unknown>;
|
|
117
|
+
/** 监听进度事件 */
|
|
118
|
+
onProgress(callback: (progress: unknown) => void): () => void;
|
|
119
|
+
|
|
120
|
+
// ============ Sessions API ============
|
|
121
|
+
/** 获取会话列表 */
|
|
122
|
+
getSessions(): Promise<SessionRecord[]>;
|
|
123
|
+
/** 获取单个会话 */
|
|
124
|
+
getSession(id: string): Promise<SessionRecord | null>;
|
|
125
|
+
/** 创建会话 */
|
|
126
|
+
createSession(params?: { title?: string; model?: string; mode?: string; webSearchEnabled?: boolean; thinkingEnabled?: boolean; hidden?: boolean }): Promise<SessionRecord>;
|
|
127
|
+
/** 更新会话 */
|
|
128
|
+
updateSession(id: string, data: { title?: string; model?: string; mode?: string; webSearchEnabled?: boolean; thinkingEnabled?: boolean; hidden?: boolean }): Promise<SessionRecord | null>;
|
|
129
|
+
/** 删除会话 */
|
|
130
|
+
deleteSession(id: string): Promise<{ success: boolean }>;
|
|
131
|
+
|
|
132
|
+
// ============ Messages API ============
|
|
133
|
+
/** 获取会话消息 */
|
|
134
|
+
getMessages(sessionId: string): Promise<MessageRecord[]>;
|
|
135
|
+
/** 保存消息 */
|
|
136
|
+
saveMessage(params: {
|
|
137
|
+
/** 消息 ID(可选,如果不传则自动生成) */
|
|
138
|
+
id?: string;
|
|
139
|
+
sessionId: string;
|
|
140
|
+
role: 'user' | 'assistant';
|
|
141
|
+
content: string;
|
|
142
|
+
/** 生成此消息时使用的模型 */
|
|
143
|
+
model?: string;
|
|
144
|
+
/** 生成此消息时使用的模式 (ask/agent) */
|
|
145
|
+
mode?: string;
|
|
146
|
+
/** 生成此消息时是否启用 web 搜索 */
|
|
147
|
+
webSearchEnabled?: boolean;
|
|
148
|
+
/** 生成此消息时是否启用深度思考 */
|
|
149
|
+
thinkingEnabled?: boolean;
|
|
150
|
+
/** 执行步骤列表 JSON */
|
|
151
|
+
steps?: string;
|
|
152
|
+
operationIds?: string;
|
|
153
|
+
}): Promise<MessageRecord>;
|
|
154
|
+
/** 更新消息(增量保存) */
|
|
155
|
+
updateMessage(params: {
|
|
156
|
+
id: string;
|
|
157
|
+
content?: string;
|
|
158
|
+
steps?: string;
|
|
159
|
+
}): Promise<{ success: boolean }>;
|
|
160
|
+
/** 删除指定时间之后的消息(用于分叉) */
|
|
161
|
+
deleteMessagesAfter(sessionId: string, timestamp: number): Promise<{ success: boolean }>;
|
|
162
|
+
|
|
163
|
+
// ============ Operations API ============
|
|
164
|
+
/** 获取操作日志 */
|
|
165
|
+
getOperations(sessionId: string): Promise<OperationRecord[]>;
|
|
166
|
+
|
|
167
|
+
// ============ Trash API ============
|
|
168
|
+
/** 获取回收站 */
|
|
169
|
+
getTrashItems(): Promise<TrashRecord[]>;
|
|
170
|
+
/** 恢复回收站项目 */
|
|
171
|
+
restoreFromTrash(id: string): Promise<TrashRecord | undefined>;
|
|
172
|
+
|
|
173
|
+
// ============ System API ============
|
|
174
|
+
/** 在系统默认浏览器中打开链接 */
|
|
175
|
+
openExternal(url: string): Promise<void>;
|
|
176
|
+
|
|
177
|
+
// ============ File System API ============
|
|
178
|
+
/** 列出目录内容 */
|
|
179
|
+
listDir(dirPath: string): Promise<FileInfo[]>;
|
|
180
|
+
/** 检查路径是否存在 */
|
|
181
|
+
exists(filePath: string): Promise<boolean>;
|
|
182
|
+
/** 获取文件信息 */
|
|
183
|
+
stat(filePath: string): Promise<FileInfo | null>;
|
|
184
|
+
/** 读取文件内容(文本) */
|
|
185
|
+
readFile(filePath: string): Promise<string | null>;
|
|
186
|
+
/** 读取文件为 base64 */
|
|
187
|
+
readFileBase64(filePath: string): Promise<string | null>;
|
|
188
|
+
/** 获取用户主目录 */
|
|
189
|
+
homeDir(): Promise<string>;
|
|
190
|
+
/** 解析路径(处理 ~) */
|
|
191
|
+
resolvePath(inputPath: string): Promise<string>;
|
|
192
|
+
/** 获取父目录 */
|
|
193
|
+
parentDir(dirPath: string): Promise<string>;
|
|
194
|
+
/** 监听目录变化 */
|
|
195
|
+
watchDir(dirPath: string): Promise<boolean>;
|
|
196
|
+
/** 停止监听目录 */
|
|
197
|
+
unwatchDir(dirPath: string): Promise<void>;
|
|
198
|
+
/** 监听目录变化事件 */
|
|
199
|
+
onDirChange(callback: (data: { dirPath: string; eventType: string; filename: string | null }) => void): () => void;
|
|
200
|
+
|
|
201
|
+
// ============ Settings API ============
|
|
202
|
+
/** 获取用户设置 */
|
|
203
|
+
getSetting(key: string): Promise<string | null>;
|
|
204
|
+
/** 设置用户设置 */
|
|
205
|
+
setSetting(key: string, value: string): Promise<{ success: boolean }>;
|
|
206
|
+
/** 获取所有用户设置 */
|
|
207
|
+
getAllSettings(): Promise<Record<string, string>>;
|
|
208
|
+
/** 删除用户设置 */
|
|
209
|
+
deleteSetting(key: string): Promise<{ success: boolean }>;
|
|
210
|
+
|
|
211
|
+
// ============ Index API ============
|
|
212
|
+
/** 获取索引统计信息 */
|
|
213
|
+
getIndexStats(): Promise<{
|
|
214
|
+
totalDocuments: number;
|
|
215
|
+
indexSize: number;
|
|
216
|
+
lastUpdated: string | null;
|
|
217
|
+
}>;
|
|
218
|
+
/** 检查索引状态 */
|
|
219
|
+
getIndexStatus(): Promise<{
|
|
220
|
+
isIndexing: boolean;
|
|
221
|
+
lastProgress: {
|
|
222
|
+
indexed: number;
|
|
223
|
+
total: number;
|
|
224
|
+
currentFile?: string;
|
|
225
|
+
stage: string;
|
|
226
|
+
} | null;
|
|
227
|
+
}>;
|
|
228
|
+
/** 同步索引(重新索引工作空间) */
|
|
229
|
+
syncIndex(): Promise<{ success: boolean }>;
|
|
230
|
+
/** 取消索引 */
|
|
231
|
+
cancelIndex(): Promise<{ success: boolean }>;
|
|
232
|
+
/** 删除索引 */
|
|
233
|
+
deleteIndex(): Promise<{ success: boolean }>;
|
|
234
|
+
/** 注册索引进度监听器 */
|
|
235
|
+
registerIndexListener(): Promise<{ success: boolean }>;
|
|
236
|
+
/** 注销索引进度监听器 */
|
|
237
|
+
unregisterIndexListener(): Promise<{ success: boolean }>;
|
|
238
|
+
/** 监听索引进度 */
|
|
239
|
+
onIndexProgress(callback: (progress: {
|
|
240
|
+
indexed: number;
|
|
241
|
+
total: number;
|
|
242
|
+
currentFile?: string;
|
|
243
|
+
stage: string;
|
|
244
|
+
error?: string;
|
|
245
|
+
}) => void): () => void;
|
|
246
|
+
|
|
247
|
+
// ============ Tool Approval API ============
|
|
248
|
+
/** 监听工具批准请求(manual 模式) */
|
|
249
|
+
onToolApprovalRequest(callback: (request: { id: string; name: string; args: Record<string, unknown> }) => void): () => void;
|
|
250
|
+
/** 响应工具批准请求 */
|
|
251
|
+
respondToolApproval(id: string, approved: boolean): Promise<void>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface ExposeOptions {
|
|
255
|
+
/** IPC channel 前缀 */
|
|
256
|
+
channelPrefix?: string;
|
|
257
|
+
/** 暴露的全局变量名 */
|
|
258
|
+
exposeName?: string;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* 暴露 AI Chat API 给渲染进程
|
|
263
|
+
*/
|
|
264
|
+
export function exposeElectronBridge(options: ExposeOptions = {}) {
|
|
265
|
+
const { channelPrefix = 'ai-chat', exposeName = 'aiChatBridge' } = options;
|
|
266
|
+
|
|
267
|
+
const bridge: AiChatBridge = {
|
|
268
|
+
// ============ Chat API ============
|
|
269
|
+
getModels: () =>
|
|
270
|
+
ipcRenderer.invoke(`${channelPrefix}:models`),
|
|
271
|
+
|
|
272
|
+
send: (params: SendMessageParams) =>
|
|
273
|
+
ipcRenderer.invoke(`${channelPrefix}:send`, params),
|
|
274
|
+
|
|
275
|
+
cancel: () =>
|
|
276
|
+
ipcRenderer.invoke(`${channelPrefix}:cancel`),
|
|
277
|
+
|
|
278
|
+
// 无状态架构:历史通过 ChatOptions.history 传入
|
|
279
|
+
|
|
280
|
+
setCwd: (dir: string) =>
|
|
281
|
+
ipcRenderer.invoke(`${channelPrefix}:setCwd`, dir),
|
|
282
|
+
|
|
283
|
+
getConfig: () =>
|
|
284
|
+
ipcRenderer.invoke(`${channelPrefix}:config`),
|
|
285
|
+
|
|
286
|
+
onProgress: (callback: (progress: unknown) => void) => {
|
|
287
|
+
const handler = (_event: Electron.IpcRendererEvent, progress: unknown) => {
|
|
288
|
+
callback(progress);
|
|
289
|
+
};
|
|
290
|
+
ipcRenderer.on(`${channelPrefix}:progress`, handler);
|
|
291
|
+
|
|
292
|
+
return () => {
|
|
293
|
+
ipcRenderer.removeListener(`${channelPrefix}:progress`, handler);
|
|
294
|
+
};
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
onToolApprovalRequest: (callback: (request: { id: string; name: string; args: Record<string, unknown> }) => void) => {
|
|
298
|
+
const handler = (_event: Electron.IpcRendererEvent, request: { id: string; name: string; args: Record<string, unknown> }) => {
|
|
299
|
+
callback(request);
|
|
300
|
+
};
|
|
301
|
+
ipcRenderer.on(`${channelPrefix}:toolApprovalRequest`, handler);
|
|
302
|
+
|
|
303
|
+
return () => {
|
|
304
|
+
ipcRenderer.removeListener(`${channelPrefix}:toolApprovalRequest`, handler);
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
respondToolApproval: (id: string, approved: boolean) =>
|
|
309
|
+
ipcRenderer.invoke(`${channelPrefix}:toolApprovalResponse`, { id, approved }),
|
|
310
|
+
|
|
311
|
+
// ============ Sessions API ============
|
|
312
|
+
getSessions: () =>
|
|
313
|
+
ipcRenderer.invoke(`${channelPrefix}:sessions:list`),
|
|
314
|
+
|
|
315
|
+
getSession: (id: string) =>
|
|
316
|
+
ipcRenderer.invoke(`${channelPrefix}:sessions:get`, id),
|
|
317
|
+
|
|
318
|
+
createSession: (params) =>
|
|
319
|
+
ipcRenderer.invoke(`${channelPrefix}:sessions:create`, params || {}),
|
|
320
|
+
|
|
321
|
+
updateSession: (id: string, data) =>
|
|
322
|
+
ipcRenderer.invoke(`${channelPrefix}:sessions:update`, id, data),
|
|
323
|
+
|
|
324
|
+
deleteSession: (id: string) =>
|
|
325
|
+
ipcRenderer.invoke(`${channelPrefix}:sessions:delete`, id),
|
|
326
|
+
|
|
327
|
+
// ============ Messages API ============
|
|
328
|
+
getMessages: (sessionId: string) =>
|
|
329
|
+
ipcRenderer.invoke(`${channelPrefix}:messages:list`, sessionId),
|
|
330
|
+
|
|
331
|
+
saveMessage: (params) =>
|
|
332
|
+
ipcRenderer.invoke(`${channelPrefix}:messages:save`, params),
|
|
333
|
+
|
|
334
|
+
updateMessage: (params) =>
|
|
335
|
+
ipcRenderer.invoke(`${channelPrefix}:messages:update`, params),
|
|
336
|
+
|
|
337
|
+
deleteMessagesAfter: (sessionId: string, timestamp: number) =>
|
|
338
|
+
ipcRenderer.invoke(`${channelPrefix}:messages:deleteAfter`, sessionId, timestamp),
|
|
339
|
+
|
|
340
|
+
// ============ Operations API ============
|
|
341
|
+
getOperations: (sessionId: string) =>
|
|
342
|
+
ipcRenderer.invoke(`${channelPrefix}:operations:list`, sessionId),
|
|
343
|
+
|
|
344
|
+
// ============ Trash API ============
|
|
345
|
+
getTrashItems: () =>
|
|
346
|
+
ipcRenderer.invoke(`${channelPrefix}:trash:list`),
|
|
347
|
+
|
|
348
|
+
restoreFromTrash: (id: string) =>
|
|
349
|
+
ipcRenderer.invoke(`${channelPrefix}:trash:restore`, id),
|
|
350
|
+
|
|
351
|
+
// ============ System API ============
|
|
352
|
+
openExternal: (url: string) =>
|
|
353
|
+
ipcRenderer.invoke(`${channelPrefix}:openExternal`, url),
|
|
354
|
+
|
|
355
|
+
// ============ File System API ============
|
|
356
|
+
listDir: (dirPath: string) =>
|
|
357
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:listDir`, dirPath),
|
|
358
|
+
|
|
359
|
+
exists: (filePath: string) =>
|
|
360
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:exists`, filePath),
|
|
361
|
+
|
|
362
|
+
stat: (filePath: string) =>
|
|
363
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:stat`, filePath),
|
|
364
|
+
|
|
365
|
+
readFile: (filePath: string) =>
|
|
366
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:readFile`, filePath),
|
|
367
|
+
|
|
368
|
+
readFileBase64: (filePath: string) =>
|
|
369
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:readFileBase64`, filePath),
|
|
370
|
+
|
|
371
|
+
homeDir: () =>
|
|
372
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:homeDir`),
|
|
373
|
+
|
|
374
|
+
resolvePath: (inputPath: string) =>
|
|
375
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:resolvePath`, inputPath),
|
|
376
|
+
|
|
377
|
+
parentDir: (dirPath: string) =>
|
|
378
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:parentDir`, dirPath),
|
|
379
|
+
|
|
380
|
+
watchDir: (dirPath: string) =>
|
|
381
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:watchDir`, dirPath),
|
|
382
|
+
|
|
383
|
+
unwatchDir: (dirPath: string) =>
|
|
384
|
+
ipcRenderer.invoke(`${channelPrefix}:fs:unwatchDir`, dirPath),
|
|
385
|
+
|
|
386
|
+
onDirChange: (callback: (data: { dirPath: string; eventType: string; filename: string | null }) => void) => {
|
|
387
|
+
const handler = (_event: Electron.IpcRendererEvent, data: { dirPath: string; eventType: string; filename: string | null }) => {
|
|
388
|
+
callback(data);
|
|
389
|
+
};
|
|
390
|
+
ipcRenderer.on(`${channelPrefix}:fs:dirChange`, handler);
|
|
391
|
+
|
|
392
|
+
return () => {
|
|
393
|
+
ipcRenderer.removeListener(`${channelPrefix}:fs:dirChange`, handler);
|
|
394
|
+
};
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
// ============ Settings API ============
|
|
398
|
+
getSetting: (key: string) =>
|
|
399
|
+
ipcRenderer.invoke(`${channelPrefix}:settings:get`, key),
|
|
400
|
+
|
|
401
|
+
setSetting: (key: string, value: string) =>
|
|
402
|
+
ipcRenderer.invoke(`${channelPrefix}:settings:set`, key, value),
|
|
403
|
+
|
|
404
|
+
getAllSettings: () =>
|
|
405
|
+
ipcRenderer.invoke(`${channelPrefix}:settings:getAll`),
|
|
406
|
+
|
|
407
|
+
deleteSetting: (key: string) =>
|
|
408
|
+
ipcRenderer.invoke(`${channelPrefix}:settings:delete`, key),
|
|
409
|
+
|
|
410
|
+
// ============ Index API ============
|
|
411
|
+
getIndexStats: () =>
|
|
412
|
+
ipcRenderer.invoke(`${channelPrefix}:index:getStats`),
|
|
413
|
+
|
|
414
|
+
getIndexStatus: () =>
|
|
415
|
+
ipcRenderer.invoke(`${channelPrefix}:index:status`),
|
|
416
|
+
|
|
417
|
+
syncIndex: () =>
|
|
418
|
+
ipcRenderer.invoke(`${channelPrefix}:index:sync`),
|
|
419
|
+
|
|
420
|
+
cancelIndex: () =>
|
|
421
|
+
ipcRenderer.invoke(`${channelPrefix}:index:cancel`),
|
|
422
|
+
|
|
423
|
+
deleteIndex: () =>
|
|
424
|
+
ipcRenderer.invoke(`${channelPrefix}:index:delete`),
|
|
425
|
+
|
|
426
|
+
registerIndexListener: () =>
|
|
427
|
+
ipcRenderer.invoke(`${channelPrefix}:index:registerListener`),
|
|
428
|
+
|
|
429
|
+
unregisterIndexListener: () =>
|
|
430
|
+
ipcRenderer.invoke(`${channelPrefix}:index:unregisterListener`),
|
|
431
|
+
|
|
432
|
+
onIndexProgress: (callback: (progress: {
|
|
433
|
+
indexed: number;
|
|
434
|
+
total: number;
|
|
435
|
+
currentFile?: string;
|
|
436
|
+
stage: string;
|
|
437
|
+
error?: string;
|
|
438
|
+
}) => void) => {
|
|
439
|
+
const handler = (_event: Electron.IpcRendererEvent, progress: {
|
|
440
|
+
indexed: number;
|
|
441
|
+
total: number;
|
|
442
|
+
currentFile?: string;
|
|
443
|
+
stage: string;
|
|
444
|
+
error?: string;
|
|
445
|
+
}) => {
|
|
446
|
+
callback(progress);
|
|
447
|
+
};
|
|
448
|
+
ipcRenderer.on(`${channelPrefix}:index:progress`, handler);
|
|
449
|
+
|
|
450
|
+
return () => {
|
|
451
|
+
ipcRenderer.removeListener(`${channelPrefix}:index:progress`, handler);
|
|
452
|
+
};
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
contextBridge.exposeInMainWorld(exposeName, bridge);
|
|
457
|
+
}
|