feat: add PWA support - manifest, service worker, offline page, icons

This commit is contained in:
2026-06-14 10:15:20 -04:00
parent 01f1215cef
commit 639af6371e
8 changed files with 135 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

26
public/manifest.json Normal file
View File

@@ -0,0 +1,26 @@
{
"name": "ServerManager",
"short_name": "SM",
"description": "Linux Server Management Platform",
"start_url": "/dashboard",
"display": "standalone",
"background_color": "#0f1117",
"theme_color": "#6366f1",
"categories": ["productivity", "utilities"],
"lang": "en",
"orientation": "any",
"icons": [
{
"src": "/assets/img/icon-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "/assets/img/icon-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
]
}

71
public/sw.js Normal file
View File

@@ -0,0 +1,71 @@
const CACHE = 'sm-v1';
const STATIC_ASSETS = [
'/assets/css/style.css',
'/assets/js/app.js',
'/assets/js/main.js',
'/assets/img/server.svg',
'/assets/img/icon-192.png',
'/assets/img/icon-512.png',
'/manifest.json',
'/offline',
];
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(CACHE).then(function(cache) {
return cache.addAll(STATIC_ASSETS);
}).then(function() {
return self.skipWaiting();
})
);
});
self.addEventListener('activate', function(e) {
e.waitUntil(
caches.keys().then(function(keys) {
return Promise.all(
keys.filter(function(k) { return k !== CACHE; }).map(function(k) { return caches.delete(k); })
);
}).then(function() {
return self.clients.claim();
})
);
});
self.addEventListener('fetch', function(e) {
var url = new URL(e.request.url);
if (url.pathname.startsWith('/api/')) {
return;
}
if (
url.pathname.startsWith('/assets/') ||
url.pathname === '/manifest.json'
) {
e.respondWith(
caches.open(CACHE).then(function(cache) {
return cache.match(e.request).then(function(cached) {
var fetchPromise = fetch(e.request).then(function(response) {
cache.put(e.request, response.clone());
return response;
});
return cached || fetchPromise;
});
})
);
return;
}
e.respondWith(
fetch(e.request).catch(function() {
return caches.match(e.request).then(function(cached) {
if (cached) return cached;
if (e.request.mode === 'navigate') {
return caches.match('/offline');
}
return new Response('Offline', { status: 503 });
});
})
);
});