Skip to content

Commit

Permalink
Make INotebookTracker optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Sep 15, 2021
1 parent aa79d9c commit 85227d3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/jupyterlab-preview/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@ class VoilaRenderButton
const extension: JupyterFrontEndPlugin<IVoilaPreviewTracker> = {
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,
Expand All @@ -114,7 +119,7 @@ const extension: JupyterFrontEndPlugin<IVoilaPreviewTracker> = {
}

function getCurrent(args: ReadonlyPartialJSONObject): NotebookPanel | null {
const widget = notebooks.currentWidget;
const widget = notebooks?.currentWidget ?? null;
const activate = args['activate'] !== false;

if (activate && widget) {
Expand All @@ -126,8 +131,8 @@ const extension: JupyterFrontEndPlugin<IVoilaPreviewTracker> = {

function isEnabled(): boolean {
return (
notebooks.currentWidget !== null &&
notebooks.currentWidget === app.shell.currentWidget
notebooks?.currentWidget !== null &&
notebooks?.currentWidget === app.shell.currentWidget
);
}

Expand Down

0 comments on commit 85227d3

Please sign in to comment.