🤯 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 apps/desktop/src/main (#12376)
LobeHub Bot5030177f3d45
diff --git a/apps/desktop/src/main/core/browser/BrowserManager.ts b/apps/desktop/src/main/core/browser/BrowserManager.tsindex 2c30d13822b..f541db4f821 100644--- a/apps/desktop/src/main/core/browser/BrowserManager.ts+++ b/apps/desktop/src/main/core/browser/BrowserManager.ts@@ -211,10 +211,10 @@ export class BrowserManager {const identifier = options.identifier;this.browsers.set(identifier, browser);- // 记录 WebContents 和 identifier 的映射+ // Record the mapping between WebContents and identifierthis.webContentsMap.set(browser.browserWindow.webContents, identifier);- // 当窗口关闭时清理映射+ // Clean up the mapping when the window is closedbrowser.browserWindow.on('close', () => {if (browser.webContents) this.webContentsMap.delete(browser.webContents);});diff --git a/apps/desktop/src/main/core/infrastructure/IoCContainer.ts b/apps/desktop/src/main/core/infrastructure/IoCContainer.tsindex 73eef33d1ac..144afc54886 100644--- a/apps/desktop/src/main/core/infrastructure/IoCContainer.ts+++ b/apps/desktop/src/main/core/infrastructure/IoCContainer.ts@@ -1,5 +1,5 @@/**- * 存储应用中需要用装饰器的类+ * Stores classes in the application that require decorators*/export class IoCContainer {static shortcuts: WeakMap<any, { methodName: string; name: string }[]> = new WeakMap();diff --git a/apps/desktop/src/main/core/infrastructure/StaticFileServerManager.ts b/apps/desktop/src/main/core/infrastructure/StaticFileServerManager.tsindex d5ad9689286..cc064f9ea8a 100644--- a/apps/desktop/src/main/core/infrastructure/StaticFileServerManager.ts+++ b/apps/desktop/src/main/core/infrastructure/StaticFileServerManager.ts@@ -36,7 +36,7 @@ export class StaticFileServerManager {}/**- * 初始化静态文件管理器+ * Initialize the static file manager*/async initialize(): Promise<void> {if (this.isInitialized) {@@ -47,7 +47,7 @@ export class StaticFileServerManager {logger.info('Initializing StaticFileServerManager');try {- // 启动 HTTP 文件服务器+ // Start the HTTP file serverawait this.startHttpServer();this.isInitialized = true;@@ -61,17 +61,17 @@ export class StaticFileServerManager {}/**- * 启动 HTTP 文件服务器+ * Start the HTTP file server*/private async startHttpServer(): Promise<void> {try {- // 使用 get-port-please 获取可用端口+ // Use get-port-please to find an available portthis.serverPort = await getPort({- // 备用端口+ // Fallback porthost: '127.0.0.1',port: 33_250,- // 首选端口+ // Preferred portsports: [33_251, 33_252, 33_253, 33_254, 33_255],});@@ -79,7 +79,7 @@ export class StaticFileServerManager {return new Promise((resolve, reject) => {const server = createServer(async (req, res) => {- // 设置请求超时+ // Set request timeoutreq.setTimeout(30_000, () => {logger.warn('Request timeout, closing connection');if (!res.destroyed && !res.headersSent) {@@ -88,7 +88,7 @@ export class StaticFileServerManager {}});- // 监听客户端断开连接+ // Listen for client disconnectionreq.on('close', () => {logger.debug('Client disconnected during request processing');});@@ -98,7 +98,7 @@ export class StaticFileServerManager {} catch (error) {logger.error('Unhandled error in HTTP request handler:', error);- // 尝试发送错误响应,但确保不会导致进一步错误+ // Attempt to send error response, but ensure it does not cause further errorstry {if (!res.destroyed && !res.headersSent) {res.writeHead(500, { 'Content-Type': 'text/plain' });@@ -110,7 +110,7 @@ export class StaticFileServerManager {}});- // 监听指定端口+ // Listen on the specified portserver.listen(this.serverPort, '127.0.0.1', () => {this.httpServer = server;logger.info(`HTTP file server started on port ${this.serverPort}`);@@ -129,21 +129,21 @@ export class StaticFileServerManager {}/**- * 处理 HTTP 请求+ * Handle HTTP requests*/private async handleHttpRequest(req: any, res: any): Promise<void> {try {- // 检查响应是否已经结束+ // Check if the response has already endedif (res.destroyed || res.headersSent) {logger.warn('Response already ended, skipping request processing');return;}- // 获取请求的 Origin 并设置 CORS+ // Get the request Origin and set CORSconst origin = req.headers.origin || req.headers.referer;const allowedOrigin = getAllowedOrigin(origin);- // 处理 CORS 预检请求+ // Handle CORS preflight requestsif (req.method === 'OPTIONS') {res.writeHead(204, {'Access-Control-Allow-Headers': 'Content-Type',@@ -160,12 +160,12 @@ export class StaticFileServerManager {logger.debug(`Request method: ${req.method}`);logger.debug(`Request headers: ${JSON.stringify(req.headers)}`);- // 提取File path:从 /desktop-file/path/to/file.png 中提取相对路径- let filePath = decodeURIComponent(url.pathname.slice(1)); // 移除开头的 /+ // Extract file path: extract the relative path from /desktop-file/path/to/file.png+ let filePath = decodeURIComponent(url.pathname.slice(1)); // Remove the leading /logger.debug(`Initial file path after decode: ${filePath}`);- // 如果路径以 desktop-file/ 开头,则移除该前缀- const prefixWithoutSlash = LOCAL_STORAGE_URL_PREFIX.slice(1) + '/'; // 移除开头的 / 并添加结尾的 /+ // If the path starts with desktop-file/, remove that prefix+ const prefixWithoutSlash = LOCAL_STORAGE_URL_PREFIX.slice(1) + '/'; // Remove the leading / and add a trailing /logger.debug(`Prefix to remove: ${prefixWithoutSlash}`);if (filePath.startsWith(prefixWithoutSlash)) {@@ -182,7 +182,7 @@ export class StaticFileServerManager {return;}- // 使用 FileService 获取文件+ // Use FileService to retrieve the fileconst desktopPath = `desktop://${filePath}`;logger.debug(`Attempting to get file: ${desktopPath}`);const fileResult = await this.fileService.getFile(desktopPath);@@ -190,13 +190,13 @@ export class StaticFileServerManager {`File retrieved successfully, mime type: ${fileResult.mimeType}, size: ${fileResult.content.byteLength} bytes`,);- // 再次检查响应状态+ // Check the response status againif (res.destroyed || res.headersSent) {logger.warn('Response ended during file processing');return;}- // 设置响应头+ // Set response headersres.writeHead(200, {'Access-Control-Allow-Origin': allowedOrigin,'Cache-Control': 'public, max-age=31536000',@@ -204,7 +204,7 @@ export class StaticFileServerManager {'Content-Type': fileResult.mimeType,});- // 发送文件内容+ // Send file contentres.end(Buffer.from(fileResult.content));logger.debug(`HTTP file served successfully: desktop://${filePath}`);@@ -212,14 +212,14 @@ export class StaticFileServerManager {logger.error(`Error serving HTTP file: ${error}`);logger.error(`Error stack: ${error.stack}`);- // 检查响应是否仍然可写+ // Check if the response is still writableif (!res.destroyed && !res.headersSent) {try {- // 获取请求的 Origin 并设置 CORS(错误响应也需要!)+ // Get the request Origin and set CORS (error responses also need this!)const origin = req.headers.origin || req.headers.referer;const allowedOrigin = getAllowedOrigin(origin);- // 判断是否是文件未找到错误+ // Determine whether it is a file not found errorif (error.name === 'FileNotFoundError') {res.writeHead(404, {'Access-Control-Allow-Origin': allowedOrigin,@@ -255,7 +255,7 @@ export class StaticFileServerManager {}/**- * 销毁静态文件管理器+ * Destroy the static file manager*/destroy() {logger.info('Destroying StaticFileServerManager');diff --git a/apps/desktop/src/main/core/ui/TrayManager.ts b/apps/desktop/src/main/core/ui/TrayManager.tsindex 379ca02b1a7..05b78091fa7 100644--- a/apps/desktop/src/main/core/ui/TrayManager.ts+++ b/apps/desktop/src/main/core/ui/TrayManager.ts@@ -67,56 +67,56 @@ export class TrayManager {}/**- * 通过标识符获取托盘实例- * @param identifier 托盘标识符+ * Retrieve a tray instance by identifier+ * @param identifier Tray identifier*/retrieveByIdentifier(identifier: TrayIdentifiers) {- logger.debug(`通过标识符获取托盘: ${identifier}`);+ logger.debug(`Retrieving tray by identifier: ${identifier}`);return this.trays.get(identifier);}/**- * 向所有托盘广播消息- * @param event 事件名称- * @param data 事件数据+ * Broadcast a message to all trays+ * @param event Event name+ * @param data Event data*/broadcastToAllTrays = <T extends MainBroadcastEventKey>(event: T,data: MainBroadcastParams<T>,) => {- logger.debug(`向所有托盘广播事件 ${event}`);+ logger.debug(`Broadcasting event ${event} to all trays`);this.trays.forEach((tray) => {tray.broadcast(event, data);});};/**- * 向指定托盘广播消息- * @param identifier 托盘标识符- * @param event 事件名称- * @param data 事件数据+ * Broadcast a message to a specific tray+ * @param identifier Tray identifier+ * @param event Event name+ * @param data Event data*/broadcastToTray = <T extends MainBroadcastEventKey>(identifier: TrayIdentifiers,event: T,data: MainBroadcastParams<T>,) => {- logger.debug(`向托盘 ${identifier} 广播事件 ${event}`);+ logger.debug(`Broadcasting event ${event} to tray ${identifier}`);this.trays.get(identifier)?.broadcast(event, data);};/**- * 获取或创建托盘实例- * @param options 托盘选项+ * Retrieve or create a tray instance+ * @param options Tray options*/private retrieveOrInitialize(options: TrayOptions) {let tray = this.trays.get(options.identifier as TrayIdentifiers);if (tray) {- logger.debug(`获取现有托盘: ${options.identifier}`);+ logger.debug(`Retrieved existing tray: ${options.identifier}`);return tray;}- logger.debug(`创建新托盘: ${options.identifier}`);+ logger.debug(`Creating new tray: ${options.identifier}`);tray = new Tray(options, this.app);this.trays.set(options.identifier as TrayIdentifiers, tray);@@ -125,10 +125,10 @@ export class TrayManager {}/**- * 销毁所有托盘+ * Destroy all trays*/destroyAll() {- logger.debug('销毁所有托盘');+ logger.debug('Destroying all trays');this.trays.forEach((tray) => {tray.destroy();});diff --git a/apps/desktop/src/main/menus/index.ts b/apps/desktop/src/main/menus/index.tsindex a97ec70be16..041891aafce 100644--- a/apps/desktop/src/main/menus/index.ts+++ b/apps/desktop/src/main/menus/index.ts@@ -24,7 +24,7 @@ export const createMenuImpl = (app: App): IMenuPlatform => {}default: {- // 提供一个备用或抛出错误+ // Provide a fallback or throw an errorconsole.warn(`Unsupported platform for menu: ${currentPlatform}, using Windows implementation as fallback.`,);diff --git a/apps/desktop/src/main/services/fileSrv.ts b/apps/desktop/src/main/services/fileSrv.tsindex 0ad8b38b2dc..72ace09999a 100644--- a/apps/desktop/src/main/services/fileSrv.ts+++ b/apps/desktop/src/main/services/fileSrv.ts@@ -158,7 +158,7 @@ export default class FileService extends ServiceModule {async getFile(path: string): Promise<{ content: ArrayBuffer; mimeType: string }> {logger.info(`Getting file content: ${path}`);try {- // 处理desktop://路径+ // Handle desktop:// pathsif (!path.startsWith('desktop://')) {logger.error(`Invalid desktop file path: ${path}`);throw new Error(`Invalid desktop file path: ${path}`);@@ -208,7 +208,7 @@ export default class FileService extends ServiceModule {logger.error(`Both legacy and fallback paths failed. Legacy error: ${(firstError as Error).message}, Fallback error: ${(fallbackError as Error).message}`,);- throw firstError; // 抛出原始错误+ throw firstError; // Re-throw the original error}} else {throw firstError;@@ -286,7 +286,7 @@ export default class FileService extends ServiceModule {async deleteFile(path: string): Promise<{ success: boolean }> {logger.info(`Deleting file: ${path}`);try {- // 处理desktop://路径+ // Handle desktop:// pathsif (!path.startsWith('desktop://')) {logger.error(`Invalid desktop file path: ${path}`);throw new Error(`Invalid desktop file path: ${path}`);@@ -333,7 +333,7 @@ export default class FileService extends ServiceModule {logger.error(`Both legacy and fallback deletion failed. Legacy error: ${(firstError as Error).message}, Fallback error: ${(fallbackError as Error).message}`,);- throw firstError; // 抛出原始错误+ throw firstError; // Re-throw the original error}} else {throw firstError;