forked from jsnbuchanan/crowd-funder-for-time-pwa
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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})`,
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user