add to display simple error

This commit is contained in:
monoid 2021-01-10 03:12:51 +09:00
parent 05814d8a31
commit 47ffe6e80f

18
app.ts
View File

@ -2,7 +2,7 @@ import { app, BrowserWindow } from "electron";
import { get_setting } from "./src/setting"; import { get_setting } from "./src/setting";
import { create_server, start_server } from "./src/server"; import { create_server, start_server } from "./src/server";
const loading_html = `<!DOCTYPE html> const get_loading_html = (content?:string)=> `<!DOCTYPE html>
<html lang="ko"><head> <html lang="ko"><head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>react-sample</title> <title>react-sample</title>
@ -28,8 +28,8 @@ h1 {
} }
</style> </style>
<body> <body>
<h1>Loading</h1> <h1>${content || "Loading..."}</h1>
<div id="loading"></div> ${content === undefined ? '<div id="loading"></div>' : ""}
</body> </body>
</html> </html>
`; `;
@ -45,10 +45,20 @@ if (!setting.cli) {
center: true, center: true,
useContentSize: true, useContentSize: true,
}); });
await window.loadURL(`data:text/html;base64,`+Buffer.from(loading_html).toString('base64')); await window.loadURL(`data:text/html;base64,`+Buffer.from(get_loading_html()).toString('base64'));
try{
const server = await create_server(); const server = await create_server();
start_server(server); start_server(server);
await window.loadURL(`http://localhost:${setting.port}`); 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.on("closed", () => {
window = null; window = null;
}); });