mirror of
https://github.com/AeThex-Corporation/AeThex-OS.git
synced 2026-04-18 06:17:21 +00:00
- ModuleManager: Central tracking for installed marketplace modules - DataAnalyzerWidget: Real-time CPU/RAM/Battery/Storage widget (unlocked by Data Analyzer module) - BottomNavBar: Navigation bar for Projects/Chat/Marketplace/Settings - RootShell: Real root command execution utility - TerminalActivity: Full root shell with neofetch, sysinfo, real Linux commands - Terminal Pro module: Adds aliases (ll, la, h), command history - ArcadeActivity + SnakeGame: Pixel Arcade module unlocks retro games - fade_in/fade_out animations for smooth transitions
110 lines
2.9 KiB
JavaScript
110 lines
2.9 KiB
JavaScript
// Service Worker for PWA functionality
|
|
// Skip in dev mode (localhost)
|
|
if (self.location.hostname === 'localhost' || self.location.hostname === '127.0.0.1') {
|
|
self.addEventListener('install', () => {
|
|
self.skipWaiting();
|
|
});
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(
|
|
self.registration.unregister().then(() => {
|
|
return self.clients.matchAll();
|
|
}).then((clients) => {
|
|
clients.forEach(client => client.navigate(client.url));
|
|
})
|
|
);
|
|
});
|
|
} else {
|
|
// Production service worker
|
|
const CACHE_NAME = 'aethex-v3';
|
|
const urlsToCache = [
|
|
|
|
'/',
|
|
'/mobile',
|
|
'/home',
|
|
'/manifest.json',
|
|
'/favicon.png'
|
|
];
|
|
|
|
// Install event - cache assets
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME)
|
|
.then((cache) => {
|
|
console.log('[SW] Caching app shell');
|
|
return cache.addAll(urlsToCache);
|
|
})
|
|
.catch((err) => {
|
|
console.error('[SW] Cache failed:', err);
|
|
})
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
// Activate event - clean up old caches
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((cacheNames) => {
|
|
return Promise.all(
|
|
cacheNames.map((cacheName) => {
|
|
if (cacheName !== CACHE_NAME) {
|
|
console.log('[SW] Deleting old cache:', cacheName);
|
|
return caches.delete(cacheName);
|
|
}
|
|
})
|
|
);
|
|
})
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
// Fetch event - network first, fallback to cache
|
|
self.addEventListener('fetch', (event) => {
|
|
if (event.request.method !== 'GET' || !event.request.url.startsWith('http')) {
|
|
return;
|
|
}
|
|
|
|
event.respondWith(
|
|
fetch(event.request)
|
|
.then((response) => {
|
|
if (!response || response.status !== 200 || response.type !== 'basic') {
|
|
return response;
|
|
}
|
|
const responseToCache = response.clone();
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
cache.put(event.request, responseToCache);
|
|
});
|
|
return response;
|
|
})
|
|
.catch(() => {
|
|
return caches.match(event.request).then((cachedResponse) => {
|
|
return cachedResponse || (event.request.mode === 'navigate' ? caches.match('/') : null);
|
|
});
|
|
})
|
|
);
|
|
});
|
|
|
|
// Push notification
|
|
self.addEventListener('push', (event) => {
|
|
const options = {
|
|
body: event.data ? event.data.text() : 'New notification',
|
|
icon: '/favicon.png',
|
|
vibrate: [200, 100, 200],
|
|
actions: [
|
|
{ action: 'explore', title: 'View' },
|
|
{ action: 'close', title: 'Close' }
|
|
]
|
|
};
|
|
event.waitUntil(
|
|
self.registration.showNotification('AeThex OS', options)
|
|
);
|
|
});
|
|
|
|
// Notification click
|
|
self.addEventListener('notificationclick', (event) => {
|
|
event.notification.close();
|
|
if (event.action === 'explore') {
|
|
event.waitUntil(clients.openWindow('/mobile'));
|
|
}
|
|
});
|
|
|
|
} // End production service worker
|