diff --git a/main.cjs b/main.cjs index bdb50c93..8e860535 100644 --- a/main.cjs +++ b/main.cjs @@ -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 diff --git a/package.json b/package.json index eefc62f6..8b0068a2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/www/js/app.js b/www/js/app.js index 7c8ec375..3aa5a1a0 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -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; - uiUtil.showUpgradeReady(data.version, 'install'); + 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'); diff --git a/www/js/lib/uiUtil.js b/www/js/lib/uiUtil.js index d3d3b6d5..cfaa7c78 100644 --- a/www/js/lib/uiUtil.js +++ b/www/js/lib/uiUtil.js @@ -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) { ' ×\n' + ' \n' + '\n'; - document.getElementById('persistentMessage').innerHTML = 'Version ' + ver + - (url ? ' is available to ' + type + '! Go to ' + url + '' - : ' is ready to ' + type + '! (Re-launch app to ' + type + '.)'); - document.getElementById('closeUpgradeAlert').addEventListener('click', function () { - alertBoxPersistent.style.display = 'none'; - }); + 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 ' + url + '' + : ' is ready to ' + type + '! (Re-launch app to ' + type + '.)'); + document.getElementById('closeUpgradeAlert').addEventListener('click', function () { + alertBoxPersistent.style.display = 'none'; + }); + } } /**