server now pushes index.html
This commit is contained in:
parent
3168aa5320
commit
f77a193791
@ -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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -4,6 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="manifest" href="/manifest.json">
|
||||||
<title>TimeTracker</title>
|
<title>TimeTracker</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
@ -249,6 +250,21 @@
|
|||||||
// --- Initializer ---
|
// --- Initializer ---
|
||||||
signOutBtn.addEventListener('click', () => handleSignOut());
|
signOutBtn.addEventListener('click', () => handleSignOut());
|
||||||
updateUI();
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
21
public/manifest.json
Normal file
21
public/manifest.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
42
public/sw.js
Normal file
42
public/sw.js
Normal file
@ -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);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
34
sw.js
34
sw.js
@ -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);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user