Display error/retry in case of failure

This commit is contained in:
TC
2019-05-01 19:31:35 +02:00
parent 15275236b0
commit 5a1d7fbf23
3 changed files with 65 additions and 2 deletions

50
error.html Normal file
View File

@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Cannot load YouTube Music</title>
<style>
body {
background: #000;
}
.container {
margin: 0;
font-family: Roboto, Arial, sans-serif;
font-size: 20px;
font-weight: 500;
color: rgba(255, 255, 255, 0.5);
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
text-align: center;
}
.button {
background: #065fd4;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: white;
font: inherit;
text-transform: uppercase;
text-decoration: none;
border-radius: 2px;
font-size: 16px;
font-weight: normal;
text-align: center;
padding: 8px 22px;
display: inline-block;
}
</style>
</head>
<body>
<div class="container">
<p>Cannot load YouTube Music… Internet disconnected?</p>
<a href="#" class="button" onclick="reload()">Retry</a>
</div>
</body>
</html>

View File

@ -72,6 +72,13 @@ function createMainWindow() {
});
});
win.webContents.on("did-fail-load", () => {
if (isDev) {
console.log("did fail load");
}
win.webContents.loadFile(path.join(__dirname, "error.html"));
});
win.webContents.on("did-navigate-in-page", () => {
const url = win.webContents.getURL();
if (url.startsWith("https://music.youtube.com")) {

View File

@ -1,6 +1,8 @@
const path = require("path");
const { getEnabledPlugins } = require("./store");
const { getCurrentWindow } = require("electron").remote;
const { getEnabledPlugins, store } = require("./store");
const { fileExists } = require("./plugins/utils");
const plugins = getEnabledPlugins();
@ -23,4 +25,8 @@ document.addEventListener("DOMContentLoaded", () => {
run();
});
});
// Add action for reloading
global.reload = () =>
getCurrentWindow().webContents.loadURL(store.get("url"));
});