Skip to content

Commit

Permalink
adjustments to fit new update checking method
Browse files Browse the repository at this point in the history
  • Loading branch information
AquaJo committed Aug 19, 2024
1 parent a290694 commit 142b496
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"files.trimTrailingWhitespace": true,
"cSpell.words": [
"BTNS",
"deanimate",
"electronjs",
"Emran",
"Garreau",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "huefl",
"version": "0.0.3",
"version": "0.0.2",
"description": "abc",
"main": "src/index.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!'); // ()
Expand Down
78 changes: 71 additions & 7 deletions src/settings/src/updates/UpdateMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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?',
Expand Down Expand Up @@ -216,23 +235,68 @@ 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 ...
element.update(reusableFetchObj, 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,
});
Expand Down

0 comments on commit 142b496

Please sign in to comment.