From 85227d3abf3fc4c985c819a10341cf23b6142c4e Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 15 Sep 2021 08:58:32 +0200 Subject: [PATCH] Make `INotebookTracker` optional --- packages/jupyterlab-preview/src/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/jupyterlab-preview/src/index.ts b/packages/jupyterlab-preview/src/index.ts index 72a14d82b..f4810260e 100644 --- a/packages/jupyterlab-preview/src/index.ts +++ b/packages/jupyterlab-preview/src/index.ts @@ -85,12 +85,17 @@ class VoilaRenderButton const extension: JupyterFrontEndPlugin = { id: '@voila-dashboards/jupyterlab-preview:plugin', autoStart: true, - requires: [INotebookTracker], - optional: [ICommandPalette, ILayoutRestorer, IMainMenu, ISettingRegistry], + optional: [ + INotebookTracker, + ICommandPalette, + ILayoutRestorer, + IMainMenu, + ISettingRegistry + ], provides: IVoilaPreviewTracker, activate: ( app: JupyterFrontEnd, - notebooks: INotebookTracker, + notebooks: INotebookTracker | null, palette: ICommandPalette | null, restorer: ILayoutRestorer | null, menu: IMainMenu | null, @@ -114,7 +119,7 @@ const extension: JupyterFrontEndPlugin = { } function getCurrent(args: ReadonlyPartialJSONObject): NotebookPanel | null { - const widget = notebooks.currentWidget; + const widget = notebooks?.currentWidget ?? null; const activate = args['activate'] !== false; if (activate && widget) { @@ -126,8 +131,8 @@ const extension: JupyterFrontEndPlugin = { function isEnabled(): boolean { return ( - notebooks.currentWidget !== null && - notebooks.currentWidget === app.shell.currentWidget + notebooks?.currentWidget !== null && + notebooks?.currentWidget === app.shell.currentWidget ); }