155 lines
3.9 KiB
JavaScript
155 lines
3.9 KiB
JavaScript
const log = require("./sub-log")
|
|
const { BrowserWindow, app, ipcMain } = require("electron")
|
|
const https = require('https');
|
|
const fs = require('fs');
|
|
const fse = require('fs-extra');
|
|
const BWin = BrowserWindow
|
|
const path = require("path")
|
|
const decompress = require('decompress');
|
|
|
|
function getSettings() {
|
|
|
|
var settings = {}
|
|
settings.canaldev = null
|
|
|
|
if(fs.existsSync(__dirname + path.sep + "settings.json")){
|
|
|
|
settings = JSON.parse(fs.readFileSync(__dirname + path.sep + "settings.json"))
|
|
}
|
|
|
|
return settings
|
|
}
|
|
|
|
module.exports.checkUpdate = () => {
|
|
|
|
var settings = getSettings()
|
|
|
|
log.update("Verification des mises a jour ... Processing !")
|
|
|
|
|
|
fetch("https://git.raphix.fr/subsonics/manager/raw/branch/main/package.json").catch(err => catchError(err)).then(resp => resp.json()).then(resp => checkUpdateProcessing(resp))
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
function checkUpdateProcessing(serverPackage) {
|
|
|
|
const clientPackage = require("./package")
|
|
|
|
if(serverPackage.version.replace(".", "") > clientPackage.version.replace(".", "")) {
|
|
|
|
log.update("Verification des mises a jour ... Finish !")
|
|
log.update("Mise a jour disponible ! Nouvelle version : " + serverPackage.version + " - Client : " + clientPackage.version + " - Git : " + serverPackage.version)
|
|
selfUpdate()
|
|
|
|
} else {
|
|
|
|
log.update("Verification des mises a jour ... Finish !")
|
|
log.update("Cette version est la derniere version ! - Client : " + clientPackage.version + " - Git : " + serverPackage.version)
|
|
}
|
|
|
|
}
|
|
|
|
function selfUpdate() {
|
|
|
|
var settings = getSettings()
|
|
|
|
const win = BWin.getFocusedWindow()
|
|
var link = "https://git.raphix.fr/subsonics/manager/archive/stable.tar.gz"
|
|
|
|
if(settings.canaldev == true) {
|
|
|
|
link = "https://git.raphix.fr/subsonics/manager/archive/main.tar.gz"
|
|
}
|
|
|
|
win.loadFile("templates/update/update.html")
|
|
|
|
ipcMain.on("close", () => {
|
|
|
|
app.quit()
|
|
})
|
|
|
|
log.update("Telechargement de la mise a jour ... Processing !")
|
|
|
|
if(fs.existsSync(__dirname + path.sep + "update.tar.gz")) {
|
|
|
|
fs.rmSync(__dirname + path.sep + "update.tar.gz")
|
|
}
|
|
|
|
const updatePack = fs.createWriteStream(__dirname + path.sep + "update.tar.gz");
|
|
const request = https.get(link, function(response) {
|
|
response.pipe(updatePack);
|
|
|
|
// after download completed close filestream
|
|
updatePack.on("finish", () => {
|
|
updatePack.close();
|
|
log.update("Telechargement de la mise a jour ... Finish !")
|
|
|
|
install(__dirname + path.sep + "update.tar.gz")
|
|
|
|
});
|
|
|
|
updatePack.on("error", (err) => {
|
|
log.update("Erreur lors du telechargement de la mise a jour !")
|
|
updatePack.close();
|
|
console.log(err)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
});
|
|
}
|
|
|
|
|
|
module.exports.update = () => {
|
|
|
|
selfUpdate()
|
|
}
|
|
|
|
function install(filename) {
|
|
|
|
log.update("Extraction de la mise a jour ... Processing !")
|
|
decompress(filename, __dirname).then(files => {
|
|
log.update("Extraction de la mise a jour ... Finish !")
|
|
log.update("Installation de la mise a jour ... Processing !")
|
|
fse.copy(__dirname + path.sep + "manager", __dirname, { overwrite: true }, () => {
|
|
fs.rm(filename, () => {
|
|
fs.rm(__dirname + path.sep + "manager", { recursive: true, force: true }, (err) => {
|
|
|
|
if(err) {
|
|
|
|
console.log(err)
|
|
}
|
|
|
|
log.update("Installation de la mise a jour ... Finish !")
|
|
log.update("Redemarrage de l'application.")
|
|
app.relaunch()
|
|
app.exit()
|
|
})
|
|
|
|
})
|
|
})
|
|
|
|
}).catch(err => catchError(err, true));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
function catchError(err, inUp) {
|
|
log.update("Erreur lors de la verification des mises a jour !")
|
|
log.update(err)
|
|
|
|
if(inUp == true) {
|
|
win.webContents.send("error")
|
|
|
|
}
|
|
|
|
} |