74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import {
|
|
JupyterFrontEnd,
|
|
JupyterFrontEndPlugin
|
|
} from '@jupyterlab/application';
|
|
import { Widget } from '@lumino/widgets';
|
|
import { LogoAnnounce} from './images';
|
|
import { MainAreaWidget } from '@jupyterlab/apputils';
|
|
function generateContent(): string {
|
|
return 'Welcome to Sandbox Playground';
|
|
}
|
|
function createNode(): HTMLElement {
|
|
let node = document.createElement('div');
|
|
node.className = "sandbox-announcement-container"
|
|
let content = document.createElement('div');
|
|
content.className = "sandbox-announcement-content"
|
|
let image = document.createElement('img');
|
|
image.src=LogoAnnounce;
|
|
image.className = "sandbox-announcement-icon"
|
|
content.appendChild(image);
|
|
let text = document.createElement('h2');
|
|
text.textContent = "Sandbox Playground"
|
|
text.className = "sandbox-announcement-text"
|
|
content.appendChild(text)
|
|
node.appendChild(content);
|
|
return node;
|
|
}
|
|
/**
|
|
* Initialization data for the jupyterlab-sandbox-announcement extension.
|
|
*/
|
|
const plugin: JupyterFrontEndPlugin<void> = {
|
|
id: 'jupyterlab-sandbox-announcement:plugin',
|
|
description: 'A Jupyterlab Sandbox customization',
|
|
autoStart: true,
|
|
activate: (app: JupyterFrontEnd) => {
|
|
console.log('JupyterLab extension jupyterlab-sandbox-announcement is activated!');
|
|
const widget = new Widget();
|
|
widget.id = "sandbox-announce"
|
|
widget.addClass('sandbox-announcement-contentheader-widget');
|
|
//widget.node.textContent = generateContent();
|
|
console.log(generateContent())
|
|
widget.node.appendChild(createNode())
|
|
setInterval(() => {
|
|
const main = app.shell.currentWidget;
|
|
if (main !=null){
|
|
console.log(main);
|
|
}
|
|
|
|
if (main instanceof MainAreaWidget) {
|
|
|
|
// if (main.title.label == 'Launcher'){
|
|
// console.log(main.title.label);
|
|
// }
|
|
let add = true;
|
|
// and insert it into the header
|
|
main.contentHeader.widgets.forEach(function (w: Widget) {
|
|
if (w.id=="sandbox-announce"){
|
|
//w.dispose()
|
|
add = false
|
|
}
|
|
});
|
|
if (add){
|
|
console.log("add")
|
|
|
|
main.contentHeader.addWidget(widget);
|
|
}
|
|
|
|
}
|
|
|
|
}, 200);
|
|
}
|
|
};
|
|
|
|
export default plugin;
|