From fdfedab77f115ca1c7032b3cecc42c46ae282b0f Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Wed, 31 May 2023 19:03:11 +0200 Subject: [PATCH] add update checking using gitea api --- app.js | 7 ++++++- appInfo.js | 22 +++++++++++++++++++--- package.json | 3 ++- preload/preload.js | 17 +++++++++++++++-- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 62f3a69..cd3cbf2 100644 --- a/app.js +++ b/app.js @@ -313,7 +313,7 @@ async function tryLogin(window) { window.webContents.send('account_update', { type: "loggedin", user: loginResponse.user - }) + }); } else { await config.remove("username"); await config.remove("password"); @@ -327,6 +327,11 @@ async function tryLogin(window) { type: "not-loggedin" }) } + + const checkUpdate = await appInfo.hasUpdate(); + if(checkUpdate){ + window.webContents.send('launcher_update', checkUpdate); + } } async function doUpdateCheck(window) { diff --git a/appInfo.js b/appInfo.js index eb72ddb..08d69b3 100644 --- a/appInfo.js +++ b/appInfo.js @@ -1,4 +1,20 @@ -const appName = "EZPPLauncher" -const appVersion = "1.1.3"; +const { default: axios } = require("axios"); +const { compareVersions } = require("compare-versions"); -module.exports = { appName, appVersion }; \ No newline at end of file +const appName = "EZPPLauncher" +const appVersion = "1.1.4"; + +const hasUpdate = async () => { + const releaseInfo = await axios.get(`https://git.ez-pp.farm/api/v1/repos/EZPPFarm/${appName}/releases/latest`); + if (releaseInfo.status !== 200) return false; + const latestReleaseVersion = releaseInfo.data.tag_name; + const updateAvailable = compareVersions(latestReleaseVersion, appVersion); + if(updateAvailable > 0) + return { + version: latestReleaseVersion, + url: releaseInfo.data.html_url, + } + return undefined; +} + +module.exports = { appName, appVersion, hasUpdate }; \ No newline at end of file diff --git a/package.json b/package.json index d7932f1..88eb632 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ezpplauncher", - "version": "1.1.3", + "version": "1.1.4", "main": "app.js", "license": "MIT", "author": "HorizonCode", @@ -46,6 +46,7 @@ }, "dependencies": { "axios": "^0.27.2", + "compare-versions": "^6.0.0-rc.1", "custom-electron-titlebar": "^4.1.1", "discord-auto-rpc": "^1.0.17", "discord-rpc": "^4.0.1", diff --git a/preload/preload.js b/preload/preload.js index 64b1bc7..befa71c 100644 --- a/preload/preload.js +++ b/preload/preload.js @@ -1,4 +1,4 @@ -const { ipcRenderer } = require('electron'); +const { ipcRenderer, shell } = require('electron'); const { Titlebar, Color } = require('custom-electron-titlebar'); const appInfo = require('../appInfo'); let titlebar; @@ -150,10 +150,23 @@ window.addEventListener('DOMContentLoaded', () => { } }) + ipcRenderer.on('launcher_update', async (event, data) => { + const res = await Swal.fire({ + title: 'Update available!', + text: `Version ${data.version} has been released!`, + icon: 'info', + showCancelButton: true, + confirmButtonText: 'Download', + cancelButtonText: 'Remind me later', + }); + if (res.isConfirmed) { + shell.openExternal(data.url); + } + }) + ipcRenderer.on('account_update', (event, data) => { switch (data.type) { case "login-failed": - console.log(data); Swal.fire({ title: 'Uh oh!', text: data.message,