From 47ffe6e80fc044260157371da4b49ea5ee8353f1 Mon Sep 17 00:00:00 2001 From: monoid Date: Sun, 10 Jan 2021 03:12:51 +0900 Subject: [PATCH] add to display simple error --- app.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/app.ts b/app.ts index 05a8116..adac428 100644 --- a/app.ts +++ b/app.ts @@ -2,7 +2,7 @@ import { app, BrowserWindow } from "electron"; import { get_setting } from "./src/setting"; import { create_server, start_server } from "./src/server"; -const loading_html = ` +const get_loading_html = (content?:string)=> ` react-sample @@ -28,8 +28,8 @@ h1 { } -

Loading

-
+

${content || "Loading..."}

+ ${content === undefined ? '
' : ""} `; @@ -45,10 +45,20 @@ if (!setting.cli) { center: true, useContentSize: true, }); - await window.loadURL(`data:text/html;base64,`+Buffer.from(loading_html).toString('base64')); - const server = await create_server(); - start_server(server); - await window.loadURL(`http://localhost:${setting.port}`); + await window.loadURL(`data:text/html;base64,`+Buffer.from(get_loading_html()).toString('base64')); + try{ + const server = await create_server(); + start_server(server); + await window.loadURL(`http://localhost:${setting.port}`); + } + catch(e){ + if(e instanceof Error){ + await window.loadURL(`data:text/html;base64,`+Buffer.from(get_loading_html("Error : "+e.message)).toString('base64')); + } + else{ + await window.loadURL(`data:text/html;base64,`+Buffer.from(get_loading_html("Error : "+e)).toString('base64')); + } + } window.on("closed", () => { window = null; });