diff --git a/ui/src/components/CustomTerminal/helper/index.ts b/ui/src/components/CustomTerminal/helper/index.ts index 6dd45b32..abae2774 100644 --- a/ui/src/components/CustomTerminal/helper/index.ts +++ b/ui/src/components/CustomTerminal/helper/index.ts @@ -22,10 +22,14 @@ export const sendEventToLuna = ( name: string, data: any, lunaId: string | null = '', - origin: string | null = null + origin: string | null = '' ) => { if (lunaId !== null && origin !== null) { - window.parent.postMessage({ name, id: lunaId, data }, origin); + try { + window.parent.postMessage({ name, id: lunaId, data }, origin); + } catch (e) { + console.info(e); + } } }; diff --git a/ui/src/hooks/helper/index.ts b/ui/src/hooks/helper/index.ts index da6c78a9..38c62404 100644 --- a/ui/src/hooks/helper/index.ts +++ b/ui/src/hooks/helper/index.ts @@ -113,15 +113,22 @@ export const handleTerminalResize = ( * * @param e * @param terminal + * @param lunaId + * @param origin */ -export const handleCustomKey = (e: KeyboardEvent, terminal: Terminal): boolean => { +export const handleCustomKey = ( + e: KeyboardEvent, + terminal: Terminal, + lunaId: string, + origin: string +): boolean => { if (e.altKey && e.shiftKey && (e.key === 'ArrowRight' || e.key === 'ArrowLeft')) { switch (e.key) { case 'ArrowRight': - window.parent.postMessage({ name: 'KEYEVENT', data: 'alt+shift+right' }); + sendEventToLuna('KEYEVENT', 'alt+shift+right', lunaId, origin); break; case 'ArrowLeft': - window.parent.postMessage({ name: 'KEYEVENT', data: 'alt+shift+left' }); + sendEventToLuna('KEYEVENT', 'alt+shift+left', lunaId, origin); break; } diff --git a/ui/src/hooks/useTerminal.ts b/ui/src/hooks/useTerminal.ts index 55ca6aae..f6e375f2 100644 --- a/ui/src/hooks/useTerminal.ts +++ b/ui/src/hooks/useTerminal.ts @@ -359,8 +359,6 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr switch (message.name) { case 'PING': { - if (lunaId.value != null) return; - lunaId.value = message.id; origin.value = e.origin; @@ -409,7 +407,7 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr handleTerminalSelection(terminal!, termSelectionText); }); terminal.attachCustomKeyEventHandler((e: KeyboardEvent) => { - return handleCustomKey(e, terminal!); + return handleCustomKey(e, terminal!, lunaId.value, origin.value); }); terminal.onData((data: string) => { lastSendTime.value = new Date();