WIP (fix): improve electron build configuration and service worker handling

- Properly disable service workers in electron builds
- Add CSP headers for electron security
- Fix path resolution in electron context
- Improve preload script error handling and IPC setup
- Update build scripts for better electron/capacitor compatibility
- Fix router path handling in electron context
- Remove electron-builder dependency
- Streamline build process and output structure

This change improves the stability and security of electron builds while
maintaining PWA functionality in web builds. Service workers are now
properly disabled in electron context, and path resolution issues are
fixed.
This commit is contained in:
Matthew Raymer
2025-02-12 13:17:25 +00:00
parent 1be5c530c5
commit d8c1a84cfe
10 changed files with 310 additions and 2735 deletions

View File

@@ -2,14 +2,11 @@
import { register } from "register-service-worker";
// NODE_ENV is "production" by default with "vite build". See https://vitejs.dev/guide/env-and-mode
if (import.meta.env.NODE_ENV === "production") {
register("/sw_scripts-combined.js", {
// Only register service worker if explicitly enabled and in production
if (process.env.VITE_PWA_ENABLED === 'true' && process.env.NODE_ENV === "production") {
register(`${process.env.BASE_URL}sw.js`, {
ready() {
console.log(
"App is being served from cache by a service worker.\n" +
"For more details, visit https://goo.gl/AFskqB",
);
console.log("Service worker is active.");
},
registered() {
console.log("Service worker has been registered.");
@@ -24,12 +21,12 @@ if (import.meta.env.NODE_ENV === "production") {
console.log("New content is available; please refresh.");
},
offline() {
console.log(
"No internet connection found. App is running in offline mode.",
);
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 - not enabled or not in production");
}