Skip to content

Commit

Permalink
Merge pull request #117 from nproctor/error-page-transition
Browse files Browse the repository at this point in the history
Add error page transition and logging
  • Loading branch information
lucbouchard1 committed Aug 10, 2017
2 parents 84ba758 + de4ad6a commit 3e31abe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jupyterlab_app",
"version": "0.1.0",
"version": "0.1.1",
"description": "A native app for JupyterLab, based on electron.",
"main": "build/main.bundle.js",
"scripts": {
Expand Down
28 changes: 15 additions & 13 deletions src/browser/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Application extends React.Component<Application.Props, Application.State>
super(props);
this._renderServerManager = this._renderServerManager.bind(this);
this._renderSplash = this._renderSplash.bind(this);
this._renderLab = this._renderLab.bind(this);
this._renderEmpty = this._renderEmpty.bind(this);
this._renderErrorScreen = this._renderErrorScreen.bind(this);
this._connectionAdded = this._connectionAdded.bind(this);
this._launchFromPath = this._launchFromPath.bind(this);
Expand All @@ -55,6 +55,7 @@ class Application extends React.Component<Application.Props, Application.State>
if (data.err) {
console.error(data.err);
this.setState({renderState: this._renderErrorScreen});
(this.refs.splash as SplashScreen).fadeSplashScreen();
return;
}

Expand Down Expand Up @@ -86,10 +87,10 @@ class Application extends React.Component<Application.Props, Application.State>
});

if (this.props.options.serverState == 'local') {
this.state = {renderState: this._renderSplash, remotes: []};
this.state = {renderSplash: this._renderSplash, renderState: this._renderEmpty, remotes: []};
ipcRenderer.send(ServerIPC.REQUEST_SERVER_START);
} else {
this.state = {renderState: this._renderServerManager, remotes: []};
this.state = {renderSplash: this._renderEmpty, renderState: this._renderServerManager, remotes: []};
}

this._serverState = new StateDB({namespace: Application.STATE_NAMESPACE});
Expand All @@ -115,10 +116,12 @@ class Application extends React.Component<Application.Props, Application.State>
}

render() {
let splash = this.state.renderSplash();
let content = this.state.renderState();

return (
<div className='jpe-body'>
{splash}
{content}
</div>
);
Expand All @@ -128,8 +131,8 @@ class Application extends React.Component<Application.Props, Application.State>
ipcRenderer.send(ServerIPC.REQUEST_SERVER_START_PATH);

let pathSelected = () => {
this.setState({renderState: this._renderSplash});
ipcRenderer.removeListener(ServerIPC.POST_PATH_SELECTED, pathSelected);
this.setState({renderSplash: this._renderSplash, renderState: this._renderEmpty});
}
ipcRenderer.on(ServerIPC.POST_PATH_SELECTED, pathSelected);
}
Expand Down Expand Up @@ -189,12 +192,12 @@ class Application extends React.Component<Application.Props, Application.State>
});

let rServer: Application.IRemoteServer = {...server, id: this._nextRemoteId++};

this.setState((prev: ServerManager.State) => {
server.id = this._nextRemoteId++;
let conns = this.state.remotes.concat(rServer);
this._saveState();
return({
renderState: this._renderLab,
renderState: this._renderEmpty,
conns: {servers: conns}
});
});
Expand All @@ -213,18 +216,12 @@ class Application extends React.Component<Application.Props, Application.State>
return (
<div className='jpe-content'>
<SplashScreen ref='splash' uiState={this.props.options.uiState} finished={() => {
this.setState({renderState: this._renderLab});}
this.setState({renderSplash: this._renderEmpty});}
} />
</div>
);
}

private _renderLab(): JSX.Element {
this._saveState();

return null;
}

private _renderErrorScreen(): JSX.Element {
return (
<div className='jpe-content'>
Expand All @@ -234,6 +231,10 @@ class Application extends React.Component<Application.Props, Application.State>
)
}

private _renderEmpty(): JSX.Element {
return null;
}

private _lab: ElectronJupyterLab;

private _ignorePlugins: string[] = ['jupyter.extensions.server-manager'];
Expand Down Expand Up @@ -270,6 +271,7 @@ namespace Application {
export
interface State {
renderState: () => any;
renderSplash: () => any;
remotes: IRemoteServer[];
}

Expand Down
29 changes: 16 additions & 13 deletions src/main/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class JupyterServer {
let home = app.getPath("home");

if (this._info.path) {
this._nbServer = execFile(join(this._info.path, 'jupyter'), ['notebook', '--no-browser']);
this._nbServer = execFile(join(this._info.path, 'jupyter'), ['notebook', '--no-browser'], {cwd: home});
} else if (process.platform === "win32") {
// Windows will return win32 (even for 64-bit)
// Dont spawn shell for Windows
Expand All @@ -60,12 +60,12 @@ class JupyterServer {

this._nbServer.on('exit', () => {
this._serverStartFailed();
reject(new Error('Jupyter not installed'));
reject(new Error('Could not find Jupyter in PATH'));
});

this._nbServer.on('error', (err: Error) => {
this._serverStartFailed();
reject(err);
reject(new Error('Could not find Jupyter in PATH'));
});

this._nbServer.stderr.on('data', (serverBuff: string) => {
Expand All @@ -78,7 +78,7 @@ class JupyterServer {

if (!token) {
this._cleanupListeners();
reject(new Error("Update Jupyter version"));
reject(new Error("Update Jupyter notebook to version 4.3.0 or greater"));
return;
}

Expand Down Expand Up @@ -169,10 +169,10 @@ class JupyterServerFactory {
ipcMain.on(ServerIPC.REQUEST_SERVER_START, (event: any) => {
this.requestServerStart({})
.then((data: JupyterServerFactory.IFactoryItem) => {
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._factoryToIPC(data))
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._factoryToIPC(data));
})
.catch((e: any) => {
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._errorToIPC(e))
.catch((e: Error) => {
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._errorToIPC(e));
});
});

Expand All @@ -182,14 +182,17 @@ class JupyterServerFactory {
event.sender.send(ServerIPC.POST_PATH_SELECTED);
this.requestServerStart({path})
.then((data: JupyterServerFactory.IFactoryItem) => {
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._factoryToIPC(data))
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._factoryToIPC(data));
})
.catch((e) => {
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._errorToIPC(e))
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._errorToIPC(e));
});
})
.catch((e: any) => {
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._errorToIPC(e))
.catch((e: Error) => {
if (e.message !== 'cancel'){
event.sender.send(ServerIPC.RESPOND_SERVER_STARTED, this._errorToIPC(e));

}
});
});

Expand Down Expand Up @@ -289,7 +292,7 @@ class JupyterServerFactory {
buttonLabel: 'Use Path'
}, (filePaths: string[]) => {
if (!filePaths) {
rej(new Error('No path selected'));
rej(new Error('cancel'));
return;
} else {
res(filePaths[0]);
Expand All @@ -313,7 +316,7 @@ class JupyterServerFactory {
factoryId: -1,
url: null,
token: null,
err: e || new Error('Server creation error')
err: e.message || 'Server creation error'
};
}

Expand Down

0 comments on commit 3e31abe

Please sign in to comment.