Add update progress and do not show GitHub updates if PWA update is needed #591 (#604)

This commit is contained in:
Jaifroid 2024-05-16 10:37:45 +01:00 committed by GitHub
parent e492c18210
commit 7eacee92ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 26 deletions

View File

@ -227,6 +227,9 @@ app.whenReady().then(() => {
autoUpdater.on('update-downloaded', function (info) {
mainWindow.webContents.send('update-available', info);
});
autoUpdater.on('download-progress', function (info) {
mainWindow.webContents.send('update-available', info);
});
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the

View File

@ -128,6 +128,7 @@
"dist-win": "electron-builder build --win --projectDir dist",
"dist-win-arm64": "electron-builder build --win NSIS:arm64 --projectDir dist",
"dist-win-nsis": "electron-builder build --win NSIS:ia32 --publish never --projectDir dist",
"dist-win-nisis-x64": "electron-builder build --win NSIS:x64 --publish never --projectDir dist",
"dist-linux": "electron-builder build --linux --projectDir dist",
"dist-linux-appimage": "electron-builder build --linux AppImage:x64 --projectDir dist",
"publish": "electron-builder --projectDir dist",

View File

@ -942,9 +942,14 @@ function checkPWAUpdate () {
// Electron callback listener if an update is found by main.js
if (window.electronAPI) {
electronAPI.on('update-available', function (data) {
console.log('Upgrade is available:' + data);
console.log('Upgrade is available or in progress:' + data);
params.upgradeNeeded = true;
if (data.percent) {
var percent = data.percent.toFixed(1);
uiUtil.showUpgradeReady(percent, 'progress');
} else {
uiUtil.showUpgradeReady(data.version, 'install');
}
});
electronAPI.on('get-store-value', function (key, value) {
if (key === 'expressPort') {
@ -994,6 +999,21 @@ function checkUpdateServer () {
// If it's plain HTML5 (not Electron/NWJS or UWP), don't check for updates
if (/HTML5/.test(params.appType)) return;
if (params.isUWPStoreApp) return; // It's a UWP app installed from the Store, so it will self update
// Electron updates
if (window.electronAPI) {
var electronVersion = navigator.userAgent.replace(/^.*Electron.([\d.]+).*/i, '$1');
var isUpdateableElectronVersion = !electronVersion.startsWith(params.win7ElectronVersion);
var baseApp = (params.packagedFile && /wikivoyage/.test(params.packagedFile)) ? 'wikivoyage'
: (params.packagedFile && /wikmed|mdwiki/.test(params.packagedFile)) ? 'wikimed'
: 'electron';
if (baseApp === 'electron' && isUpdateableElectronVersion) {
console.log('Launching Electron auto-updater...');
electronAPI.checkForUpdates();
} else {
console.log('Auto-update: ' + (isUpdateableElectronVersion ? 'Packaged apps with large ZIM archives are not currently'
: 'Versions for Windows 7+ 32bit cannot be') + ' auto-updated.');
}
}
// GitHub updates
console.log('Checking for updates from Releases...');
updater.getLatestUpdates(function (tag, url, releases) {
@ -1011,21 +1031,6 @@ function checkUpdateServer () {
params.upgradeNeeded = true;
uiUtil.showUpgradeReady(tag.replace(/^v/, ''), 'download', url);
});
// Electron updates
if (window.electronAPI) {
var electronVersion = navigator.userAgent.replace(/^.*Electron.([\d.]+).*/i, '$1');
var isUpdateableElectronVersion = !electronVersion.startsWith(params.win7ElectronVersion);
var baseApp = (params.packagedFile && /wikivoyage/.test(params.packagedFile)) ? 'wikivoyage'
: (params.packagedFile && /wikmed|mdwiki/.test(params.packagedFile)) ? 'wikimed'
: 'electron';
if (baseApp === 'electron' && isUpdateableElectronVersion) {
console.log('Launching Electron auto-updater...');
electronAPI.checkForUpdates();
} else {
console.log('Auto-update: ' + (isUpdateableElectronVersion ? 'Packaged apps with large ZIM archives are not currently'
: 'Versions for Windows 7+ 32bit cannot be') + ' auto-updated.');
}
}
}
// Do update checks 10s after startup
@ -1034,8 +1039,9 @@ setTimeout(function () {
console.log('Checking for updates to the PWA...');
checkPWAUpdate();
}
checkUpdateServer();
}, 10000);
// Delay GitHub checks so that any needed PWA update can be notified first
setTimeout(checkUpdateServer, 2000);
}, 8000);
function setActiveBtn (activeBtn) {
document.getElementById('btnHome').classList.remove('active');

View File

@ -1034,7 +1034,7 @@ function systemAlert (message, label, isConfirm, declineConfirmLabel, approveCon
/**
* Shows that an upgrade is ready to install
* @param {String} ver The version of the upgrade
* @param {String} type Either 'load', 'install' or 'download' according to the type of upgrade
* @param {String} type Either 'load', 'install', 'download' or 'progress' according to the type of upgrade
* @param {String} url An optional download URL
*/
function showUpgradeReady (ver, type, url) {
@ -1044,12 +1044,17 @@ function showUpgradeReady (ver, type, url) {
' <a href="#" id="closeUpgradeAlert" class="close" data-dismiss="alert" aria-label="close">&times;</a>\n' +
' <span id="persistentMessage"></span>\n' +
'</div>\n';
document.getElementById('persistentMessage').innerHTML = 'Version ' + ver +
var persistentMessage = document.getElementById('persistentMessage');
if (type === 'progress') {
persistentMessage.innerHTML = 'Download in progress: ' + ver + '%';
} else {
persistentMessage.innerHTML = 'Version ' + ver +
(url ? ' is available to ' + type + '! Go to <a href="' + url + '" style="color:white;" target="_blank">' + url + '</a>'
: ' is ready to ' + type + '! (Re-launch app to ' + type + '.)');
document.getElementById('closeUpgradeAlert').addEventListener('click', function () {
alertBoxPersistent.style.display = 'none';
});
}
}
/**