浏览代码

Add busy favicon based on running sessions

code to animate transitions taken from jupyter notebook
https://github.com/jupyter/notebook/commit/3e01e128f5082e70e665b446529adfb06912bd7e#diff-1882488485f6b478b0b9073f207ab594
Saul Shanabrook 7 年之前
父节点
当前提交
a591e7f539
共有 1 个文件被更改,包括 24 次插入0 次删除
  1. 24 0
      packages/application-extension/src/index.tsx

+ 24 - 0
packages/application-extension/src/index.tsx

@@ -151,6 +151,30 @@ const main: JupyterLabPlugin<void> = {
         return (event as any).returnValue = message;
       }
     });
+
+    let isBusy = false;
+    const favicon = document.querySelector('link[rel="shortcut icon"]') as HTMLLinkElement;
+    const icons = ['favicon-busy-1.ico', 'favicon-busy-3.ico', 'favicon-busy-3.ico'];
+
+    let interval = 0;
+    let i = 0;
+
+    app.serviceManager.sessions.runningChanged.connect((_, sessions) => {
+      const newIsBusy = sessions.map(s => s.kernel.execution_state).indexOf('busy') !== -1;
+      if (newIsBusy !== isBusy) {
+        isBusy = newIsBusy;
+        console.log({isBusy});
+        if (isBusy && !interval) {
+          interval = window.setInterval(() => {
+              favicon.href = `/static/base/images/${icons[i++ % 3]}`;
+          }, 300);
+        } else {
+            window.clearInterval(interval);
+            favicon.href = '/static/base/images/favicon.ico';
+            interval = i = 0;
+        }
+      }
+    });
   },
   autoStart: true
 };