add message layer for backward compatibility

This commit is contained in:
Diego Colombo 2022-04-04 17:08:46 +01:00 коммит произвёл Brett V. Forsgren
Родитель 6c5559d3cb
Коммит 4604ee022d
1 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -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"
}, '*');
}