From 4604ee022da553e3c4635933032c78643a6fbdd0 Mon Sep 17 00:00:00 2001 From: Diego Colombo Date: Mon, 4 Apr 2022 17:08:46 +0100 Subject: [PATCH] add message layer for backward compatibility --- src/microsoft-trydotnet-editor/src/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/microsoft-trydotnet-editor/src/index.ts b/src/microsoft-trydotnet-editor/src/index.ts index 1a47b31a..9ea91e4e 100644 --- a/src/microsoft-trydotnet-editor/src/index.ts +++ b/src/microsoft-trydotnet-editor/src/index.ts @@ -8,6 +8,7 @@ import './index.css'; import * as messageBus from './messageBus'; import * as rxjs from 'rxjs'; import * as monacoAdapterImpl from './monacoAdapterImpl'; +import { CommandCancelledType, CommandFailedType, CommandSucceededType, SubmitCodeType } from '@microsoft/dotnet-interactive'; if (window) { @@ -29,7 +30,21 @@ if (window) { const kernel = factory.createWasmProjectKernel(); const tdnEditor = new tryDotNetEditor.TryDotNetEditor(mainWindowMessageBus, kernel); + // for messaging api backward compatibility + kernel.subscribeToKernelEvents((event) => { + if ((event.eventType === CommandSucceededType || event.eventType == CommandFailedType || event.eventType == CommandCancelledType) && event.command?.commandType === SubmitCodeType) { + window.postMessage({ + type: "NOTIFY_HOST_RUN_READY" + }, '*'); + } + }); + tdnEditor.editor = new monacoAdapterImpl.MonacoEditorAdapter(editor); window['trydotnetEditor'] = tdnEditor; + + // for messaging api backward compatibility + window.postMessage({ + type: "NOTIFY_HOST_EDITOR_READY" + }, '*'); }