Skip to content
Open
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
10 changes: 10 additions & 0 deletions jupyter_app_launcher/schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
"catalog": {
"type": "string"
},
"options": {
"anyOf": [
{
"type": "object"
},
{
"type": "array"
}
]
},
"args": {
"anyOf": [
{
Expand Down
87 changes: 63 additions & 24 deletions src/factories/local_server/local_server_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@ import { requestAPI } from '../../handler';
import { ILauncherConfiguration } from '../../schema';
import { IDict, IPanelFactory } from '../../token';
import { ILauncherApp } from './../../token';
import { Dialog } from '@jupyterlab/apputils';

function showTemporaryPopup(title: string) {
const dialog = new Dialog({
title: 'Loading',
body: 'Please wait a few seconds until ' + title + ' has started...',
buttons: []
});

// Show the dialog
dialog.launch();

// Close the dialog after 3 seconds
setTimeout(() => {
dialog.dispose();
}, 3000);
}

export class LocalServerFactory implements IPanelFactory {
async create(
config: ILauncherConfiguration,
args: IDict
): Promise<ILauncherApp> {
): Promise<ILauncherApp | void> {
const instanceId = UUID.uuid4();
const serverUrlPromise = requestAPI<string>({
method: 'POST',
Expand All @@ -21,34 +38,56 @@ export class LocalServerFactory implements IPanelFactory {
instanceId
})
});
const widget = new IFrame({
sandbox: [
'allow-same-origin',
'allow-scripts',
'allow-downloads',
'allow-modals',
'allow-popups'
]
});
const baseUrl = PageConfig.getBaseUrl();
widget.title.label = config.title;
widget.title.closable = true;
widget.disposed.connect(async () => {
await requestAPI<string>({
method: 'POST',
body: JSON.stringify({
method: 'terminate_resources',
id: config.id,
instanceId
})

let createNewWindow: boolean = false;
if (config.args) {
createNewWindow = (config.options as IDict)['createNewWindow'];
}

let widget: IFrame | undefined;

if (!createNewWindow) {
widget = new IFrame({
sandbox: [
'allow-same-origin',
'allow-scripts',
'allow-downloads',
'allow-modals',
'allow-popups'
]
});
});
widget.title.label = config.title;
widget.title.closable = true;
widget.disposed.connect(async () => {
await requestAPI<string>({
method: 'POST',
body: JSON.stringify({
method: 'terminate_resources',
id: config.id,
instanceId
})
});
});
} else {
showTemporaryPopup(config.title);
}
const baseUrl = PageConfig.getBaseUrl();
const ready = new PromiseDelegate<void>();

serverUrlPromise.then(url => {
widget.url = baseUrl + url;
if (createNewWindow) {
window.open(baseUrl + url, '_blank');
} else {
if (widget !== undefined) {
widget.url = baseUrl + url;
}
}
ready.resolve();
});
return { panel: widget, ready: ready.promise };
if (widget !== undefined) {
return { panel: widget, ready: ready.promise };
} else {
return;
}
}
}
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ async function activate(
config.type === 'jupyterlab-commands'
) {
skipMainAreaWidget = true;
} else if (
config.type === 'local-server' &&
(config.options as IDict)['createNewWindow']
) {
skipMainAreaWidget = true;
} else if (
config.type === 'url' &&
(config.args as IDict)['createNewWindow']
Expand Down
5 changes: 5 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export interface ILauncherConfiguration {
| 'jupyterlab-commands'
| 'terminal';
catalog?: string;
options?:
| {
[k: string]: any;
}
| any[];
args?:
| {
[k: string]: any;
Expand Down