added error handling

This commit is contained in:
steev 2023-02-06 16:44:17 +01:00
parent 749e8b43d5
commit 3285770d97
7 changed files with 41 additions and 6 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
gittoken.json
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

View File

@ -1 +1 @@
{"token": "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"}
{"token": "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"}

View File

@ -18,8 +18,8 @@
<button class="download" id="download">Update to V<span id="latest">0.0.0</span></button>
</div>
<div class="col-7" id="download-section">
<h4 class="centered" id="progress-step">Downloading...</h4>
<div id="progress-bar"><span id="progress-label">100%</span></div>
<h4 class="centered" id="progress-step">idling<h4>
<div id="progress-bar"><span id="progress-label">0%</span></div>
</div>
</div>
</div>

View File

@ -15,7 +15,6 @@ const createWindow = () => {
width: 600,
height: 300,
backgroundColor: '#2f3241',
symbolColor: '#74b1be',
resizable: false,
titleBarStyle: 'hidden',
titleBarOverlay: true,
@ -40,7 +39,12 @@ async function initGithub (){
console.log(`token: %s`, token)
mainWindow.webContents.send("github-lookup", "looking up releases");
// Compare: https://docs.github.com/en/rest/reference/users#get-the-authenticated-user
const { data: { login }, } = await octokit.rest.users.getAuthenticated();
const { data: { login }, } = await octokit.rest.users.getAuthenticated().catch(async err => {
if (err) {
console.log(err);
mainWindow.webContents.send("error-message", {label: "authentication failed", err: err})
}
});
console.log("Hello, %s", login);
}

View File

@ -3,6 +3,7 @@
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
handleError: (callback) => ipcRenderer.on("error-message", callback),
updateProgress: (callback) => ipcRenderer.on('github-lookup', callback)
})

View File

@ -1,9 +1,27 @@
window.electronAPI.updateProgress(async (_event, value) => {
window.electronAPI.updateProgress((_event, value) => {
console.log(_event)
console.log(value)
updateProgressStep(value);
})
window.electronAPI.handleError((_event, value) => {
let error = `
<div class="titlebar">NCOS Companion</div>
<div class="content">
<h1 class="centered">An Error Occured</h1>
<div class="row">
<div class="col-12">
<h4 class="centered">${value.label}</h4>
<h4 class="centered">pleas report this to <a class="link" target="_blank" href="https://github.com/Vortex-Dynamics/NervUpdaterClient/issues">us</a></h4>
<pre class="centered">${value.err}</pre>
</div>
</div>
</div>
`;
document.querySelector("body").innerHTML = error;
})
function updateProgressBar(progress){
document.getElementById("progress-bar").style.width = progress + "%";
document.getElementById("progress-label").textContent = progress + "%";

View File

@ -13,6 +13,13 @@ h4 {
margin: 0;
margin-bottom: 10px;
}
pre {
border: 1px solid #74b1be;
border-radius: 5px;
padding: 5px;
}
.content {
padding-left: 15.5%;
padding-right: 15.5%;
@ -68,6 +75,10 @@ div[class^=col-] {
padding: 1rem 0
}
.link {
color: #74b1be;
}
.row {
display: flex;
flex-wrap: wrap