🌐 chore: translate non-English comments to English in apps/desktop/src/main (#12376)

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
LobeHub Bot
2026-02-18 22:15:03 +08:00
committed by GitHub
parent 38e1adba2f
commit 5030177f3d
6 changed files with 52 additions and 52 deletions

View File

@@ -211,10 +211,10 @@ export class BrowserManager {
const identifier = options.identifier;
this.browsers.set(identifier, browser);
// 记录 WebContents identifier 的映射
// Record the mapping between WebContents and identifier
this.webContentsMap.set(browser.browserWindow.webContents, identifier);
// 当窗口关闭时清理映射
// Clean up the mapping when the window is closed
browser.browserWindow.on('close', () => {
if (browser.webContents) this.webContentsMap.delete(browser.webContents);
});

View File

@@ -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();

View File

@@ -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 server
await 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 port
this.serverPort = await getPort({
// 备用端口
// Fallback port
host: '127.0.0.1',
port: 33_250,
// 首选端口
// Preferred ports
ports: [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 timeout
req.setTimeout(30_000, () => {
logger.warn('Request timeout, closing connection');
if (!res.destroyed && !res.headersSent) {
@@ -88,7 +88,7 @@ export class StaticFileServerManager {
}
});
// 监听客户端断开连接
// Listen for client disconnection
req.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 errors
try {
if (!res.destroyed && !res.headersSent) {
res.writeHead(500, { 'Content-Type': 'text/plain' });
@@ -110,7 +110,7 @@ export class StaticFileServerManager {
}
});
// 监听指定端口
// Listen on the specified port
server.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 ended
if (res.destroyed || res.headersSent) {
logger.warn('Response already ended, skipping request processing');
return;
}
// 获取请求的 Origin 并设置 CORS
// Get the request Origin and set CORS
const origin = req.headers.origin || req.headers.referer;
const allowedOrigin = getAllowedOrigin(origin);
// 处理 CORS 预检请求
// Handle CORS preflight requests
if (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 file
const 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 again
if (res.destroyed || res.headersSent) {
logger.warn('Response ended during file processing');
return;
}
// 设置响应头
// Set response headers
res.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 content
res.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 writable
if (!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 error
if (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');

View File

@@ -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();
});

View File

@@ -24,7 +24,7 @@ export const createMenuImpl = (app: App): IMenuPlatform => {
}
default: {
// 提供一个备用或抛出错误
// Provide a fallback or throw an error
console.warn(
`Unsupported platform for menu: ${currentPlatform}, using Windows implementation as fallback.`,
);

View File

@@ -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:// paths
if (!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:// paths
if (!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;