From c9868b806b4764426f3b0d845f0f8afa85d9aa1b Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sun, 11 Jun 2023 11:44:41 +0100 Subject: [PATCH] Do not check for Electron updates if app installed from MS Store --- preload.cjs | 7 +++++++ www/js/app.js | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/preload.cjs b/preload.cjs index 37cf324f..7382ac55 100644 --- a/preload.cjs +++ b/preload.cjs @@ -3,6 +3,12 @@ 'use strict'; +// A regular expression that matches the hash of the Kiwix publisher on the Microsoft Store (CN=0A5438F5-EEA6-4300-9B77-E45BBD148885) +// If the app is installed from the Store rather than from the signed GitHub release, we need to disable update checking +const regexpInstalledFromMicrosoftStore = /_mc3511b08yc0e/; +console.log('[Preload] Is app installed from Microsoft Store? ' + (process.windowsStore && regexpInstalledFromMicrosoftStore.test(window.location.pathname) ? 'Yes' : 'No')); +console.log('Window location: ' + window.location.pathname + '\nStore publisher hash: ' + regexpInstalledFromMicrosoftStore); + // DEV: TO SUPPORT ELECTRON ^12 YOU WILL NEED THIS const { ipcRenderer, contextBridge } = require('electron'); const { open, read, close, stat, readdir } = require('fs'); @@ -22,6 +28,7 @@ contextBridge.exposeInMainWorld('electronAPI', { checkForUpdates: function () { ipcRenderer.send('check-updates'); }, + isMicrosoftStoreApp: process.windowsStore && regexpInstalledFromMicrosoftStore.test(window.location.pathname), on: function (event, callback) { ipcRenderer.on(event, function (_, data) { callback(data); diff --git a/www/js/app.js b/www/js/app.js index d27d8046..e2bca7e9 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -918,15 +918,16 @@ if (window.electronAPI) { // Check for GitHub and Electron updates var updateCheck = document.getElementById('updateCheck'); params.isUWPStoreApp = /UWP/.test(params.appType) && Windows.ApplicationModel && Windows.ApplicationModel.Package && - !/Association.Kiwix/.test(Windows.ApplicationModel.Package.current.id.publisher); + !/Association.Kiwix/.test(Windows.ApplicationModel.Package.current.id.publisher) || electronAPI && electronAPI.isMicrosotStoreApp; // If Internet access is allowed, or it's a UWP Store app, or it's HTML5 (i.e., not Electron/NWJS or UWP) ... if (params.allowInternetAccess || params.isUWPStoreApp || /HTML5/.test(params.appType)) { updateCheck.style.display = 'none'; // ... hide the update check link + if (params.isUWPStoreApp) console.debug('Hiding update check link because this is a UWP Store app.'); } // Function to check for updates from GitHub function checkUpdateServer() { if (!params.allowInternetAccess || params.upgradeNeeded) { - console.log('The GitHub update check was blocked because ' + (params.upgradeNeeded ? 'a PWA upgrade is needed.' : 'the user has not allowed Internet access.')); + console.warn('The GitHub update check was blocked because ' + (params.upgradeNeeded ? 'a PWA upgrade is needed.' : 'the user has not allowed Internet access.')); return; } // If it's plain HTML5 (not Electron/NWJS or UWP), don't check for updates