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

Add configurable choice of a JupyterLab launcher category to present registered proxies (Notebook, Console, Other) #244

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions jupyterlab-server-proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jupyterlab/server-proxy",
"version": "2.1.2",
"version": "2.1.2-dev",
"description": "Launcher icons for proxied applications",
"keywords": [
"jupyter",
Expand All @@ -15,6 +15,7 @@
"author": "Yuvi Panda",
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"schema/**/*.json",
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
],
"main": "lib/index.js",
Expand All @@ -32,13 +33,15 @@
"dependencies": {
"@jupyterlab/application": "^1.0.0 || ^2.0.0 || ^3.0.0",
"@jupyterlab/apputils": "^1.0.0 || ^2.0.0 || ^3.0.0",
"@jupyterlab/launcher": "^1.0.0 || ^2.0.0 || ^3.0.0"
"@jupyterlab/launcher": "^1.0.0 || ^2.0.0 || ^3.0.0",
"@jupyterlab/settingregistry": "^1.0.0 || ^2.0.0 || ^3.0.0"
},
"devDependencies": {
"rimraf": "^2.6.1",
"typescript": "~3.7.0"
},
"jupyterlab": {
"extension": true
"extension": true,
"schemaDir": "schema"
}
}
13 changes: 13 additions & 0 deletions jupyterlab-server-proxy/schema/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "Server Proxy",
"description": "Settings for the Server Proxy extension",
"type": "object",
"properties": {
"category": {
"type": "string",
"title": "Category",
"description": "Category of proxy launchers",
"default": "Notebook"
}
}
}
29 changes: 22 additions & 7 deletions jupyterlab-server-proxy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { JupyterFrontEnd, JupyterFrontEndPlugin, ILayoutRestorer } from '@jupyte
import { ILauncher } from '@jupyterlab/launcher';
import { PageConfig } from '@jupyterlab/coreutils';
import { IFrame, MainAreaWidget, WidgetTracker } from '@jupyterlab/apputils';
import { ISettingRegistry } from '@jupyterlab/settingregistry';

import '../style/index.css';


const EXTENSION_NAME = '@jupyterlab/server-proxy:plugin';

function newServerProxyWidget(id: string, url: string, text: string): MainAreaWidget<IFrame> {
const content = new IFrame({
sandbox: ['allow-same-origin', 'allow-scripts', 'allow-popups', 'allow-forms'],
Expand All @@ -19,7 +23,7 @@ function newServerProxyWidget(id: string, url: string, text: string): MainAreaWi
return widget;
}

async function activate(app: JupyterFrontEnd, launcher: ILauncher, restorer: ILayoutRestorer) : Promise<void> {
async function activate(app: JupyterFrontEnd, launcher: ILauncher, restorer: ILayoutRestorer, settingRegistry: ISettingRegistry): Promise<void> {
const response = await fetch(PageConfig.getBaseUrl() + 'server-proxy/servers-info');
if (!response.ok) {
console.log('Could not fetch metadata about registered servers. Make sure jupyter-server-proxy is installed.');
Expand All @@ -34,6 +38,16 @@ async function activate(app: JupyterFrontEnd, launcher: ILauncher, restorer: ILa
namespace
});
const command = namespace + ':' + 'open';
var category = 'Notebook';

if (settingRegistry) {
const setting = await settingRegistry.load(extension.id);
const updateSettings = (): void => {
category = setting.get('category').composite as string;
};
updateSettings();
setting.changed.connect(updateSettings);
}

if (restorer) {
void restorer.restore(tracker, {
Expand All @@ -60,7 +74,7 @@ async function activate(app: JupyterFrontEnd, launcher: ILauncher, restorer: ILa
return;
}
let widget = tracker.find((widget) => { return widget.content.id == id; });
if(!widget){
if (!widget) {
widget = newServerProxyWidget(id, url, title);
}
if (!tracker.has(widget)) {
Expand All @@ -84,19 +98,19 @@ async function activate(app: JupyterFrontEnd, launcher: ILauncher, restorer: ILa
const title = server_process.launcher_entry.title;
const newBrowserTab = server_process.new_browser_tab;
const id = namespace + ':' + server_process.name;
const launcher_item : ILauncher.IItemOptions = {
const launcher_item: ILauncher.IItemOptions = {
command: command,
args: {
url: url,
title: title + (newBrowserTab ? ' [↗]': ''),
title: title + (newBrowserTab ? ' [↗]' : ''),
newBrowserTab: newBrowserTab,
id: id
},
category: 'Notebook'
category: category
};

if (server_process.launcher_entry.icon_url) {
launcher_item.kernelIconUrl = server_process.launcher_entry.icon_url;
launcher_item.kernelIconUrl = server_process.launcher_entry.icon_url;
}
launcher.add(launcher_item);
}
Expand All @@ -106,9 +120,10 @@ async function activate(app: JupyterFrontEnd, launcher: ILauncher, restorer: ILa
* Initialization data for the jupyterlab-server-proxy extension.
*/
const extension: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-server-proxy',
id: EXTENSION_NAME,
autoStart: true,
requires: [ILauncher, ILayoutRestorer],
optional: [ISettingRegistry],
activate: activate
};

Expand Down