From bb90d66381262ecd1c74ad840f6e387acd04c2bf Mon Sep 17 00:00:00 2001 From: Mohammed Abdullah Date: Wed, 15 Jan 2025 21:14:11 +0530 Subject: [PATCH] Add files via upload --- manifest.json | 22 ++++++++++++++++ service-worker.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 manifest.json create mode 100644 service-worker.js diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..2a3be5a --- /dev/null +++ b/manifest.json @@ -0,0 +1,22 @@ +{ + "name": "ReflectHub", + "short_name": "ReflectHub", + "description": "Read Quran and watch these videos sincerely by reflecting upon them deeply, so that you may find truth and accept it!", + "start_url": "/index.html", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#c8ffcd", + "icons": [ + { + "src": "icon2.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icon2.png", + "sizes": "512x512", + "type": "image/png" + } + ] + } + \ No newline at end of file diff --git a/service-worker.js b/service-worker.js new file mode 100644 index 0000000..6806a80 --- /dev/null +++ b/service-worker.js @@ -0,0 +1,64 @@ +const CACHE_NAME = "abdullah-pwa-cache-v1"; +const ASSETS_TO_CACHE = [ + "/", + "/index.html", + "/index.js", + "/index.css", + "/Logos/Translate.png", + "/Logos/discord.png", + "/Logos/facebook.png", + "/Logos/github.svg", + "/Logos/locate.svg", + "/Logos/reddit.png", + "/Logos/twitter.png", + "/Homepage.png", + "/License.md", + "/README.md", + "/ReflectIMG.png", + "/drop.html", + "/future.html", + "/green.png", + "/hamburger.svg", + "/icon2.png", + "/icon4.png", + "/icon5.png", + "/score.html", + "/search.js" +]; + +// Install Service Worker +self.addEventListener("install", (event) => { + event.waitUntil( + caches.open(CACHE_NAME).then((cache) => { + console.log("Opened cache"); + return cache.addAll(ASSETS_TO_CACHE); + }) + ); +}); + +// Fetch Event +self.addEventListener("fetch", (event) => { + event.respondWith( + caches.match(event.request).then((response) => { + // Return cached version or fetch from network + return response || fetch(event.request); + }) + ); +}); + +// Activate Service Worker +self.addEventListener("activate", (event) => { + const cacheWhitelist = [CACHE_NAME]; + event.waitUntil( + caches.keys().then((cacheNames) => + Promise.all( + cacheNames.map((cacheName) => { + if (!cacheWhitelist.includes(cacheName)) { + console.log("Deleting old cache:", cacheName); + return caches.delete(cacheName); + } + }) + ) + ) + ); +});