Remove manual service worker registration; rely on VitePWA auto-registration

- Deleted src/registerServiceWorker.ts and all related imports
- Cleaned up WebPlatformService and main.web.ts to remove manual SW logic
- Updated VitePWA config for correct dev/prod SW handling
- Fixed missing FontAwesome download icon in PWA prompt
- Updated docs to reflect new PWA registration approach

PWA now works reliably in all web environments with zero manual SW code.
This commit is contained in:
Matthew Raymer
2025-07-15 06:13:33 +00:00
parent 6dea12bbaf
commit 6d4fb4f57a
23 changed files with 328 additions and 126 deletions

View File

@@ -79,12 +79,6 @@ export default class PWAInstallPrompt extends Vue {
}
private setupInstallPrompt() {
// Only show install prompt if PWA is enabled
if (process.env.VITE_PWA_ENABLED !== "true") {
logger.debug("[PWA] Install prompt disabled - PWA not enabled");
return;
}
// Check if already installed
if (this.isPWAInstalled()) {
logger.debug("[PWA] Install prompt disabled - PWA already installed");
@@ -95,9 +89,6 @@ export default class PWAInstallPrompt extends Vue {
window.addEventListener('beforeinstallprompt', (e) => {
logger.debug("[PWA] beforeinstallprompt event fired");
// Prevent the mini-infobar from appearing on mobile
e.preventDefault();
// Stash the event so it can be triggered later
this.deferredPrompt = e as BeforeInstallPromptEvent;

View File

@@ -36,6 +36,7 @@ import {
faComment,
faCopy,
faDollar,
faDownload,
faEllipsis,
faEllipsisVertical,
faEnvelopeOpenText,
@@ -121,6 +122,7 @@ library.add(
faComment,
faCopy,
faDollar,
faDownload,
faEllipsis,
faEllipsisVertical,
faEnvelopeOpenText,

View File

@@ -2,12 +2,8 @@ import { initializeApp } from "./main.common";
import { logger } from "./utils/logger";
const platform = process.env.VITE_PLATFORM;
const pwa_enabled = process.env.VITE_PWA_ENABLED === "true";
// Only import service worker for web builds
if (pwa_enabled) {
import("./registerServiceWorker"); // Web PWA support
}
// PWA service worker is automatically registered by VitePWA plugin
const app = initializeApp();

View File

@@ -1,37 +0,0 @@
/* eslint-disable no-console */
import { register } from "register-service-worker";
// Register service worker if PWA is enabled
// Enable in all environments for consistent testing and functionality
if (process.env.VITE_PWA_ENABLED === "true") {
register(`${process.env.BASE_URL}sw.js`, {
ready() {
console.log("Service worker is active.");
},
registered() {
console.log("Service worker has been registered.");
},
cached() {
console.log("Content has been cached for offline use.");
},
updatefound() {
console.log("New content is downloading.");
},
updated() {
console.log("New content is available; please refresh.");
},
offline() {
console.log(
"No internet connection found. App is running in offline mode.",
);
},
error(error) {
console.error("Error during service worker registration:", error);
},
});
} else {
console.log(
`Service worker registration skipped - PWA not enabled (VITE_PWA_ENABLED=${process.env.VITE_PWA_ENABLED})`,
);
}

View File

@@ -647,13 +647,13 @@ export class WebPlatformService implements PlatformService {
// --- PWA/Web-only methods ---
public registerServiceWorker(): void {
if (this.isPWAEnabled) {
import("@/registerServiceWorker");
}
// PWA service worker is automatically registered by VitePWA plugin
// No manual registration needed
}
public get isPWAEnabled(): boolean {
return process.env.VITE_PWA_ENABLED === "true";
// PWA is always enabled for web platform
return true;
}
/**