Skip to content

Commit

Permalink
feat: update manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullathedruid committed Dec 26, 2024
1 parent eed563b commit ba0f392
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 50 deletions.
3 changes: 2 additions & 1 deletion priv/static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "GymLive",
"short_name": "GymLive",
"description": "Track your workouts and progress in real-time",
"start_url": "/workouts",
"id": "/",
"scope": "/",
"start_url": "/workouts",
"display": "standalone",
"orientation": "portrait",
"background_color": "#ffffff",
Expand Down
72 changes: 23 additions & 49 deletions priv/static/sw.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,29 @@
const CACHE_NAME = 'gym-live-v1';
const URLS_TO_CACHE = [
'/',
'/manifest.json',
'/assets/app.css',
'/assets/app.js',
'/images/icons/icon-72x72.png',
'/images/icons/icon-96x96.png',
'/images/icons/icon-128x128.png',
'/images/icons/icon-144x144.png',
'/images/icons/icon-152x152.png',
'/images/icons/icon-192x192.png',
'/images/icons/icon-384x384.png',
'/images/icons/icon-512x512.png'
];
const sw = self;
const config = {
debug: false,
}

self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => {
return cache.addAll(URLS_TO_CACHE);
})
);
});
const { debug } = config;

self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request)
.then((response) => {
// Cache hit - return response
if (response) {
return response;
}
sw.addEventListener('install', handleInstall);

return fetch(event.request).then(
(response) => {
// Check if we received a valid response
if (!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
function handleInstall(event) {
debug && console.log('[Service Worker] Installed.');
}

// Clone the response
const responseToCache = response.clone();
sw.addEventListener('fetch', handleFetch);

caches.open(CACHE_NAME)
.then((cache) => {
cache.put(event.request, responseToCache);
});
function handleFetch(event) {
// Ignore non-GET requests
if (event.request.method.toUpperCase() !== 'GET') { return; }

return response;
}
);
})
);
});
// Ignore requests from Chrome extensions
if (event.request.url.startsWith("chrome-extension://")) { return; }

const url = new URL(event.request.url);
// Ignore LiveReloader - only requested in dev
if (url.pathname === "/phoenix/live_reload/frame") { return; }

debug && console.log('[Service Worker] Handling fetch:', event.request.url);
event.respondWith(fetch(event.request));
}

0 comments on commit ba0f392

Please sign in to comment.