WIP: disabling absurd-sql when using Capacitor SQLite

This commit is contained in:
Matthew Raymer
2025-05-27 13:15:41 +00:00
parent a228a9b1c0
commit b18112b869
5 changed files with 151 additions and 33 deletions

View File

@@ -1,7 +1,11 @@
// @ts-expect-error but not sure why it's not in there
import { initBackend } from "absurd-sql/dist/indexeddb-main-thread";
import { initializeApp } from "./main.common";
import "./registerServiceWorker"; // Web PWA support
// Only import service worker for web builds
if (process.env.VITE_PLATFORM !== 'electron' && process.env.VITE_PWA_ENABLED === 'true') {
import("./registerServiceWorker"); // Web PWA support
}
const app = initializeApp();

View File

@@ -2,11 +2,18 @@
import { register } from "register-service-worker";
// Only register service worker if explicitly enabled and in production
if (
process.env.VITE_PWA_ENABLED === "true" &&
process.env.NODE_ENV === "production"
) {
// Check if we're in an Electron environment
const isElectron = process.env.VITE_PLATFORM === 'electron' ||
process.env.VITE_DISABLE_PWA === 'true' ||
window.navigator.userAgent.toLowerCase().includes('electron');
// Only register service worker if:
// 1. Not in Electron
// 2. PWA is explicitly enabled
// 3. In production mode
if (!isElectron &&
process.env.VITE_PWA_ENABLED === "true" &&
process.env.NODE_ENV === "production") {
register(`${process.env.BASE_URL}sw.js`, {
ready() {
console.log("Service worker is active.");
@@ -34,6 +41,12 @@ if (
});
} else {
console.log(
"Service worker registration skipped - not enabled or not in production",
`Service worker registration skipped - ${
isElectron
? "running in Electron"
: process.env.VITE_PWA_ENABLED !== "true"
? "PWA not enabled"
: "not in production mode"
}`
);
}