diff --git a/app/index.js b/app/index.js index cafb6ed7d2..61a9661d31 100644 --- a/app/index.js +++ b/app/index.js @@ -83,6 +83,7 @@ async function main() { require('@jupyterlab/apputils-extension').default.filter(({ id }) => [ '@jupyterlab/apputils-extension:palette', + '@jupyter/apputils-extension:sanitizer', '@jupyterlab/apputils-extension:settings', '@jupyterlab/apputils-extension:state', '@jupyterlab/apputils-extension:themes', @@ -135,6 +136,7 @@ async function main() { '@jupyterlab/notebook-extension:code-console', '@jupyterlab/notebook-extension:export', '@jupyterlab/notebook-extension:factory', + '@jupyterlab/notebook-extension:toc', '@jupyterlab/notebook-extension:tracker', '@jupyterlab/notebook-extension:widget-factory' ].includes(id) diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index f4c3d904a0..5e65911d31 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -185,7 +185,7 @@ const opener: JupyterFrontEndPlugin = { const command = 'router:tree'; commands.addCommand(command, { - execute: (args: any) => { + execute: async (args: any) => { const parsed = args as IRouter.ILocation; const matches = parsed.path.match(TREE_PATTERN) ?? []; const [, , path] = matches; @@ -195,12 +195,11 @@ const opener: JupyterFrontEndPlugin = { const file = decodeURIComponent(path); const ext = PathExt.extname(file); - app.restored.then(async () => { + await new Promise(async () => { // TODO: get factory from file type instead? if (ext === '.ipynb') { // TODO: fix upstream? await settingRegistry?.load('@jupyterlab/notebook-extension:panel'); - await Promise.resolve(); docManager.open(file, NOTEBOOK_FACTORY, undefined, { ref: '_noref' }); diff --git a/packages/application/src/app.ts b/packages/application/src/app.ts index 4c5ff461f8..e3392e2970 100644 --- a/packages/application/src/app.ts +++ b/packages/application/src/app.ts @@ -37,6 +37,11 @@ export class NotebookApp extends JupyterFrontEnd { this.registerPlugin(plugin); } } + + this.restored = this.shell.restored + .then(() => undefined) + .catch(() => undefined); + this.restored.then(() => this._formatter.invoke()); } @@ -55,6 +60,12 @@ export class NotebookApp extends JupyterFrontEnd { */ readonly status = new LabStatus(this); + /** + * Promise that resolves when state is first restored, returning layout + * description. + */ + readonly restored: Promise; + /** * The version of the application. */ diff --git a/packages/application/src/shell.ts b/packages/application/src/shell.ts index 7cf764acf1..d336525df3 100644 --- a/packages/application/src/shell.ts +++ b/packages/application/src/shell.ts @@ -6,7 +6,7 @@ import { PageConfig } from '@jupyterlab/coreutils'; import { DocumentRegistry } from '@jupyterlab/docregistry'; import { ArrayExt, find, IIterator, iter } from '@lumino/algorithm'; -import { Token } from '@lumino/coreutils'; +import { PromiseDelegate, Token } from '@lumino/coreutils'; import { Message, MessageLoop, IMessageHandler } from '@lumino/messaging'; import { Debouncer } from '@lumino/polling'; import { ISignal, Signal } from '@lumino/signaling'; @@ -75,12 +75,10 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { } else { this.layout = this.initLayoutWithoutSidePanels(); } - } initLayoutWithoutSidePanels(): Layout { const rootLayout = new BoxLayout(); - BoxLayout.setStretch(this._main, 1); this._spacer = new Widget(); @@ -211,6 +209,13 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { return !(this._rightHandler.isVisible && this.rightPanel.isVisible); } + /** + * Promise that resolves when main widget is loaded + */ + get restored(): Promise { + return this._mainWidgetLoaded.promise; + } + /** * Activate a widget in its area. */ @@ -259,6 +264,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { this._main.addWidget(widget); this._main.update(); this._currentChanged.emit(void 0); + this._mainWidgetLoaded.resolve(); break; case 'left': if (this.sidePanelsVisible()) { @@ -410,6 +416,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell { private _spacer: Widget; private _main: Panel; private _currentChanged = new Signal(this); + private _mainWidgetLoaded = new PromiseDelegate(); } /**