diff --git a/index.html b/index.html index e14eb92..50a47aa 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,6 @@

Chatbot

- @@ -85,11 +84,13 @@

ChatBot

A secure offline chatbot vault that stores your personal documents, notes, and files locally, no internet or servers required. made to keep your data truly yours.

+ GitHub + CodePen + Changelog +
+

Developed by Adityasinh Sodha

-

Version: v2.0.0

+

Version: v2.0.1

@@ -125,6 +126,17 @@

User Guide

+ + diff --git a/js/app.js b/js/app.js index 27eaa29..e91ecf1 100644 --- a/js/app.js +++ b/js/app.js @@ -930,3 +930,50 @@ helpBtn.onclick = async () => { closeHelp.onclick = () => { helpPopup.style.display = "none"; }; + +const LOCAL_VERSION = "2"; +const REMOTE_VERSION_URL = "https://raw.githubusercontent.com/WorkofAditya/ChatBot/refs/heads/Beta/version.txt"; + +let latestRemoteVersion = null; + +function checkForAppUpdate() { + fetch(REMOTE_VERSION_URL + "?cache=" + Date.now()) + .then(res => res.text()) + .then(remote => { + const remoteVersion = remote.trim(); + latestRemoteVersion = remoteVersion; + + const storedVersion = localStorage.getItem("updatedVersion"); + if (storedVersion === remoteVersion) return; + + if (remoteVersion > LOCAL_VERSION) { + showUpdatePopup(); + } + }) + .catch(() => {}); +} + +function showUpdatePopup() { + const popup = document.getElementById("updatePopup"); + popup.style.display = "flex"; + + document.getElementById("refreshAppBtn").onclick = async () => { + popup.style.display = "none"; + localStorage.setItem("updatedVersion", latestRemoteVersion); + + if ("serviceWorker" in navigator) { + const reg = await navigator.serviceWorker.getRegistration(); + if (reg && reg.waiting) { + reg.waiting.postMessage("SKIP_WAITING"); + } + } + + setTimeout(() => window.location.reload(), 300); + }; + + document.getElementById("dismissUpdateBtn").onclick = () => { + popup.style.display = "none"; + }; +} + +if (navigator.onLine) checkForAppUpdate(); diff --git a/service-worker.js b/service-worker.js index d6b2a2a..76b1c13 100644 --- a/service-worker.js +++ b/service-worker.js @@ -1,6 +1,6 @@ -const CACHE_NAME = "vault-cache-v14"; +const APP_VERSION = "1"; +const CACHE_NAME = `vault-cache-v${APP_VERSION}`; const FILES_TO_CACHE = [ - "/", "/index.html", "/styles.css", "/js/app.js", @@ -13,13 +13,10 @@ const FILES_TO_CACHE = [ "/icons/favicon.ico" ]; - // Install: cache everything self.addEventListener("install", (event) => { event.waitUntil( - caches.open(CACHE_NAME).then((cache) => { - return cache.addAll(FILES_TO_CACHE); - }) + caches.open(CACHE_NAME).then((cache) => cache.addAll(FILES_TO_CACHE)) ); self.skipWaiting(); }); @@ -30,9 +27,7 @@ self.addEventListener("activate", (event) => { caches.keys().then((keyList) => Promise.all( keyList.map((key) => { - if (key !== CACHE_NAME) { - return caches.delete(key); - } + if (key !== CACHE_NAME) return caches.delete(key); }) ) ) @@ -40,11 +35,32 @@ self.addEventListener("activate", (event) => { self.clients.claim(); }); -// Fetch: serve from cache when offline +// Fetch: cache-first for offline self.addEventListener("fetch", (event) => { + if (event.request.method !== "GET") return; + event.respondWith( - caches.match(event.request).then((response) => { - return response || fetch(event.request); + caches.match(event.request, { ignoreSearch: true }).then((cached) => { + if (cached) return cached; + + return fetch(event.request) + .then((response) => { + const clone = response.clone(); + caches.open(CACHE_NAME).then((cache) => { + cache.put(event.request, clone); + }); + return response; + }) + .catch(() => { + if (event.request.mode === "navigate") { + return caches.match("/index.html"); + } + }); }) ); }); + +// Force update activation from app.js +self.addEventListener("message", (event) => { + if (event.data === "SKIP_WAITING") self.skipWaiting(); +}); diff --git a/styles.css b/styles.css index 1f58955..bb5f42b 100644 --- a/styles.css +++ b/styles.css @@ -1128,3 +1128,28 @@ hr { margin: 16px 0; height: 2px; } + +#updatePopup .popup-content { + max-width: 380px; + text-align: center; + padding: 28px 22px; +} +#updatePopup h2 { + font-size: 1.4rem; + color: #6ab7ff; + margin-bottom: 10px; +} +#updatePopup p { + font-size: 0.94rem; + color: #e1e7f8; + margin-bottom: 14px; +} +#updatePopup .popup-actions button { + background: rgba(60, 110, 200, 0.15); + border: 1px solid rgba(60, 110, 200, 0.4); + color: #9abfff; +} +#updatePopup .popup-actions button:hover { + background: rgba(60, 110, 200, 0.24); + color: #fff; +} diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +2