mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-10 04:40:27 -04:00
Preliminary code to enable SW mode in UWP
# Conflicts: # package.appxmanifest Former-commit-id: b015ab8cc95553be1a09c6ab8e83cfac2b41b94e [formerly ba2c1cf22a4ee3b4c2b2a0d73e6b1c9e6329a034 [formerly 5088eb4fd5b3b1fa3b37cf1ad702383b29cc1ccb]] Former-commit-id: 88ddfaacb2d91c68546b44bd2852817b7b56b5f8 Former-commit-id: b436bcd69068e7f34a6b3c9ed9bb45ae01153d1a
This commit is contained in:
parent
e7797e4f58
commit
c79f1ac3ef
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap mp uap3">
|
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" IgnorableNamespaces="uap mp uap3 uap5">
|
||||||
<Identity Name="Kiwix.KiwixJS" Version="1.1.4.0" Publisher="CN=Association Kiwix, O=Association Kiwix, L=Lausanne, C=CH" />
|
<Identity Name="Kiwix.KiwixJS" Version="1.1.4.0" Publisher="CN=Association Kiwix, O=Association Kiwix, L=Lausanne, C=CH" />
|
||||||
<mp:PhoneIdentity PhoneProductId="9850377b-0966-437e-ab30-a076c125f472" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
|
<mp:PhoneIdentity PhoneProductId="9850377b-0966-437e-ab30-a076c125f472" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
|
||||||
<Properties>
|
<Properties>
|
||||||
@ -16,7 +16,8 @@
|
|||||||
<Applications>
|
<Applications>
|
||||||
<Application Id="App" StartPage="ms-appx-web:///www/index.html">
|
<Application Id="App" StartPage="ms-appx-web:///www/index.html">
|
||||||
<uap:ApplicationContentUriRules>
|
<uap:ApplicationContentUriRules>
|
||||||
<uap:Rule Match="ms-appx-web:///www/index.html" Type="include" WindowsRuntimeAccess="all" />
|
<uap:Rule Match="ms-appx-web:///www/index.html" Type="include" uap5:ServiceWorker="true" WindowsRuntimeAccess="all" />
|
||||||
|
<uap:Rule Match="https://kiwix.github.io/kiwix-js-windows/" Type="include" uap5:ServiceWorker="true" WindowsRuntimeAccess="all" />
|
||||||
</uap:ApplicationContentUriRules>
|
</uap:ApplicationContentUriRules>
|
||||||
<uap:VisualElements DisplayName="Kiwix JS" Description="Kiwix Offline Wikipedia and ZIM File Reader" BackgroundColor="transparent" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
|
<uap:VisualElements DisplayName="Kiwix JS" Description="Kiwix Offline Wikipedia and ZIM File Reader" BackgroundColor="transparent" Square150x150Logo="images\Square150x150Logo.png" Square44x44Logo="images\Square44x44Logo.png">
|
||||||
<uap:DefaultTile ShortName="Kiwix JS" Square310x310Logo="images\LargeTile.png" Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\SmallTile.png">
|
<uap:DefaultTile ShortName="Kiwix JS" Square310x310Logo="images\LargeTile.png" Wide310x150Logo="images\Wide310x150Logo.png" Square71x71Logo="images\SmallTile.png">
|
||||||
|
@ -1541,6 +1541,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
|
|||||||
}, function (err) {
|
}, function (err) {
|
||||||
console.error('error while registering serviceWorker', err);
|
console.error('error while registering serviceWorker', err);
|
||||||
refreshAPIStatus();
|
refreshAPIStatus();
|
||||||
|
var goPWA = false;
|
||||||
var message = "The ServiceWorker could not be properly registered. Switching back to jQuery mode. Error message : " + err;
|
var message = "The ServiceWorker could not be properly registered. Switching back to jQuery mode. Error message : " + err;
|
||||||
var protocol = window.location.protocol;
|
var protocol = window.location.protocol;
|
||||||
if (protocol === 'moz-extension:') {
|
if (protocol === 'moz-extension:') {
|
||||||
@ -1548,8 +1549,22 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
|
|||||||
message += "\nPlease vote for https://bugzilla.mozilla.org/show_bug.cgi?id=1344561 so that some future Firefox versions support it";
|
message += "\nPlease vote for https://bugzilla.mozilla.org/show_bug.cgi?id=1344561 so that some future Firefox versions support it";
|
||||||
} else if (protocol === 'file:') {
|
} else if (protocol === 'file:') {
|
||||||
message += "\n\nYou seem to be opening kiwix-js with the file:// protocol. You should open it through a web server : either through a local one (http://localhost/...) or through a remote one (but you need SSL : https://webserver/...)";
|
message += "\n\nYou seem to be opening kiwix-js with the file:// protocol. You should open it through a web server : either through a local one (http://localhost/...) or through a remote one (but you need SSL : https://webserver/...)";
|
||||||
|
} else if (protocol === 'ms-appx-web:') {
|
||||||
|
message = 'This UWP app uses locally packaged code by default.\n' +
|
||||||
|
'To enable the Service Worker we need to switch to PWA mode.\n\n' +
|
||||||
|
'WARNING: This will attempt to access the server: ' + params.PWAServer;
|
||||||
|
goPWA = true;
|
||||||
|
}
|
||||||
|
if (goPWA) {
|
||||||
|
uiUtil.systemAlert(message, 'Warning!', 'Access server', function () {
|
||||||
|
settingsStore.setItem('lastContentInjectionMode', value, Infinity);
|
||||||
|
window.location.href = 'https://kiwix.github.io/kiwix-js-windows/www/index.html?contentInjectionMode=serviceworker';
|
||||||
|
}, 'Cancel', function () {
|
||||||
|
document.getElementById('btnConfigure').click();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
uiUtil.systemAlert(message, 'Information');
|
||||||
}
|
}
|
||||||
uiUtil.systemAlert(message);
|
|
||||||
setContentInjectionMode("jquery");
|
setContentInjectionMode("jquery");
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
@ -56,6 +56,8 @@ params['archivePath'] = "archives"; //The directory containing the packaged arch
|
|||||||
params['fileVersion'] = "wikipedia_en_100_maxi_2021-01.zim (23-Jan-2021)"; //Use generic name for actual file, and give version here
|
params['fileVersion'] = "wikipedia_en_100_maxi_2021-01.zim (23-Jan-2021)"; //Use generic name for actual file, and give version here
|
||||||
params['cachedStartPage'] = false; //If you have cached the start page for quick start, give its URI here
|
params['cachedStartPage'] = false; //If you have cached the start page for quick start, give its URI here
|
||||||
params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/"; //Include final slash
|
params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/"; //Include final slash
|
||||||
|
params['PWAServer'] = "https://kiwix.github.io/kiwix-js-windows/";
|
||||||
|
params['PWAMode'] = getSetting('PWAMode'); // Set to true if the app should always operate in PWA mode
|
||||||
|
|
||||||
params['storeType'] = getBestAvailableStorageAPI();
|
params['storeType'] = getBestAvailableStorageAPI();
|
||||||
params['keyPrefix'] = 'kiwixjs-'; // Prefix to use for localStorage keys
|
params['keyPrefix'] = 'kiwixjs-'; // Prefix to use for localStorage keys
|
||||||
@ -104,6 +106,13 @@ params['PWAInstalled'] = getSetting('PWAInstalled');
|
|||||||
params['appType'] = getAppType();
|
params['appType'] = getAppType();
|
||||||
params.pagesLoaded = 0; // Page counter used to show PWA Install Prompt only after user has played with the app for a while
|
params.pagesLoaded = 0; // Page counter used to show PWA Install Prompt only after user has played with the app for a while
|
||||||
|
|
||||||
|
// Make sure we are accessing the correct server according to the PWA setting
|
||||||
|
if (params.PWAMode && !~window.location.href.indexOf(params.PWAServer) && /UWP/.test(params.appType)) {
|
||||||
|
// User wants PWA mode so reload now
|
||||||
|
window.location.href = params.PWAServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Prevent app boot loop with problematic pages that cause an app crash
|
//Prevent app boot loop with problematic pages that cause an app crash
|
||||||
if (getSetting('lastPageLoad') === 'failed') {
|
if (getSetting('lastPageLoad') === 'failed') {
|
||||||
params.lastPageVisit = "";
|
params.lastPageVisit = "";
|
||||||
|
@ -529,11 +529,18 @@ define(rqDef, function() {
|
|||||||
* Provides system-specific alert function
|
* Provides system-specific alert function
|
||||||
*
|
*
|
||||||
* @param {String} message The message to display
|
* @param {String} message The message to display
|
||||||
|
* @param {String} title The message title
|
||||||
|
* @param {String} btn1 An optional button to display
|
||||||
|
* @param {Function} btn1Func An optional function to run when btn1 is selected
|
||||||
|
* @param {String} btn2 An optional secondary button to display
|
||||||
|
* @param {Function} btn2Func An optional function to run when btn2 is selected
|
||||||
*/
|
*/
|
||||||
function systemAlert(message) {
|
function systemAlert(message, title, btn1, btn1Func, btn2, btn2Func) {
|
||||||
// Test for UWP
|
// Test for UWP
|
||||||
if (typeof Windows !== 'undefined' && typeof Windows.UI !== 'undefined' && typeof Windows.UI.Popups !== 'undefined') {
|
if (typeof Windows !== 'undefined' && typeof Windows.UI !== 'undefined' && typeof Windows.UI.Popups !== 'undefined') {
|
||||||
var dialog = new Windows.UI.Popups.MessageDialog(message);
|
var dialog = new Windows.UI.Popups.MessageDialog(message);
|
||||||
|
if (btn1 && btn1Func) dialog.commands.append(new Windows.UI.Popups.UICommand(btn1, btn1Func));
|
||||||
|
if (btn2 && btn2Func) dialog.commands.append(new Windows.UI.Popups.UICommand(btn2, btn2Func));
|
||||||
dialog.showAsync();
|
dialog.showAsync();
|
||||||
} else {
|
} else {
|
||||||
alert(message);
|
alert(message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user