* refactor(editor-app): 改进架构和类型安全 * refactor(editor-app): 开始拆分 Inspector.tsx - 创建基础架构 * refactor(editor-app): 完成 Inspector.tsx 拆分 * refactor(editor-app): 优化 Inspector 类型定义,消除所有 any 使用 * refactor(editor): 实现可扩展的属性渲染器系统 * Potential fix for code scanning alert no. 231: Unused variable, import, function or class Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix(ci): 防止 Codecov 服务故障阻塞 CI 流程 --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
30 lines
842 B
TypeScript
30 lines
842 B
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
export interface ProfilerService {
|
|
connect(port: number): void;
|
|
disconnect(): void;
|
|
isConnected(): boolean;
|
|
requestEntityList(): void;
|
|
requestEntityDetails(entityId: number): void;
|
|
}
|
|
|
|
export function useProfilerService(): ProfilerService | undefined {
|
|
const [service, setService] = useState<ProfilerService | undefined>(() => {
|
|
return (window as any).__PROFILER_SERVICE__;
|
|
});
|
|
|
|
useEffect(() => {
|
|
const checkService = () => {
|
|
const newService = (window as any).__PROFILER_SERVICE__;
|
|
if (newService !== service) {
|
|
setService(newService);
|
|
}
|
|
};
|
|
|
|
const interval = setInterval(checkService, 1000);
|
|
return () => clearInterval(interval);
|
|
}, [service]);
|
|
|
|
return service;
|
|
}
|