diff --git a/src/lib/components/common/OfflineIndicator.svelte b/src/lib/components/common/OfflineIndicator.svelte index d966e47..dee3860 100644 --- a/src/lib/components/common/OfflineIndicator.svelte +++ b/src/lib/components/common/OfflineIndicator.svelte @@ -13,10 +13,10 @@ $: messageData = isOfflinePage ? { message: 'Currently offline. Awaiting internet connection...', showLink: false, isError: false } : isActualTool - ? { message: 'You are offline. This tool has been downloaded.', showLink: false, isError: false } - : !worksOffline - ? { message: 'This tool may not function correctly without network access', showLink: false, isError: true } - : { message: 'Offline, limited functionality available.', showLink: true, isError: false }; + ? { message: 'You are offline. This tool has been downloaded.', showLink: false, isError: false } + : !worksOffline + ? { message: 'This tool may not function correctly without network access', showLink: false, isError: true } + : { message: 'Offline, limited functionality available.', showLink: true, isError: false }; $: message = messageData.message; $: showOfflineLink = messageData.showLink; diff --git a/src/lib/stores/offline.ts b/src/lib/stores/offline.ts index 4a9ffad..6716bb6 100644 --- a/src/lib/stores/offline.ts +++ b/src/lib/stores/offline.ts @@ -20,7 +20,7 @@ export const serviceWorkerRegistered = writable(false); export const offlineCapabilities = writable({ cacheEnabled: false, backgroundSync: false, - pushNotifications: false + pushNotifications: false, }); // Initialize offline functionality @@ -37,12 +37,14 @@ export function initializeOfflineSupport() { // Trigger background sync if available if ('serviceWorker' in navigator && 'sync' in window.ServiceWorkerRegistration.prototype) { - navigator.serviceWorker.ready.then(registration => { - // Cast to any to work around TypeScript sync API limitations - return (registration as any).sync.register('background-sync-bookmarks'); - }).catch(err => { - log('Offline', ' Background sync failed:', err); - }); + navigator.serviceWorker.ready + .then((registration) => { + // Cast to any to work around TypeScript sync API limitations + return (registration as any).sync.register('background-sync-bookmarks'); + }) + .catch((err) => { + log('Offline', ' Background sync failed:', err); + }); } }; @@ -76,7 +78,7 @@ async function registerServiceWorker() { try { const registration = await navigator.serviceWorker.register('/sw.js', { - scope: '/' + scope: '/', }); serviceWorkerRegistered.set(true); @@ -86,7 +88,7 @@ async function registerServiceWorker() { offlineCapabilities.set({ cacheEnabled: true, backgroundSync: 'sync' in (registration as any), - pushNotifications: 'showNotification' in registration + pushNotifications: 'showNotification' in registration, }); // Listen for service worker updates @@ -119,7 +121,6 @@ async function registerServiceWorker() { log('SW', ' Unknown message type:', type); } }); - } catch (error) { log('SW', 'Service worker registration failed:', error); serviceWorkerRegistered.set(false); @@ -130,32 +131,36 @@ async function registerServiceWorker() { export function cacheBookmark(url: string) { if (!browser || !('serviceWorker' in navigator)) return; - navigator.serviceWorker.ready.then(registration => { - if (registration.active) { - registration.active.postMessage({ - type: 'CACHE_BOOKMARK', - url: url - }); - } - }).catch(error => { - log('SW', ' Failed to cache bookmark:', error); - }); + navigator.serviceWorker.ready + .then((registration) => { + if (registration.active) { + registration.active.postMessage({ + type: 'CACHE_BOOKMARK', + url: url, + }); + } + }) + .catch((error) => { + log('SW', ' Failed to cache bookmark:', error); + }); } // Cache all bookmarks at once export function cacheAllBookmarks(bookmarks: any[]) { if (!browser || !('serviceWorker' in navigator)) return; - navigator.serviceWorker.ready.then(registration => { - if (registration.active) { - registration.active.postMessage({ - type: 'CACHE_ALL_BOOKMARKS', - bookmarks: bookmarks - }); - } - }).catch(error => { - log('SW', ' Failed to cache all bookmarks:', error); - }); + navigator.serviceWorker.ready + .then((registration) => { + if (registration.active) { + registration.active.postMessage({ + type: 'CACHE_ALL_BOOKMARKS', + bookmarks: bookmarks, + }); + } + }) + .catch((error) => { + log('SW', ' Failed to cache all bookmarks:', error); + }); } // Sync bookmarks data (called by service worker) @@ -176,8 +181,8 @@ function getAllToolRoutes(): string[] { const toolRoutes: string[] = []; // Iterate through all sections in SUB_NAV - Object.values(SUB_NAV).forEach(sectionItems => { - sectionItems.forEach(item => { + Object.values(SUB_NAV).forEach((sectionItems) => { + sectionItems.forEach((item) => { if ('href' in item && item.href) { // Extract the route pattern from the href const pathParts = item.href.split('/').filter(Boolean); @@ -189,7 +194,7 @@ function getAllToolRoutes(): string[] { } } else if ('items' in item && item.items) { // Handle NavGroup - extract routes from nested items - item.items.forEach(subItem => { + item.items.forEach((subItem) => { if (subItem.href) { const pathParts = subItem.href.split('/').filter(Boolean); if (pathParts.length >= 2) { @@ -210,11 +215,11 @@ function getAllToolRoutes(): string[] { // Check if a URL is an actual downloadable tool (not just a regular page) export function isDownloadableTool(url: string): boolean { const toolRoutes = getAllToolRoutes(); - return toolRoutes.some(route => url.includes(route)); + return toolRoutes.some((route) => url.includes(route)); } // Derived store for offline-ready status export const offlineReady = derived( [serviceWorkerRegistered, offlineCapabilities], - ([$registered, $capabilities]) => $registered && $capabilities.cacheEnabled + ([$registered, $capabilities]) => $registered && $capabilities.cacheEnabled, ); diff --git a/src/lib/stores/version.ts b/src/lib/stores/version.ts index e8bb77e..c688bdd 100644 --- a/src/lib/stores/version.ts +++ b/src/lib/stores/version.ts @@ -23,4 +23,4 @@ export async function initializeVersion() { log('Failed to fetch version from API, using fallback'); // Keep fallback version } -} \ No newline at end of file +} diff --git a/src/routes/offline/+page.server.ts b/src/routes/offline/+page.server.ts index 261d8ce..cffca4f 100644 --- a/src/routes/offline/+page.server.ts +++ b/src/routes/offline/+page.server.ts @@ -11,6 +11,6 @@ export const load: PageServerLoad = async () => { return { breadcrumbJsonLd: null, // No breadcrumbs needed for offline page version: '0.2.5', // Hardcoded fallback version for offline page - isOfflinePage: true // Flag to indicate this is the special offline page + isOfflinePage: true, // Flag to indicate this is the special offline page }; -}; \ No newline at end of file +}; diff --git a/src/routes/offline/+page.svelte b/src/routes/offline/+page.svelte index 0a5e2b6..8a8bb3c 100644 --- a/src/routes/offline/+page.svelte +++ b/src/routes/offline/+page.svelte @@ -11,7 +11,7 @@ const handleOnline = () => { isOnline = true; - setTimeout(() => window.location.href = '/', 1000); + setTimeout(() => (window.location.href = '/'), 1000); }; const handleOffline = () => { @@ -35,14 +35,14 @@
- +

- {isOnline ? "Back Online" : "You're Offline"} + {isOnline ? 'Back Online' : "You're Offline"}

- {isOnline ? "Connection restored! Redirecting..." : "Your bookmarked tools work offline"} + {isOnline ? 'Connection restored! Redirecting...' : 'Your bookmarked tools work offline'}

@@ -59,48 +59,48 @@
diff --git a/src/routes/version/+server.ts b/src/routes/version/+server.ts index 7ae7727..b4a598f 100644 --- a/src/routes/version/+server.ts +++ b/src/routes/version/+server.ts @@ -7,13 +7,16 @@ export async function GET() { const pkg = JSON.parse(readFileSync('package.json', 'utf8')); return json({ version: pkg.version, - timestamp: Date.now() + timestamp: Date.now(), }); } catch { - return json({ - version: 'unknown', - timestamp: Date.now(), - error: 'Failed to read version' - }, { status: 500 }); + return json( + { + version: 'unknown', + timestamp: Date.now(), + error: 'Failed to read version', + }, + { status: 500 }, + ); } -} \ No newline at end of file +}