From 142b49693a781205f0bfca80b221417984ae7dc0 Mon Sep 17 00:00:00 2001 From: AquaJo <84229101+AquaJo@users.noreply.github.com> Date: Mon, 19 Aug 2024 02:57:41 +0200 Subject: [PATCH] adjustments to fit new update checking method --- .vscode/settings.json | 1 + package.json | 2 +- src/index.js | 6 ++ src/settings/src/updates/UpdateMain.vue | 78 ++++++++++++++++++++++--- 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5807f39..672f64d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "files.trimTrailingWhitespace": true, "cSpell.words": [ "BTNS", + "deanimate", "electronjs", "Emran", "Garreau", diff --git a/package.json b/package.json index 146ce7e..c07012c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "huefl", - "version": "0.0.3", + "version": "0.0.2", "description": "abc", "main": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 84d5e04..c5b3264 100644 --- a/src/index.js +++ b/src/index.js @@ -67,6 +67,12 @@ if (!gotTheLock) { // temporary update checking insert if (app.isPackaged) { + autoUpdater.on('update-not-available', () => { + mainWindow.webContents.send('log', `updateNotYetRecognized`); + }); + autoUpdater.on('error', (err) => { + mainWindow.webContents.send('log', `updateNotYetRecognizedError`); + }); autoUpdater.on('update-downloaded', async () => { console.log('Update heruntergeladen!'); mainWindow.webContents.send('log', 'Update heruntergeladen!'); // () diff --git a/src/settings/src/updates/UpdateMain.vue b/src/settings/src/updates/UpdateMain.vue index 6c39c74..1957816 100644 --- a/src/settings/src/updates/UpdateMain.vue +++ b/src/settings/src/updates/UpdateMain.vue @@ -156,19 +156,36 @@ async function start() { let versions = reusableFetchObj.data.map((obj) => obj['tag_name'].replace('v', '') ); + versionsRef.value = versions; console.log(reusableFetchObj); if (reusableFetchObj.success) { remotePossible.value = true; - setInstallButton(); + setInstallButton(version, versions[0], reusableFetchObj.data[0].prerelease); } else { remotePossible.value = false; } currentVersionStat.value.update(reusableFetchObj, version); // update(fetchObj, version) OR update(owner, repo, version) } -async function setInstallButton() { - installButtonResponse = await api.send('upToDateCheck'); +async function setInstallButton(versionMe, versionRemote, prerelease) { + installButtonResponse = {}; + const comparedVersionResult = compareVersions(versionRemote, versionMe); + console.log(versionMe, versionRemote, prerelease); + if (comparedVersionResult > 0 && !prerelease) { + installButtonText.value = 'Install newest version'; + installButtonResponse.status = 'available'; + } else if (comparedVersionResult == 0) { + installButtonText.value = 'Up to date'; + installCloudColor.value = 'rgb(96,133,93)'; + installButtonResponse.status = 'not-available'; + } else { + installButtonText.value = 'error finding status'; + installCloudColor.value = '#F90B31'; + installButtonResponse.status = 'error'; // error message not needed so far + } + console.log(installButtonResponse); + /* installButtonResponse = await api.send('upToDateCheck'); const response = installButtonResponse; if (response.status === 'available') { installButtonText.value = 'Install newest version'; @@ -182,9 +199,11 @@ async function setInstallButton() { installButtonText.value = 'in dev mode'; installCloudColor.value = '#111111'; installCloudColor.value = '#191919'; - } + } */ + // NOT DOING THIS ANYMORE BC EVERY upToDateCheck this way will download the build already EACH TIME! } function installBtnClick() { + if (!installButtonResponse.status) return; if (installButtonResponse.status === 'available') { vex.dialog.open({ message: 'Do you want to start an automated Download and Install?', @@ -216,16 +235,21 @@ function installBtnClick() { }); } } - +let installBtnAnimationInterval; function animateInstallBtn() { installButtonResponse.status = 'downloading'; document.getElementById('installBtn'); installButtonText.value = 'Downloading ...'; - setInterval(function () { + installBtnAnimationInterval = setInterval(function () { installBtn.classList.toggle('hover'); }, 490); } - +function deanimateInstallBtn() { + installButtonResponse.status = 'available'; + clearInterval(installBtnAnimationInterval); + installBtn.classList.remove('hover'); + installButtonText.value = 'Install newest version'; +} const updateMe = (element, version) => { if (element) { // can be null when it gets deleted ... @@ -233,6 +257,46 @@ const updateMe = (element, version) => { } }; +function compareVersions(version1, version2) { + // > 0 --> version1 param is a newer version tag, ... + // maybe class worthy + // Split the version strings into arrays of numbers + const v1Parts = version1.split('.').map(Number); + const v2Parts = version2.split('.').map(Number); + + // Pad the shorter version array with zeros + while (v1Parts.length < v2Parts.length) v1Parts.push(0); + while (v2Parts.length < v1Parts.length) v2Parts.push(0); + + // Compare each part of the version numbers + for (let i = 0; i < v1Parts.length; i++) { + if (v1Parts[i] > v2Parts[i]) { + return 1; // version1 is newer + } else if (v1Parts[i] < v2Parts[i]) { + return -1; // version2 is newer + } + } + + return 0; // Both versions are the same +} + +electron.onLog((event, message) => { + if (message === 'updateNotYetRecognized') { + deanimateInstallBtn(); + vex.dialog.open({ + message: + 'Electron-Updater maybe needs a bit longer to recognize the new release. Feel free to try again in a few minutes.', + buttons: [$.extend({}, vex.dialog.buttons.YES, { text: 'close' })], + }); + } else if (message === 'updateNotYetRecognizedError') { + deanimateInstallBtn(); + vex.dialog.open({ + message: + 'Electron-Updater sent an error even a new release is detected. Thats unexpected. :(', + buttons: [$.extend({}, vex.dialog.buttons.YES, { text: 'close' })], + }); + } +}); defineExpose({ start, });