Просмотр исходного кода

Fix splash: allow it to show even if recovery is impossible.

Afshin Darian 7 лет назад
Родитель
Сommit
a8f90969be

+ 1 - 0
packages/apputils-extension/package.json

@@ -37,6 +37,7 @@
     "@jupyterlab/coreutils": "^1.1.2",
     "@jupyterlab/mainmenu": "^0.5.2",
     "@jupyterlab/services": "^2.0.2",
+    "@phosphor/commands": "^1.5.0",
     "@phosphor/coreutils": "^1.3.0",
     "@phosphor/disposable": "^1.1.2",
     "@phosphor/widgets": "^1.6.0",

+ 10 - 11
packages/apputils-extension/src/index.ts

@@ -24,6 +24,10 @@ import {
   ServiceManager
 } from '@jupyterlab/services';
 
+import {
+  CommandRegistry
+} from '@phosphor/commands';
+
 import {
   PromiseDelegate
 } from '@phosphor/coreutils';
@@ -281,15 +285,8 @@ const splash: JupyterLabPlugin<ISplashScreen> = {
     return {
       show: () => {
         const { commands, restored } = app;
-        const recovery = () => { commands.execute(CommandIDs.reset); };
 
-        // If the reset command is available, show the recovery UI.
-        if (commands.hasCommand(CommandIDs.reset)) {
-          return Private.showSplash(restored, recovery);
-        }
-
-        // If the reset command is unavailable, showing the UI is superfluous.
-        return new DisposableDelegate(() => { /* no-op */ });
+        return Private.showSplash(restored, commands, CommandIDs.reset);
       }
     };
   }
@@ -645,10 +642,10 @@ namespace Private {
    *
    * @param ready - A promise that must be resolved before splash disappears.
    *
-   * @param recovery - A function that recovers from a hanging splash.
+   * @param recovery - A command that recovers from a hanging splash.
    */
   export
-  function showSplash(ready: Promise<any>, recovery: () => void): IDisposable {
+  function showSplash(ready: Promise<any>, commands: CommandRegistry, recovery: string): IDisposable {
     splash.classList.remove('splash-fade');
     splashCount++;
 
@@ -656,7 +653,9 @@ namespace Private {
       window.clearTimeout(debouncer);
     }
     debouncer = window.setTimeout(() => {
-      recover(recovery);
+      if (commands.hasCommand(recovery)) {
+        recover(() => { commands.execute(recovery); });
+      }
     }, SPLASH_RECOVER_TIMEOUT);
 
     document.body.appendChild(splash);

+ 2 - 2
packages/apputils/src/thememanager.ts

@@ -233,12 +233,12 @@ class ThemeManager {
     const old = current ? themes[current].unload() : Promise.resolve();
 
     return Promise.all([old, themes[theme].load()]).then(() => {
-      splash.dispose();
       this._current = theme;
       Private.fitAll(this._host);
-    }).catch(reason => {
       splash.dispose();
+    }).catch(reason => {
       this._onError(reason);
+      splash.dispose();
     });
   }