summaryrefslogtreecommitdiff
path: root/src/scripts
diff options
context:
space:
mode:
authoraltaf-creator <64111012+altaf-creator@users.noreply.github.com>2023-05-05 08:42:54 +0700
committeraltaf-creator <64111012+altaf-creator@users.noreply.github.com>2023-05-05 08:42:54 +0700
commitd152ffac9147986b25542bcf78561e183ae83eb3 (patch)
tree27032fe0d92821721f63de6d8040edab2602275f /src/scripts
parent5725accf76d1ec02d569c59a9989b7d72827a7ee (diff)
PWA Update - final i hope
Diffstat (limited to 'src/scripts')
-rw-r--r--src/scripts/main.js18
-rw-r--r--src/scripts/service-worker.js76
2 files changed, 51 insertions, 43 deletions
diff --git a/src/scripts/main.js b/src/scripts/main.js
index c610e83..96210b1 100644
--- a/src/scripts/main.js
+++ b/src/scripts/main.js
@@ -8,13 +8,17 @@ function urlExists(url) {
if ("serviceWorker" in navigator) {
window.addEventListener("load", function () {
- for (var i = 0; i < assets.length; i++) {
- urlExists(assets[i]);
- }
+ try {
+ process.versions['electron'];
+ } catch {
+ for (var i = 0; i < assets.length; i++) {
+ urlExists(assets[i]);
+ }
- navigator.serviceWorker
- .register("scripts/service-worker.js")
- .then(res => console.log("service worker registered"))
- .catch(err => console.log("service worker not registered", err))
+ navigator.serviceWorker
+ .register("scripts/service-worker.js")
+ .then(res => console.log("service worker registered"))
+ .catch(err => console.log("service worker not registered", err))
+ }
})
} \ No newline at end of file
diff --git a/src/scripts/service-worker.js b/src/scripts/service-worker.js
index 19f58b8..4263b47 100644
--- a/src/scripts/service-worker.js
+++ b/src/scripts/service-worker.js
@@ -32,50 +32,54 @@ self.addEventListener("install", installEvent => {
})
)
})
-
+
self.addEventListener("fetch", fetchEvent => {
fetchEvent.respondWith(
caches.match(fetchEvent.request).then(res => {
return res || fetch(fetchEvent.request);
})
- )
-})
+ )
+ })
*/
-self.addEventListener('install', function (event) {
- console.log('Service worker installed');
+try {
+ process.versions['electron']
+} catch {
+ self.addEventListener('install', function (event) {
+ console.log('Service worker installed');
- event.waitUntil(
- caches.open('staticQuran')
- .then(function (cache) {
- console.log('Cache opened');
- return cache.addAll(assets);
- })
- .then(function () {
- console.log('Assets cached');
- })
- .catch(function (error) {
- console.error('Error caching assets:', error);
- })
- );
-});
+ event.waitUntil(
+ caches.open('staticQuran')
+ .then(function (cache) {
+ console.log('Cache opened');
+ return cache.addAll(assets);
+ })
+ .then(function () {
+ console.log('Assets cached');
+ })
+ .catch(function (error) {
+ console.error('Error caching assets:', error);
+ })
+ );
+ });
-self.addEventListener('fetch', function (event) {
- console.log('Fetch event:', event.request.url);
+ self.addEventListener('fetch', function (event) {
+ console.log('Fetch event:', event.request.url);
- event.respondWith(
- caches.match(event.request)
- .then(function (response) {
- if (response) {
- console.log('Cached response found:', response);
- return response;
- }
+ event.respondWith(
+ caches.match(event.request)
+ .then(function (response) {
+ if (response) {
+ console.log('Cached response found:', response);
+ return response;
+ }
- console.log('No cached response found, fetching from network');
- return fetch(event.request);
- })
- .catch(function (error) {
- console.error('Error fetching from cache:', error);
- })
- );
-}); \ No newline at end of file
+ console.log('No cached response found, fetching from network');
+ return fetch(event.request);
+ })
+ .catch(function (error) {
+ console.error('Error fetching from cache:', error);
+ })
+ );
+ });
+} \ No newline at end of file