浏览代码

Make ILabShell optional for the launcher extension

Jeremy Tuloup 4 年之前
父节点
当前提交
539ef0cd56
共有 1 个文件被更改,包括 13 次插入11 次删除
  1. 13 11
      packages/launcher-extension/src/index.ts

+ 13 - 11
packages/launcher-extension/src/index.ts

@@ -28,8 +28,8 @@ namespace CommandIDs {
 const plugin: JupyterFrontEndPlugin<ILauncher> = {
   activate,
   id: '@jupyterlab/launcher-extension:plugin',
-  requires: [ILabShell, ITranslator],
-  optional: [ICommandPalette],
+  requires: [ITranslator],
+  optional: [ILabShell, ICommandPalette],
   provides: ILauncher,
   autoStart: true
 };
@@ -44,11 +44,11 @@ export default plugin;
  */
 function activate(
   app: JupyterFrontEnd,
-  labShell: ILabShell,
   translator: ITranslator,
+  labShell: ILabShell | null,
   palette: ICommandPalette | null
 ): ILauncher {
-  const { commands } = app;
+  const { commands, shell } = app;
   const trans = translator.load('jupyterlab');
   const model = new LauncherModel();
 
@@ -58,7 +58,7 @@ function activate(
       const cwd = args['cwd'] ? String(args['cwd']) : '';
       const id = `launcher-${Private.id++}`;
       const callback = (item: Widget) => {
-        labShell.add(item, 'main', { ref: id });
+        shell.add(item, 'main', { ref: id });
       };
       const launcher = new Launcher({
         model,
@@ -75,15 +75,17 @@ function activate(
       const main = new MainAreaWidget({ content: launcher });
 
       // If there are any other widgets open, remove the launcher close icon.
-      main.title.closable = !!toArray(labShell.widgets('main')).length;
+      main.title.closable = !!toArray(shell.widgets('main')).length;
       main.id = id;
 
-      labShell.add(main, 'main', { activate: args['activate'] as boolean });
+      shell.add(main, 'main', { activate: args['activate'] as boolean });
 
-      labShell.layoutModified.connect(() => {
-        // If there is only a launcher open, remove the close icon.
-        main.title.closable = toArray(labShell.widgets('main')).length > 1;
-      }, main);
+      if (labShell) {
+        labShell.layoutModified.connect(() => {
+          // If there is only a launcher open, remove the close icon.
+          main.title.closable = toArray(labShell.widgets('main')).length > 1;
+        }, main);
+      }
 
       return main;
     }