远程读取日志

This commit is contained in:
YHH
2025-10-16 17:10:22 +08:00
parent 1ec7892338
commit 43bdd7e43b
16 changed files with 966 additions and 80 deletions

View File

@@ -1,5 +1,6 @@
import { invoke } from '@tauri-apps/api/core';
import { SettingsService } from './SettingsService';
import { LogLevel } from '@esengine/ecs-framework';
export interface SystemPerformanceData {
name: string;
@@ -201,6 +202,8 @@ export class ProfilerService {
this.handleRawEntityListResponse(message.data);
} else if (message.type === 'get_entity_details_response' && message.data) {
this.handleEntityDetailsResponse(message.data);
} else if (message.type === 'log' && message.data) {
this.handleRemoteLog(message.data);
}
} catch (error) {
console.error('[ProfilerService] Failed to parse message:', error);
@@ -343,6 +346,39 @@ export class ProfilerService {
}));
}
private handleRemoteLog(data: any): void {
if (!data) {
return;
}
const levelMap: Record<string, LogLevel> = {
'debug': LogLevel.Debug,
'info': LogLevel.Info,
'warn': LogLevel.Warn,
'error': LogLevel.Error,
'fatal': LogLevel.Fatal
};
const level = levelMap[data.level?.toLowerCase() || 'info'] || LogLevel.Info;
let message = data.message || '';
if (typeof message === 'object') {
try {
message = JSON.stringify(message, null, 2);
} catch {
message = String(message);
}
}
window.dispatchEvent(new CustomEvent('profiler:remote-log', {
detail: {
level,
message,
timestamp: data.timestamp ? new Date(data.timestamp) : new Date()
}
}));
}
private createEmptyData(): ProfilerData {
return {
totalFrameTime: 0,

View File

@@ -64,4 +64,25 @@ export class SettingsService {
public getAll(): Record<string, any> {
return Object.fromEntries(this.settings);
}
public getRecentProjects(): string[] {
return this.get<string[]>('recentProjects', []);
}
public addRecentProject(projectPath: string): void {
const recentProjects = this.getRecentProjects();
const filtered = recentProjects.filter(p => p !== projectPath);
const updated = [projectPath, ...filtered].slice(0, 10);
this.set('recentProjects', updated);
}
public removeRecentProject(projectPath: string): void {
const recentProjects = this.getRecentProjects();
const filtered = recentProjects.filter(p => p !== projectPath);
this.set('recentProjects', filtered);
}
public clearRecentProjects(): void {
this.set('recentProjects', []);
}
}