Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App version and auto loading local dev configs #764

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { inactivityTime, urls } from "./src/shared.js";
import { firebaseConfig as devFirebaseConfig } from "./src/dev/config.js";
import { firebaseConfig as stageFirebaseConfig } from "./src/stage/config.js";
import { firebaseConfig as prodFirebaseConfig } from "./src/prod/config.js";
// When doing local development, uncomment this
// Get the API key file from Box or the DevOps team
// Do not accept PRs with the localDevFirebaseConfig import uncommented
// import { firebaseConfig as localDevFirebaseConfig} from "./src/local-dev/config.js";
import { manageUsers } from "./src/pages/users.js";
import { userDashboard } from "./src/pages/dashboard.js";
import { shippingDashboard } from "./src/pages/shipping.js";
Expand Down Expand Up @@ -34,23 +30,31 @@ import { checkOutReportTemplate } from "./src/pages/checkOutReport.js";
import { dailyReportTemplate } from "./src/pages/dailyReport.js";

if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("./serviceWorker.js").catch((error) => {
console.error("Service worker registration failed.", error);
return;
});

navigator.serviceWorker.ready.then(() => {
if (navigator.serviceWorker.controller) {
navigator.serviceWorker.controller.postMessage({ action: "getAppVersion" });
}
});

navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data.action === "sendAppVersion") {
document.getElementById("appVersion").textContent = event.data.payload;
}
});
}
navigator.serviceWorker
.register("./serviceWorker.js")
.then((registration) => {
registration.onupdatefound = () => {
const sw = registration.installing;
if (sw) {
sw.onstatechange = () => sw.state === "activated" && sw.postMessage({ action: "getAppVersion" });
}
};
})
.catch((err) => {
console.error("Service worker registration failed.", err);
});

navigator.serviceWorker.ready.then(() => {
const sw = navigator.serviceWorker.controller;
sw && sw.postMessage({ action: "getAppVersion" });
});

navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data.action === "sendAppVersion") {
document.getElementById("appVersion").textContent = event.data.payload;
}
});
}

let auth = '';

Expand All @@ -69,7 +73,7 @@ const datadogConfig = {

const isLocalDev = location.hostname === 'localhost' || location.hostname === '127.0.0.1';

window.onload = () => {
window.onload = async () => {
if(location.host === urls.prod) {
!firebase.apps.length ? firebase.initializeApp(prodFirebaseConfig()) : firebase.app();
window.DD_RUM && window.DD_RUM.init({ ...datadogConfig, env: 'prod' });
Expand All @@ -79,8 +83,9 @@ window.onload = () => {
window.DD_RUM && window.DD_RUM.init({ ...datadogConfig, env: 'stage' });
}
else if (isLocalDev) {
if (typeof localDevFirebaseConfig === 'undefined') {
console.error('Local development requires a localDevFirebaseConfig function to be defined in src/local-dev/config.js.');
const { firebaseConfig: localDevFirebaseConfig} = await import("./src/local-dev/config.js");
if (!localDevFirebaseConfig) {
console.error('Local development requires a firebaseConfig function defined in src/local-dev/config.js.');
return;
}
!firebase.apps.length ? firebase.initializeApp(localDevFirebaseConfig()) : firebase.app();
Expand Down
2 changes: 1 addition & 1 deletion serviceWorker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');

const appVersion = "v24.10.0";
const appVersion = "v24.12.0";
workbox.setConfig({debug: false});
const { registerRoute } = workbox.routing;
const { CacheFirst, NetworkFirst } = workbox.strategies;
Expand Down