perf: WebView2 HostObject 프록시 캐싱으로 성능 개선
- communication.ts에서 machine 프록시를 모듈 로드 시 한 번만 초기화 - 10개 API 메서드에서 매번 hostObjects.machine 접근하던 오버헤드 제거 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,9 @@
|
|||||||
// Check if running in WebView2
|
// Check if running in WebView2
|
||||||
const isWebView = typeof window !== 'undefined' && !!window.chrome?.webview;
|
const isWebView = typeof window !== 'undefined' && !!window.chrome?.webview;
|
||||||
|
|
||||||
|
// 비동기 프록시 캐싱 (한 번만 초기화) - 매번 접근 시 오버헤드 제거
|
||||||
|
const machine = isWebView ? window.chrome!.webview!.hostObjects.machine : null;
|
||||||
|
|
||||||
type MessageCallback = (data: any) => void;
|
type MessageCallback = (data: any) => void;
|
||||||
|
|
||||||
class CommunicationLayer {
|
class CommunicationLayer {
|
||||||
@@ -70,8 +73,8 @@ class CommunicationLayer {
|
|||||||
// --- API Methods ---
|
// --- API Methods ---
|
||||||
|
|
||||||
public async getConfig(): Promise<string> {
|
public async getConfig(): Promise<string> {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
return await window.chrome!.webview!.hostObjects.machine.GetConfig();
|
return await machine.GetConfig();
|
||||||
} else {
|
} else {
|
||||||
// WebSocket Request/Response Pattern
|
// WebSocket Request/Response Pattern
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -103,8 +106,8 @@ class CommunicationLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getIOList(): Promise<string> {
|
public async getIOList(): Promise<string> {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
return await window.chrome!.webview!.hostObjects.machine.GetIOList();
|
return await machine.GetIOList();
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!this.isConnected) {
|
if (!this.isConnected) {
|
||||||
@@ -132,8 +135,8 @@ class CommunicationLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getRecipeList(): Promise<string> {
|
public async getRecipeList(): Promise<string> {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
return await window.chrome!.webview!.hostObjects.machine.GetRecipeList();
|
return await machine.GetRecipeList();
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!this.isConnected) {
|
if (!this.isConnected) {
|
||||||
@@ -161,40 +164,40 @@ class CommunicationLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async saveConfig(configJson: string): Promise<void> {
|
public async saveConfig(configJson: string): Promise<void> {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
await window.chrome!.webview!.hostObjects.machine.SaveConfig(configJson);
|
await machine.SaveConfig(configJson);
|
||||||
} else {
|
} else {
|
||||||
this.ws?.send(JSON.stringify({ type: 'SAVE_CONFIG', data: JSON.parse(configJson) }));
|
this.ws?.send(JSON.stringify({ type: 'SAVE_CONFIG', data: JSON.parse(configJson) }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendControl(command: string) {
|
public async sendControl(command: string) {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
await window.chrome!.webview!.hostObjects.machine.SystemControl(command);
|
await machine.SystemControl(command);
|
||||||
} else {
|
} else {
|
||||||
this.ws?.send(JSON.stringify({ type: 'CONTROL', command }));
|
this.ws?.send(JSON.stringify({ type: 'CONTROL', command }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async moveAxis(axis: string, value: number) {
|
public async moveAxis(axis: string, value: number) {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
await window.chrome!.webview!.hostObjects.machine.MoveAxis(axis, value);
|
await machine.MoveAxis(axis, value);
|
||||||
} else {
|
} else {
|
||||||
this.ws?.send(JSON.stringify({ type: 'MOVE', axis, value }));
|
this.ws?.send(JSON.stringify({ type: 'MOVE', axis, value }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setIO(id: number, state: boolean) {
|
public async setIO(id: number, state: boolean) {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
await window.chrome!.webview!.hostObjects.machine.SetIO(id, false, state);
|
await machine.SetIO(id, false, state);
|
||||||
} else {
|
} else {
|
||||||
this.ws?.send(JSON.stringify({ type: 'SET_IO', id, state }));
|
this.ws?.send(JSON.stringify({ type: 'SET_IO', id, state }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async selectRecipe(recipeId: string): Promise<{ success: boolean; message: string; recipeId?: string }> {
|
public async selectRecipe(recipeId: string): Promise<{ success: boolean; message: string; recipeId?: string }> {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
const resultJson = await window.chrome!.webview!.hostObjects.machine.SelectRecipe(recipeId);
|
const resultJson = await machine.SelectRecipe(recipeId);
|
||||||
return JSON.parse(resultJson);
|
return JSON.parse(resultJson);
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -223,8 +226,8 @@ class CommunicationLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async copyRecipe(recipeId: string, newName: string): Promise<{ success: boolean; message: string; newRecipe?: any }> {
|
public async copyRecipe(recipeId: string, newName: string): Promise<{ success: boolean; message: string; newRecipe?: any }> {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
const resultJson = await window.chrome!.webview!.hostObjects.machine.CopyRecipe(recipeId, newName);
|
const resultJson = await machine.CopyRecipe(recipeId, newName);
|
||||||
return JSON.parse(resultJson);
|
return JSON.parse(resultJson);
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -253,8 +256,8 @@ class CommunicationLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async deleteRecipe(recipeId: string): Promise<{ success: boolean; message: string; recipeId?: string }> {
|
public async deleteRecipe(recipeId: string): Promise<{ success: boolean; message: string; recipeId?: string }> {
|
||||||
if (isWebView) {
|
if (isWebView && machine) {
|
||||||
const resultJson = await window.chrome!.webview!.hostObjects.machine.DeleteRecipe(recipeId);
|
const resultJson = await machine.DeleteRecipe(recipeId);
|
||||||
return JSON.parse(resultJson);
|
return JSON.parse(resultJson);
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user