From 7d2eeb9e69da481dab9b6c3080cb839f7dca3011 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 13 Oct 2022 21:55:09 +0200 Subject: [PATCH] Fix updater (well I think too) --- src/server/updater.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/server/updater.js b/src/server/updater.js index f33c289..894b6a2 100644 --- a/src/server/updater.js +++ b/src/server/updater.js @@ -56,27 +56,33 @@ class Updater { win.loadFile('src/client/login.html') }) } else { - fetch(feed).then(response => { - if(response.status === 200) { - response.json().then(json => { - win.webContents.send("please-download-update", { url: json.url} ) - }) - } else { - if(response.status === 204) { - this.logger.info("update not available") - win.loadFile('src/client/login.html') - } else { - this.displayError(win, showNotification, "Server return " + response.status + " http code") - } - - } - }).catch(err => { - this.displayError(win, showNotification, err) - }) + this.searchUpdateLinux(win, showNotification) } } + searchUpdateLinux(win, showNotification) { + const url = 'https://api.github.com/repos/AltarikMc/Launcher/releases/latest' + fetch(url).then(response => { + if(response.status === 200) { + response.json().then(json => { + if(json.tag_name !== pkg.version) { + let asset = json.assets.filter(el => el.browser_download_url.inludes(".zip")) + if(asset.length ===1) { + let downloadUrl = asset[0].browser_download_url + win.webContents.send("please-download-update", { url: downloadUrl} ) + } else { + this.displayError(win, showNotification, "Can't find right asset in last update") + } + } + }).catch(err => this.displayError(win, showNotification, err) + ) + } else { + this.displayError(win, showNotification, "Server unavailable") + } + }).catch(err => this.displayError(win, showNotification, err)) + } + displayError(win, showNotification, errorMessage) { this.logger.error('There was a problem updating the application') this.logger.error(errorMessage)