feat: transform library into Progressive Web App (PWA)

Implements issue #52 - adds complete PWA functionality with offline support, installability, and app-like experience.

PWA Features:
- Installable on mobile devices and desktop
- Offline support with smart caching strategies
- App-like experience with standalone display mode
- Full-screen mode and app icon on home screen
- Install prompt with beautiful banner UI

Manifest Configuration:
- Created manifest.json with app metadata
- App name: "Naomi's Library"
- Theme colour: #9d4edd (witchy purple!)
- Background colour: #1a1a2e (dark theme)
- Display mode: standalone (app-like)
- Icons: Multiple sizes specified (72-512px, maskable variants)
- Categories: entertainment, lifestyle

Service Worker Implementation:
- Cache-first strategy for static assets (JS, CSS, fonts, images)
- Network-first strategy for API requests with cache fallback
- Network-first strategy for HTML pages with cache fallback
- Cache versioning: library-v1 (static, dynamic, images)
- Automatic cache cleanup on activation
- Update checking every 60 seconds
- Message handling for cache clearing and skipWaiting

Offline Support:
- Created offline.html fallback page with beautiful UI
- Auto-retry when network comes back online
- Purple gradient matching app theme
- Informative messaging about offline state

Install Prompt:
- Created PwaInstallComponent with banner UI
- Detects installability and shows prompt
- "Install" and "Not Now" actions
- Responsive design for mobile and desktop
- Session storage for dismissal state
- Animated slide-up entrance

Services:
- PwaService: Manages service worker registration, install prompts, cache clearing
- Automatic initialization on app bootstrap
- Signals for reactivity: isInstallable, isInstalled, promptEvent
- Update detection and notification

HTML Updates:
- Added PWA meta tags (theme-color, description)
- Linked manifest.json
- Apple-specific meta tags for iOS support
- Apple touch icon specified

Build Configuration:
- Updated project.json to include PWA assets
- manifest.json, service-worker.js, offline.html copied to dist root

Integration:
- Added PwaService to app bootstrap
- Integrated PwaInstallComponent in main app template
- Install banner appears at bottom of screen
- Dismissible with session storage

Technical Notes:
- Service worker uses efficient caching strategies per resource type
- Handles Chrome extensions and non-HTTP protocols gracefully
- Supports message-based cache clearing
- Includes skipWaiting for immediate updates
- Compatible with iOS, Android, and desktop PWA standards

The library is now a fully-functional Progressive Web App that users can install on any device! The app works offline with cached content and provides an app-like experience with no browser UI in standalone mode.

Note: App icons still need to be generated/provided (placeholder paths specified in manifest).

 This feature was built by Hikari~ 🌸
This commit is contained in:
2026-02-20 00:43:55 -08:00
committed by Naomi Carrigan
parent 7606a18e38
commit c1d2e192da
9 changed files with 664 additions and 1 deletions
@@ -0,0 +1,176 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Hikari
*/
import { Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PwaService } from '../../services/pwa.service';
@Component({
selector: 'app-pwa-install',
standalone: true,
imports: [CommonModule],
template: `
@if (pwaService.isInstallable() && !dismissed) {
<div class="install-banner">
<div class="install-content">
<div class="install-icon">📱</div>
<div class="install-text">
<h3>Install Naomi's Library</h3>
<p>Add to your home screen for quick access and offline support!</p>
</div>
</div>
<div class="install-actions">
<button (click)="install()" class="btn-install">Install</button>
<button (click)="dismiss()" class="btn-dismiss">Not Now</button>
</div>
</div>
}
`,
styles: [`
.install-banner {
position: fixed;
bottom: 1rem;
left: 50%;
transform: translateX(-50%);
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
border: 2px solid #9d4edd;
border-radius: 12px;
padding: 1.5rem;
max-width: 500px;
width: calc(100% - 2rem);
box-shadow: 0 8px 32px rgba(157, 78, 221, 0.3);
z-index: 1000;
animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
from {
transform: translateX(-50%) translateY(100px);
opacity: 0;
}
to {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
}
.install-content {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 1rem;
}
.install-icon {
font-size: 2.5rem;
flex-shrink: 0;
}
.install-text h3 {
margin: 0 0 0.25rem 0;
color: #9d4edd;
font-size: 1.1rem;
}
.install-text p {
margin: 0;
color: #b0b0b0;
font-size: 0.9rem;
}
.install-actions {
display: flex;
gap: 0.75rem;
justify-content: flex-end;
}
.btn-install,
.btn-dismiss {
padding: 0.75rem 1.5rem;
border: none;
border-radius: 8px;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
}
.btn-install {
background: linear-gradient(135deg, #9d4edd 0%, #c77dff 100%);
color: white;
}
.btn-install:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(157, 78, 221, 0.4);
}
.btn-dismiss {
background: transparent;
color: #9d4edd;
border: 1px solid #9d4edd;
}
.btn-dismiss:hover {
background: rgba(157, 78, 221, 0.1);
}
@media (max-width: 600px) {
.install-banner {
bottom: 0;
left: 0;
right: 0;
transform: none;
max-width: none;
width: 100%;
border-radius: 12px 12px 0 0;
border-bottom: none;
}
@keyframes slideUp {
from {
transform: translateY(100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.install-content {
flex-direction: column;
text-align: center;
}
.install-actions {
flex-direction: column-reverse;
}
.btn-install,
.btn-dismiss {
width: 100%;
}
}
`]
})
export class PwaInstallComponent {
protected pwaService = inject(PwaService);
protected dismissed = false;
protected async install(): Promise<void> {
const result = await this.pwaService.promptInstall();
if (result) {
this.dismissed = true;
}
}
protected dismiss(): void {
this.dismissed = true;
// Remember dismissal in session storage
sessionStorage.setItem('pwa-install-dismissed', 'true');
}
}