From f051e470c1cc8eab26544efcc619dd5cb206cdf6 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sun, 5 Jul 2020 09:31:02 +0100 Subject: [PATCH] Make Electron app work with pwabuilder Former-commit-id: d3ddcf4b7e75db8bbba6b2d7f6917b01e066f3e1 [formerly dc1e971e68f1b682bbceb494d70bd6b3e771ee2b] [formerly 42142309a5bb263848ae3500ac9655a743a9821a [formerly b2cd0e46617655422abdcbcce83f1921bb7af1f4]] Former-commit-id: bdee798fc30446b0248248579c0686f1cc1a3907 [formerly 403a4424c4d62b0f179a31872ed2638dad66c50d] Former-commit-id: ef10d2de4ecd92c4383c5cf36194f3c42c69e312 --- main.js | 19 ++++++++++--------- pwabuilder-sw.js | 2 +- www/js/app.js | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/main.js b/main.js index 22c09ef5..29e6b854 100644 --- a/main.js +++ b/main.js @@ -8,15 +8,15 @@ const { const path = require('path'); // This is used to set capabilities of the app: protocol in onready event below -protocol.registerSchemesAsPrivileged([{ - scheme: 'app', - privileges: { - standard: true, - secure: true, - allowServiceWorkers: true, - supportFetchAPI: true - } -}]); +// protocol.registerSchemesAsPrivileged([{ +// scheme: 'app', +// privileges: { +// standard: true, +// secure: true, +// allowServiceWorkers: true, +// supportFetchAPI: true +// } +// }]); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. @@ -45,6 +45,7 @@ function createWindow() { // and load the index.html of the app. // mainWindow.loadURL(`https://${__dirname}/www/index.html`); + // mainWindow.loadURL(`https://kiwix.github.io/kiwix-js-windows/`); // DEV: If you need Service Worker more than you need document.cookie, load app like this: mainWindow.loadFile('www/index.html'); diff --git a/pwabuilder-sw.js b/pwabuilder-sw.js index 4cad7ea4..171e222e 100644 --- a/pwabuilder-sw.js +++ b/pwabuilder-sw.js @@ -135,7 +135,7 @@ self.addEventListener('fetch', intercept); // Look up fetch in cache, and if it does not exist, try to get it from the network function intercept(event) { - if (excludedURLSchema.test(event.request.url) && !(/\.zim\w{0,2}\//i.test(event.request.url) || regexpZIMUrlWithNamespace.test(event.request.url))) return; + if (excludedURLSchema.test(event.request.url) && !(/\.zim\w{0,2}\//i.test(event.request.url) && regexpZIMUrlWithNamespace.test(event.request.url))) return; console.log('[SW] Service Worker ' + (event.request.method === "GET" ? 'intercepted ' : 'noted ') + event.request.url, event.request.method); if (event.request.method !== "GET") return; event.respondWith( diff --git a/www/js/app.js b/www/js/app.js index 91d38e98..50026e4c 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -2112,7 +2112,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki // For Electron, we need to set an absolute filepath in case the file was launched from a shortcut (and if it's not already absolute) // DEV: Periodically check Electron hasn't changed its resources folder; NB the ! in indexOf below indicates position at start of string if (!filepath.indexOf(params.archivePath) && /^file:/.test(window.location.protocol)) { - filepath = window.location.pathname.replace(/^\//, '').replace(/resources\/app\/www\/[^/]+$/, '') + filepath; + filepath = window.location.pathname.replace(/^\//, '').replace(/(resources\/app\/)?www\/[^/]+$/, '') + filepath; } file.name = filename; file.path = filepath;