Replace request and JSON5

This commit is contained in:
DeionSi 2023-01-13 22:15:48 +01:00
parent 1a809c304e
commit d6d77b94bd
2 changed files with 38 additions and 39 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "speedyloader", "name": "speedyloader",
"version": "1.5.1", "version": "1.5.0",
"description": "Speeduino universal firmware loader", "description": "Speeduino universal firmware loader",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
@ -30,7 +30,6 @@
}, },
"dependencies": { "dependencies": {
"electron-dl": "^3.5.0", "electron-dl": "^3.5.0",
"json5": "^2.2.3",
"marked": "^4.2.5", "marked": "^4.2.5",
"semver": "^7.3.8", "semver": "^7.3.8",
"@serialport/bindings-cpp": "^10.8.0", "@serialport/bindings-cpp": "^10.8.0",

View File

@ -1,6 +1,5 @@
const serialport = require('@serialport/bindings-cpp') const serialport = require('@serialport/bindings-cpp')
const usb = require('usb') const usb = require('usb')
const JSON5 = require('json5')
const {ipcRenderer} = require("electron") const {ipcRenderer} = require("electron")
const {remote} = require('electron') const {remote} = require('electron')
const { shell } = require('electron') const { shell } = require('electron')
@ -228,26 +227,28 @@ function refreshBasetunes()
//var url = "https://speeduino.com/fw/basetunes.json"; //var url = "https://speeduino.com/fw/basetunes.json";
var url = "https://github.com/speeduino/Tunes/raw/main/index.json"; var url = "https://github.com/speeduino/Tunes/raw/main/index.json";
var request = require('request'); fetch(url)
const options = { .then((response) => {
url: url, if (response.ok) {
headers: { return response.json();
'User-Agent': 'request'
} }
}; return Promise.reject(response);
})
.then((result) => {
request.get(options, function (error, response, body) { basetuneList = result;
if (!error ) console.log(result);
{
basetuneList = JSON5.parse(body);
//Remove the loading spinner //Remove the loading spinner
loadingSpinner = document.getElementById("baseTuneSpinner"); loadingSpinner = document.getElementById("baseTuneSpinner");
loadingSpinner.style.display = "none"; loadingSpinner.style.display = "none";
refreshBasetunes(); refreshBasetunes();
} })
.catch((error) => {
console.log('Could not download base tune list.', error);
}); });
} }
else else
{ {
@ -595,30 +596,29 @@ async function checkForUpdates()
var url = "https://api.github.com/repos/speeduino/SpeedyLoader/releases/latest"; var url = "https://api.github.com/repos/speeduino/SpeedyLoader/releases/latest";
//document.getElementById('detailsHeading').innerHTML = version; //document.getElementById('detailsHeading').innerHTML = version;
var request = require('request');
const options = {
url: url,
headers: {
'User-Agent': 'request'
}
};
request.get(options, function (error, response, body) { fetch(url)
if (!error ) .then((response) => {
if (response.ok) {
return response.json();
}
return Promise.reject(response);
})
.then((result) => {
latest_version = result.tag_name.substring(1);
console.log("Latest version: " + latest_version);
var semver = require('semver');
if(semver.gt(latest_version, current_version))
{ {
var result = JSON.parse(body); //New version has been found
latest_version = result.tag_name.substring(1); document.getElementById('update_url').setAttribute("href", result.html_url);
console.log("Latest version: " + latest_version); document.getElementById('update_text').style.display = "block";
var semver = require('semver');
if(semver.gt(latest_version, current_version))
{
//New version has been found
document.getElementById('update_url').setAttribute("href", result.html_url);
document.getElementById('update_text').style.display = "block";
}
} }
})
.catch((error) => {
console.log('Could not get latest version.', error);
}); });
} }