Skip to content

Commit

Permalink
Merge pull request #6399 from ian-r-rose/connection-lost-token
Browse files Browse the repository at this point in the history
Connection lost token
  • Loading branch information
vidartf committed May 24, 2019
2 parents 7fb34cd + 6716a08 commit 4d1eeba
Show file tree
Hide file tree
Showing 15 changed files with 359 additions and 178 deletions.
25 changes: 23 additions & 2 deletions packages/application-extension/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Distributed under the terms of the Modified BSD License.

import {
ConnectionLost,
IConnectionLost,
ILabShell,
ILabStatus,
ILayoutRestorer,
Expand Down Expand Up @@ -73,10 +75,11 @@ namespace CommandIDs {
*/
const main: JupyterFrontEndPlugin<void> = {
id: '@jupyterlab/application-extension:main',
requires: [ICommandPalette, IRouter, IWindowResolver],
requires: [ICommandPalette, IConnectionLost, IRouter, IWindowResolver],
activate: (
app: JupyterFrontEnd,
palette: ICommandPalette,
connectionLost: IConnectionLost,
router: IRouter,
resolver: IWindowResolver
) => {
Expand Down Expand Up @@ -108,6 +111,10 @@ const main: JupyterFrontEndPlugin<void> = {
app.commands.notifyCommandChanged();
});

// If the connection to the server is lost, handle it with the
// connection lost token.
app.serviceManager.connectionFailure.connect(connectionLost);

const builder = app.serviceManager.builder;
const build = () => {
return builder
Expand Down Expand Up @@ -741,6 +748,19 @@ const paths: JupyterFrontEndPlugin<JupyterFrontEnd.IPaths> = {
provides: JupyterFrontEnd.IPaths
};

/**
* The default JupyterLab connection lost provider. This may be overridden
* to provide custom behavior when a connection to the server is lost.
*/
const connectionlost: JupyterFrontEndPlugin<IConnectionLost> = {
id: '@jupyterlab/apputils-extension:connectionlost',
activate: (app: JupyterFrontEnd): IConnectionLost => {
return ConnectionLost;
},
autoStart: true,
provides: IConnectionLost
};

/**
* Export the plugins as default.
*/
Expand All @@ -755,7 +775,8 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
shell,
status,
info,
paths
paths,
connectionlost
];

export default plugins;
41 changes: 41 additions & 0 deletions packages/application/src/connectionlost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { showErrorMessage } from '@jupyterlab/apputils';

import { ServerConnection, ServiceManager } from '@jupyterlab/services';

import { IConnectionLost } from './tokens';

/**
* A default connection lost handler, which brings up an error dialog.
*/
export const ConnectionLost: IConnectionLost = async function(
manager: ServiceManager.IManager,
err: ServerConnection.NetworkError
): Promise<void> {
if (Private.showingError) {
return;
}
Private.showingError = true;

const title = 'Server Connection Error';
const networkMsg =
'A connection to the Jupyter server could not be established.\n' +
'JupyterLab will continue trying to reconnect.\n' +
'Check your network connection or Jupyter server configuration.\n';

return showErrorMessage(title, { message: networkMsg }).then(() => {
Private.showingError = false;
});
};

/**
* A namespace for module private functionality.
*/
namespace Private {
/**
* Whether the connection lost error is currently being shown.
*/
export let showingError = false;
}
6 changes: 5 additions & 1 deletion packages/application/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// Local CSS must be loaded prior to loading other libs.
import '../style/index.css';

export { ConnectionLost } from './connectionlost';

export { JupyterFrontEnd, JupyterFrontEndPlugin } from './frontend';

export { JupyterLab } from './lab';
Expand All @@ -12,8 +14,10 @@ export { ILayoutRestorer, LayoutRestorer } from './layoutrestorer';

export { IMimeDocumentTracker } from './mimerenderers';

export { IRouter, Router } from './router';
export { Router } from './router';

export { ILabShell, LabShell } from './shell';

export { ILabStatus } from './status';

export * from './tokens';
149 changes: 2 additions & 147 deletions packages/application/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,158 +7,13 @@ import { URLExt } from '@jupyterlab/coreutils';

import { CommandRegistry } from '@phosphor/commands';

import {
PromiseDelegate,
ReadonlyJSONObject,
Token
} from '@phosphor/coreutils';
import { PromiseDelegate, Token } from '@phosphor/coreutils';

import { DisposableDelegate, IDisposable } from '@phosphor/disposable';

import { ISignal, Signal } from '@phosphor/signaling';

/* tslint:disable */
/**
* The URL Router token.
*/
export const IRouter = new Token<IRouter>('@jupyterlab/application:IRouter');
/* tslint:enable */

/**
* A static class that routes URLs within the application.
*/
export interface IRouter {
/**
* The base URL for the router.
*/
readonly base: string;

/**
* The command registry used by the router.
*/
readonly commands: CommandRegistry;

/**
* The parsed current URL of the application.
*/
readonly current: IRouter.ILocation;

/**
* A signal emitted when the router routes a route.
*/
readonly routed: ISignal<IRouter, IRouter.ILocation>;

/**
* If a matching rule's command resolves with the `stop` token during routing,
* no further matches will execute.
*/
readonly stop: Token<void>;

/**
* Navigate to a new path within the application.
*
* @param path - The new path or empty string if redirecting to root.
*
* @param options - The navigation options.
*/
navigate(path: string, options?: IRouter.INavOptions): void;

/**
* Register a rule that maps a path pattern to a command.
*
* @param options - The route registration options.
*
* @returns A disposable that removes the registered rule from the router.
*/
register(options: IRouter.IRegisterOptions): IDisposable;

/**
* Cause a hard reload of the document.
*/
reload(): void;

/**
* Route a specific path to an action.
*
* @param url - The URL string that will be routed.
*
* #### Notes
* If a pattern is matched, its command will be invoked with arguments that
* match the `IRouter.ILocation` interface.
*/
route(url: string): void;
}

/**
* A namespace for the `IRouter` specification.
*/
export namespace IRouter {
/**
* The parsed location currently being routed.
*/
export interface ILocation extends ReadonlyJSONObject {
/**
* The location hash.
*/
hash: string;

/**
* The path that matched a routing pattern.
*/
path: string;

/**
* The request being routed with the router `base` omitted.
*
* #### Notes
* This field includes the query string and hash, if they exist.
*/
request: string;

/**
* The search element, including leading question mark (`'?'`), if any,
* of the path.
*/
search: string;
}

/**
* The options passed into a navigation request.
*/
export interface INavOptions {
/**
* Whether the navigation should be hard URL change instead of an HTML
* history API change.
*/
hard?: boolean;

/**
* Whether the navigation should be added to the browser's history.
*/
silent?: boolean;
}

/**
* The specification for registering a route with the router.
*/
export interface IRegisterOptions {
/**
* The command string that will be invoked upon matching.
*/
command: string;

/**
* The regular expression that will be matched against URLs.
*/
pattern: RegExp;

/**
* The rank order of the registered rule. A lower rank denotes a higher
* priority. The default rank is `100`.
*/
rank?: number;
}
}
import { IRouter } from './tokens';

/**
* A static class that routes URLs within the application.
Expand Down

0 comments on commit 4d1eeba

Please sign in to comment.