diff --git a/packages/erd-editor-jetbrains-webview/src/env.d.ts b/packages/erd-editor-jetbrains-webview/src/env.d.ts index 62b3aed2..b2c1380d 100644 --- a/packages/erd-editor-jetbrains-webview/src/env.d.ts +++ b/packages/erd-editor-jetbrains-webview/src/env.d.ts @@ -1,5 +1,11 @@ -declare global { - interface Window { - cefQuery: (arg: any) => number; - } +interface Window { + cefQuery: (query: { + request: string; + onSuccess: (response: string) => void; + onFailure: (errorCode: number, errorMessage: string) => void; + context?: any; + persistent: boolean; + keepAlive?: boolean; + }) => number; + cefQueryCancel: (requestId: number) => void; } diff --git a/packages/erd-editor-jetbrains-webview/src/main.ts b/packages/erd-editor-jetbrains-webview/src/main.ts index 56e9c15b..4b51b9d8 100644 --- a/packages/erd-editor-jetbrains-webview/src/main.ts +++ b/packages/erd-editor-jetbrains-webview/src/main.ts @@ -19,12 +19,16 @@ import { import { encode } from 'base64-arraybuffer'; const bridge = new Emitter(); -// const vscode = globalThis.acquireVsCodeApi(); const editor = document.createElement('erd-editor'); const sharedStore = editor.getSharedStore({ mouseTracker: false }); const dispatch = (action: AnyAction) => { - // vscode.postMessage(action); + window.cefQuery({ + request: JSON.stringify(action), + persistent: false, + onSuccess: () => {}, + onFailure: () => {}, + }); }; import('@dineug/erd-editor-shiki-worker').then(({ getShikiService }) => { @@ -95,5 +99,5 @@ bridge.on({ }, }); -globalThis.addEventListener('message', event => bridge.emit(event.data)); +window.addEventListener('message', event => bridge.emit(event.data)); dispatch(vscodeInitialAction());