Skip to content
Merged
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
4 changes: 4 additions & 0 deletions client/client-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const urls = {
dev: `file://${root}/client/splash-screen/splash-screen.html`,
prod: `file://${root}/build/client/splash-screen/splash-screen.html`,
},
recover: {
dev: `file://${root}/client/recover-window/recover-window.html`,
prod: `file://${root}/build/client/recover-window/recover-window.html`,
},
icon: __dirname + "/../assets/images/icon.ico",
};

Expand Down
4 changes: 3 additions & 1 deletion client/core/global.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { AuthenticationWindow } from "../authentication";
import { MainWindow } from "../main-window";
import { RecoverWindow } from "../recover-window";
import { SplashScreen } from "../splash-screen";

const splashScreen = new SplashScreen();
const authenticationWindow = new AuthenticationWindow();
const recoverWindow = new RecoverWindow();
const mainWindow = new MainWindow();

/**
* Set of unique windows used across the app
*/
export const windows = { splashScreen, authentication: authenticationWindow, main: mainWindow };
export const windows = { splashScreen, authentication: authenticationWindow, main: mainWindow, recover: recoverWindow };
20 changes: 19 additions & 1 deletion client/main-window/main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class MainWindow extends UniqueWindow {
},
});
const url = process.env.HOT ? devServerUrl : buildFileUrl;

this._setupEvents(window);
window.loadURL(url);

const anyWindow = window as any;
Expand Down Expand Up @@ -59,4 +59,22 @@ export class MainWindow extends UniqueWindow {

return window;
}

private _setupEvents(window: Electron.BrowserWindow) {
window.webContents.on("crashed", (error: Error) => {
logger.error("There was a crash", error);
windows.recover.createWithError(error.message);
});

window.webContents.on("did-fail-load", (error) => {
windows.splashScreen.updateMessage(
"Fail to load! Make sure you built the app or are running the dev-server.");
logger.error("Fail to load", error);
});

window.on("unresponsive", (error: Error) => {
logger.error("There was a crash", error);
windows.recover.createWithError(error.message);
});
}
}
25 changes: 24 additions & 1 deletion client/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { app, protocol } from "electron";
import { app, ipcMain, protocol } from "electron";
import * as path from "path";

app.setPath("userData", path.join(app.getPath("appData"), "batch-labs"));

import { windows } from "./core";
import { logger } from "./logger";

// Create the browser window.
function createWindow() {
Expand Down Expand Up @@ -40,3 +41,25 @@ app.on("activate", () => {
createWindow();
}
});

ipcMain.once("exit", () => {
process.exit(1);
});

ipcMain.on("reload", () => {
// Destroy window and error window if applicable
windows.main.destroy();
windows.recover.destroy();

// Show splash screen
windows.splashScreen.create();
windows.splashScreen.updateMessage("Loading app");

// Reopen a new window
windows.main.create();
});

process.on("uncaughtException", (error: Error) => {
logger.error("There was a uncaught exception", error);
windows.recover.createWithError(error.message);
});
1 change: 1 addition & 0 deletions client/recover-window/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./recover-window";
108 changes: 108 additions & 0 deletions client/recover-window/recover-window.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!DOCTYPE html>
<style>
* {
box-sizing: border-box;
}

body {
background: #00416f;
width: 100vw;
height: 100vh;
font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif
}

body {
overflow: hidden;
margin: 0;
padding: 0;
}

.title {
color: #d5d5d5;
padding: 20px;
font-size: 20px;
text-align: center;
}

#message {
color: #d5d5d5;
font-size: 12px;
bottom: 5px;
padding: 10px;
}

.content {
height: calc(100vh - 60px);
}

.footer {
height: 60px;
width: 100vw;
background: #36719a;
padding: 15px;
}

.action-btns {
height: 30px;
width: 240px;
margin: auto;
}

.reload,
.exit {
background: #f5f5f5;
border: none;
padding: 5px;
color: #333;
width: 100px;
height: 30px;
cursor: pointer;
margin: 0 5px;
}

.reload:hover,
.exit:hover {
background-color: #94bdd9;
}
</style>
<html>

<script>
const { ipcRenderer } = require("electron");
document.addEventListener("DOMContentLoaded", () => {
const message = document.getElementById("message");
ipcRenderer.on("update-message", (event, arg) => {
message.innerHTML = arg;
});
})

function exit() {
console.log("Exit...");
ipcRenderer.send("exit", true);
}

function reload() {
ipcRenderer.send("reload", true);
}

</script>

<body>
<div class="content">
<div class="title">
Oops! There was an error in batch labs
</div>

<div id="message">
Blabal lots off errors....
</div>
</div>
<div class="footer">
<div class="action-btns">
<button onclick="reload()" class="reload">Reload</button>
<button onclick="exit()" class="exit">Exit</button>
</div>
</div>
</body>

</html>
51 changes: 51 additions & 0 deletions client/recover-window/recover-window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { BrowserWindow } from "electron";
import { Constants } from "../client-constants";
import { UniqueWindow } from "../core";

const urls = Constants.urls.recover;
const url = process.env.HOT ? urls.dev : urls.prod;

export class RecoverWindow extends UniqueWindow {
private _currentMessage = "";

public createWithError(message: string) {
this.create();
this.updateErrorMessage(message);
}

public updateErrorMessage(message: string) {
this._currentMessage = message;
this._sendMessageToWindow();
}

public destroy() {
super.destroy();
this.clearMessage();
}

public clearMessage() {
this.updateErrorMessage("");
}

protected createWindow() {
const window = new BrowserWindow({
height: 440,
width: 440,
icon: Constants.urls.icon,
resizable: false,
titleBarStyle: "hidden",
frame: false,
});
window.loadURL(url);
window.webContents.once("dom-ready", () => {
this._sendMessageToWindow();
});
return window;
}

private _sendMessageToWindow() {
if (this._window) {
this._window.webContents.send("update-message", this._currentMessage);
}
}
}