add update checking using gitea api

This commit is contained in:
HorizonCode 2023-05-31 19:03:11 +02:00
parent fc284e08f0
commit fdfedab77f
4 changed files with 42 additions and 7 deletions

7
app.js
View File

@ -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) {

View File

@ -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 };
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 };

View File

@ -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",

View File

@ -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,