Skip to content

Commit

Permalink
Update browser tab favicon on kernel busy (#6980)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio authored Jul 27, 2023
1 parent fe4799a commit 2270c04
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,51 @@ const notebookToolsWidget: JupyterFrontEndPlugin<void> = {
},
};

/**
* A plugin to update the tab icon based on the kernel status.
*/
const tabIcon: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/notebook-extension:tab-icon',
autoStart: true,
requires: [INotebookTracker],
activate: (app: JupyterFrontEnd, tracker: INotebookTracker) => {
// the favicons are provided by Jupyter Server
const notebookIcon = ' /static/favicons/favicon-notebook.ico';
const busyIcon = ' /static/favicons/favicon-busy-1.ico';

const updateBrowserFavicon = (
status: ISessionContext.KernelDisplayStatus
) => {
const link = document.querySelector(
"link[rel*='icon']"
) as HTMLLinkElement;
switch (status) {
case 'busy':
link.href = busyIcon;
break;
case 'idle':
link.href = notebookIcon;
break;
}
};

const onChange = async () => {
const current = tracker.currentWidget;
const sessionContext = current?.sessionContext;
if (!sessionContext) {
return;
}

sessionContext.statusChanged.connect(() => {
const status = sessionContext.kernelDisplayStatus;
updateBrowserFavicon(status);
});
};

tracker.currentChanged.connect(onChange);
},
};

/**
* A plugin that adds a Trusted indicator to the menu area
*/
Expand Down Expand Up @@ -441,8 +486,9 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
closeTab,
kernelLogo,
kernelStatus,
scrollOutput,
notebookToolsWidget,
scrollOutput,
tabIcon,
trusted,
];

Expand Down

0 comments on commit 2270c04

Please sign in to comment.