From f4b3867ab89ab4d4d456d2b09c4c1cc65de5dcc7 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 31 Jul 2025 10:39:51 -0400 Subject: [PATCH] server now pushes index.html --- manifest.json | 17 ----------------- public/index.html | 16 ++++++++++++++++ public/manifest.json | 21 +++++++++++++++++++++ public/sw.js | 42 ++++++++++++++++++++++++++++++++++++++++++ sw.js | 34 ---------------------------------- 5 files changed, 79 insertions(+), 51 deletions(-) delete mode 100644 manifest.json create mode 100644 public/manifest.json create mode 100644 public/sw.js delete mode 100644 sw.js diff --git a/manifest.json b/manifest.json deleted file mode 100644 index e57e4e7..0000000 --- a/manifest.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "TimeTracker", - "short_name": "TimeTrack", - "description": "A simple time tracking application for employees and admins.", - "start_url": "/", - "display": "standalone", - "background_color": "#ffffff", - "theme_color": "#2563EB", - "orientation": "portrait-primary", - "icons": [ - { - "src": "/images/icon-512.png", - "type": "image/png", - "sizes": "512x512" - } - ] -} \ No newline at end of file diff --git a/public/index.html b/public/index.html index 5b01c3e..648e5c5 100644 --- a/public/index.html +++ b/public/index.html @@ -4,6 +4,7 @@ + TimeTracker @@ -249,6 +250,21 @@ // --- Initializer --- signOutBtn.addEventListener('click', () => handleSignOut()); updateUI(); + + // Add the registration code here, inside the same script + if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('/sw.js') + .then(registration => { + console.log('✅ ServiceWorker registration successful with scope: ', registration.scope); + }) + .catch(err => { + console.log('❌ ServiceWorker registration failed: ', err); + }); + }); + } + + diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..f122983 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,21 @@ +{ + "name": "TimeTracker", + "short_name": "TimeTracker", + "start_url": "/", + "display": "standalone", + "background_color": "#f3f4f6", + "theme_color": "#4f46e5", + "description": "A simple time tracking application.", + "icons": [ + { + "src": "/images/icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/images/icon-512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..ff8d240 --- /dev/null +++ b/public/sw.js @@ -0,0 +1,42 @@ +// A name for our cache +const CACHE_NAME = 'timetracker-v1'; + +// The files that make up the "app shell" - the minimum needed to run +const urlsToCache = [ + '/', + '/index.html', + // You can also cache the CDN assets if you want + 'https://cdn.tailwindcss.com', + 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap' +]; + +// 1. Installation: Open the cache and add the app shell files. +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(CACHE_NAME) + .then((cache) => { + console.log('Opened cache'); + return cache.addAll(urlsToCache); + }) + ); +}); + +// 2. Fetch: Intercept network requests. +self.addEventListener('fetch', (event) => { + // We only want to cache GET requests + if (event.request.method !== 'GET') { + return; + } + + event.respondWith( + caches.match(event.request) + .then((response) => { + // If the file is in the cache, serve it. + if (response) { + return response; + } + // Otherwise, fetch it from the network. + return fetch(event.request); + }) + ); +}); diff --git a/sw.js b/sw.js deleted file mode 100644 index 1409549..0000000 --- a/sw.js +++ /dev/null @@ -1,34 +0,0 @@ -const CACHE_NAME = 'timetracker-v1'; -// Add the paths to the files you want to cache -const urlsToCache = [ - '/', - '/index.html' - // If you had separate CSS or JS files, you would add them here too. - // e.g., '/style.css', '/app.js' -]; - -// Install the service worker and cache the app shell -self.addEventListener('install', event => { - event.waitUntil( - caches.open(CACHE_NAME) - .then(cache => { - console.log('Opened cache'); - return cache.addAll(urlsToCache); - }) - ); -}); - -// Intercept network requests and serve from cache if available -self.addEventListener('fetch', event => { - event.respondWith( - caches.match(event.request) - .then(response => { - // Cache hit - return response - if (response) { - return response; - } - // Not in cache - fetch from network - return fetch(event.request); - }) - ); -}); \ No newline at end of file