diff --git a/www/js/app.js b/www/js/app.js index 06db8fd7..e74db9fd 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1556,12 +1556,19 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett goPWA = true; } if (goPWA) { - uiUtil.systemAlert(message, 'Warning!', 'Access server', function () { + var launchPWA = function () { settingsStore.setItem('lastContentInjectionMode', value, Infinity); + params.allowInternetAccess = true; + settingsStore.setItem('allowInternetAccess', params.allowInternetAccess, Infinity); window.location.href = 'https://kiwix.github.io/kiwix-js-windows/www/index.html?contentInjectionMode=serviceworker'; - }, 'Cancel', function () { - document.getElementById('btnConfigure').click(); - }); + }; + if (params.allowInternetAccess) { + launchPWA(); + } else { + uiUtil.systemAlert(message, 'Warning!', 'Access server', launchPWA, 'Cancel', function () { + document.getElementById('btnConfigure').click(); + }); + } } else { uiUtil.systemAlert(message, 'Information'); } diff --git a/www/js/init.js b/www/js/init.js index dd9ab0fc..12841830 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -81,7 +81,11 @@ params['hideActiveContentWarning'] = getSetting('hideActiveContentWarning') != n params['allowHTMLExtraction'] = getSetting('allowHTMLExtraction') == true; params['alphaChar'] = getSetting('alphaChar') || 'A'; //Set default start of alphabet string (used by the Archive Index) params['omegaChar'] = getSetting('omegaChar') || 'Z'; //Set default end of alphabet string -params['contentInjectionMode'] = getSetting('contentInjectionMode') || 'jquery'; //Defaults to jquery mode (widest compatibility) +if (/contentInjectionMode=serviceworker/i.test(window.location.href) && /^http/i.test(window.location.protocol)) { + // We have launched the app from a PWA redirect so set preferred contentInjectionMode (this can be overridden by user below) + params.contentInjectionMode = 'serviceworker'; +} +params['contentInjectionMode'] = getSetting('contentInjectionMode') || params.contentInjectionMode || 'jquery'; // Defaults to jquery mode (widest compatibility) //Do not touch these values unless you know what they do! Some are global variables, some are set programmatically params['imageDisplayMode'] = params.imageDisplay ? 'progressive' : 'manual'; @@ -97,7 +101,7 @@ params['localStorage'] = params['localStorage'] || ""; params['pickedFile'] = launchArguments ? launchArguments.files[0] : ""; params['pickedFolder'] = params['pickedFolder'] || ""; params['themeChanged'] = params['themeChanged'] || false; -params['allowInternetAccess'] = params['allowInternetAccess'] || false; // Do not get value from cookie, should be explicitly set by user on a per-session basis +params['allowInternetAccess'] = getSetting('allowInternetAccess'); // This should only be set by the PWA access permissions box params['printIntercept'] = false; params['printInterception'] = false; params['appIsLaunching'] = true; // Allows some routines to tell if the app has just been launched @@ -126,6 +130,7 @@ if (getSetting('lastPageLoad') === 'failed') { } //Initialize checkbox, radio and other values +document.getElementById('allowInternetAccessCheck').checked = params.allowInternetAccess; document.getElementById('cssCacheModeCheck').checked = params.cssCache; document.getElementById('imageDisplayModeCheck').checked = params.imageDisplay; document.getElementById('removePageMaxWidthCheck').checked = params.removePageMaxWidth === true; // Will be false if false or auto