🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🌐 chore: translate non-English comments to English in electron-server-ipc (#10207)
LobeHub Bot14dd288d50cf
diff --git a/packages/electron-server-ipc/src/ipcClient.ts b/packages/electron-server-ipc/src/ipcClient.tsindex 9d7c73e8492..834a128e2ce 100644--- a/packages/electron-server-ipc/src/ipcClient.ts+++ b/packages/electron-server-ipc/src/ipcClient.ts@@ -28,19 +28,19 @@ export class ElectronIpcClient {this.initialize();}- // 初始化客户端+ // Initialize clientprivate initialize() {try {const tempDir = os.tmpdir();- // Windows 平台强制使用命名管道+ // Force use of named pipe on Windows platformif (process.platform === 'win32') {this.socketPath = WINDOW_PIPE_FILE(this.appId);log('Using named pipe for Windows: %s', this.socketPath);return;}- // 其他平台尝试读取 sock info 文件+ // Try to read sock info file on other platformsconst socketInfoPath = path.join(tempDir, SOCK_INFO_FILE(this.appId));log('Looking for socket info at: %s', socketInfoPath);@@ -49,7 +49,7 @@ export class ElectronIpcClient {this.socketPath = socketInfo.socketPath;log('Found socket path: %s', this.socketPath);} else {- // 如果找不到套接字信息,使用默认 sock 文件路径+ // If socket information is not found, use default sock file paththis.socketPath = path.join(tempDir, SOCK_FILE(this.appId));log('Socket info not found, using default sock path: %s', this.socketPath);}@@ -59,7 +59,7 @@ export class ElectronIpcClient {}}- // 连接到 Electron IPC 服务器+ // Connect to Electron IPC serverprivate connect(): Promise<void> {if (this.connected || !this.socketPath) {log('Connection skipped: Connected=%s, SocketPath=%s', this.connected, !!this.socketPath);@@ -80,18 +80,18 @@ export class ElectronIpcClient {const dataStr = data.toString();log('Received data: %s', dataStr.length > 100 ? `${dataStr.slice(0, 100)}...` : dataStr);- // 将新数据添加到缓冲区+ // Add new data to bufferthis.dataBuffer += dataStr;- // 按换行符分割消息+ // Split messages by newlineconst messages = this.dataBuffer.split('\n');- // 最后一个元素可能是不完整的消息,保留在缓冲区+ // The last element may be an incomplete message, keep it in bufferthis.dataBuffer = messages.pop() || '';log('Buffer remainder: %d bytes', this.dataBuffer.length);for (const message of messages) {- if (!message.trim()) continue; // 跳过空消息+ if (!message.trim()) continue; // Skip empty messagestry {const response = JSON.parse(message);@@ -138,20 +138,20 @@ export class ElectronIpcClient {});}- // 处理断开连接+ // Handle disconnectionprivate handleDisconnect() {log('Handling disconnect, connection attempts: %d', this.connectionAttempts);- // 清除重连定时器+ // Clear reconnection timerif (this.reconnectTimeout) {clearTimeout(this.reconnectTimeout);this.reconnectTimeout = null;log('Cleared reconnect timeout');}- // 清空数据缓冲区+ // Clear data bufferthis.dataBuffer = '';- // 拒绝所有待处理的请求+ // Reject all pending requestsconst pendingCount = this.requestQueue.size;log('Rejecting %d pending requests', pendingCount);for (const [id, { reject }] of this.requestQueue) {@@ -160,7 +160,7 @@ export class ElectronIpcClient {}this.requestQueue.clear();- // 尝试重新连接+ // Attempt to reconnectif (this.connectionAttempts < this.maxConnectionAttempts) {this.connectionAttempts++;const delay = Math.min(1000 * Math.pow(2, this.connectionAttempts - 1), 30_000);@@ -177,14 +177,14 @@ export class ElectronIpcClient {}}- // 发送请求到 Electron IPC 服务器+ // Send request to Electron IPC serverpublic async sendRequest<T>(method: ServerDispatchEventKey, params: any = {}): Promise<T> {if (!this.socketPath) {console.error('Cannot send request: Electron IPC connection not available');throw new Error('Electron IPC connection not available');}- // 如果未连接,先连接+ // Connect first if not connectedif (!this.connected) {log('Not connected, connecting before sending request');await this.connect();@@ -208,7 +208,7 @@ export class ElectronIpcClient {const cleanupAndReject = (error: any) => {clearTimeout(requestTimeoutId);this.requestQueue.delete(id);- // 保留超时错误的 console.error 日志+ // Keep console.error log for timeout errorsif (error &&error.message &&@@ -226,29 +226,29 @@ export class ElectronIpcClient {requestTimeoutId = setTimeout(() => {const pendingRequest = this.requestQueue.get(id);if (pendingRequest) {- // 请求仍在队列中,表示超时- // 调用其专用的 reject处理器 (cleanupAndReject)+ // Request is still in queue, indicating timeout+ // Call its dedicated reject handler (cleanupAndReject)const errorMsg = `Request timed out, method: ${method}`;- // console.error 移至 cleanupAndReject 中处理+ // console.error is handled in cleanupAndRejectpendingRequest.reject(new Error(errorMsg));}- // 如果 pendingRequest 不存在, 表示请求已被处理,其超时已清除+ // If pendingRequest does not exist, the request has been processed and its timeout has been cleared}, 5000);try {- // 发送请求+ // Send requestconst requestJson = JSON.stringify(request) + '\n';log('Writing request to socket, size: %d bytes', requestJson.length);this.socket!.write(requestJson, (err) => {if (err) {- // 写入失败,请求应被视为失败- // 调用其 reject 处理器 (cleanupAndReject)+ // Write failed, request should be treated as failed+ // Call its reject handler (cleanupAndReject)const pending = this.requestQueue.get(id);if (pending) {- pending.reject(err); // 这会调用 cleanupAndReject+ pending.reject(err); // This will call cleanupAndReject} else {- // 理论上不应发生,因为写入失败通常很快- // 但为安全起见,确保原始 promise 被 reject+ // This should not happen in theory, as write failures are usually quick+ // But for safety, ensure the original promise is rejectedcleanupAndReject(err);}console.error('Failed to write request to socket: %o', err);@@ -258,15 +258,15 @@ export class ElectronIpcClient {});} catch (err) {console.error('Error sending request (during setup/write phase): %o', err);- // 发生在此处的错误意味着请求甚至没有机会进入队列或设置超时- // 直接调用 cleanupAndReject 以确保一致性,尽管此时 requestTimeoutId 可能未定义- // (clearTimeout(undefined)是安全的)+ // Error occurring here means the request didn't even have a chance to enter the queue or set timeout+ // Call cleanupAndReject directly to ensure consistency, although requestTimeoutId may be undefined at this point+ // (clearTimeout(undefined) is safe)cleanupAndReject(err);}});}- // 关闭连接+ // Close connectionpublic close() {log('Closing client connection');if (this.reconnectTimeout) {diff --git a/packages/electron-server-ipc/src/ipcServer.ts b/packages/electron-server-ipc/src/ipcServer.tsindex 2c466360c28..c50ef1f9816 100644--- a/packages/electron-server-ipc/src/ipcServer.ts+++ b/packages/electron-server-ipc/src/ipcServer.ts@@ -19,25 +19,25 @@ export class ElectronIPCServer {constructor(appId: string, eventHandler: ElectronIPCEventHandler) {this.appId = appId;const isWindows = process.platform === 'win32';- // 创建唯一的套接字路径,避免冲突+ // Create unique socket path to avoid conflictsthis.socketPath = isWindows? WINDOW_PIPE_FILE(appId): path.join(os.tmpdir(), SOCK_FILE(appId));- // 如果是 Unix 套接字,确保文件不存在+ // For Unix sockets, ensure the file does not existif (!isWindows && fs.existsSync(this.socketPath)) {log('Removing existing socket file at: %s', this.socketPath);fs.unlinkSync(this.socketPath);}- // 创建服务器+ // Create serverlog('Creating IPC server');this.server = net.createServer(this.handleConnection.bind(this));this.eventHandler = eventHandler;}- // 启动服务器+ // Start serverpublic start(): Promise<void> {log('Starting IPC server');return new Promise((resolve, reject) => {@@ -49,7 +49,7 @@ export class ElectronIPCServer {this.server.listen(this.socketPath, () => {log('Electron IPC server listening on %s', this.socketPath);- // 将套接字路径写入临时文件,供 Next.js 服务端读取+ // Write socket path to temporary file for Next.js server to readconst tempDir = os.tmpdir();const socketInfoPath = path.join(tempDir, SOCK_INFO_FILE(this.appId));log('Writing socket info to: %s', socketInfoPath);@@ -60,7 +60,7 @@ export class ElectronIPCServer {});}- // 处理客户端连接+ // Handle client connectionprivate handleConnection(socket: net.Socket): void {let dataBuffer = '';log('New client connection established');@@ -70,12 +70,12 @@ export class ElectronIPCServer {log('Received data chunk, size: %d bytes', chunk.length);dataBuffer += chunk;- // 按 \n\n 分割消息+ // Split messages by \n\nconst messages = dataBuffer.split('\n');- // 保留最后一个可能不完整的消息+ // Keep the last potentially incomplete messagedataBuffer = messages.pop() || '';- // 处理每个完整的消息+ // Process each complete messagefor (const message of messages) {if (!message.trim()) continue;@@ -101,12 +101,12 @@ export class ElectronIPCServer {});}- // 处理客户端请求+ // Handle client requestprivate handleRequest = async (socket: net.Socket, request: any) => {const { id, method, params } = request;log('Handling request: %s (ID: %s)', method, id);- // 根据请求方法执行相应的操作+ // Execute corresponding operation based on request methodconst eventHandler = this.eventHandler[method as ServerDispatchEventKey];if (!eventHandler) {console.error('No handler found for method: %s', method);@@ -126,28 +126,28 @@ export class ElectronIPCServer {}};- // 发送结果+ // Send resultprivate sendResult(socket: net.Socket, id: string, result: any): void {const response = JSON.stringify({ id, result }) + '\n\n';log('Sending success response for ID: %s, size: %d bytes', id, response.length);socket.write(response);}- // 发送错误+ // Send errorprivate sendError(socket: net.Socket, id: string, error: string): void {const response = JSON.stringify({ error, id }) + '\n\n';log('Sending error response for ID: %s: %s', id, error);socket.write(response);}- // 关闭服务器+ // Close serverpublic close(): Promise<void> {log('Closing IPC server');return new Promise((resolve) => {this.server.close(() => {log('Electron IPC server closed');- // 删除套接字文件(Unix 平台)+ // Delete socket file (Unix platforms)if (process.platform !== 'win32' && fs.existsSync(this.socketPath)) {log('Removing socket file: %s', this.socketPath);fs.unlinkSync(this.socketPath);