Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the browser tab favicon on kernel busy #6980

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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