diff --git a/src/js/controls.js b/src/js/controls.js index 4dd7dc31..124f4690 100644 --- a/src/js/controls.js +++ b/src/js/controls.js @@ -29,8 +29,8 @@ import ThreeD from "./three-d"; import LayerConfig from "./layer-manager/layer-config"; import LocationLayers from "./services/location-styles"; -// TODO: activate -// import ImmersiveNotifications from "./immersive-notifications"; + +import ImmersiveNotifications from "./immersive-notifications"; /** * Ajout des contrôle à la fin du chargement de la carte @@ -135,9 +135,8 @@ const addControls = () => { } }); - // TODO: activate - // // contrôle "notifications immersives" - // Globals.immersiveNotifications = new ImmersiveNotifications(true); + // contrôle "notifications immersives" + Globals.immersiveNotifications = new ImmersiveNotifications(true); // compte utilisateur Globals.myaccount = new MyAccount(map, {}); diff --git a/src/js/globals.js b/src/js/globals.js index 3969c381..c4a874e9 100644 --- a/src/js/globals.js +++ b/src/js/globals.js @@ -153,7 +153,7 @@ if (!localStorage.getItem("walkingSpeed")) { // Are new place notifications enabled? let newPlaceNotifEnabled; if (!localStorage.getItem("newPlaceNotifEnabled")) { - newPlaceNotifEnabled = 0; + newPlaceNotifEnabled = 1; } else { newPlaceNotifEnabled = parseFloat(localStorage.getItem("newPlaceNotifEnabled")); } diff --git a/src/js/immersive-notifications.js b/src/js/immersive-notifications.js index 9fd4aea3..365a0f33 100644 --- a/src/js/immersive-notifications.js +++ b/src/js/immersive-notifications.js @@ -38,6 +38,8 @@ class ImmersiveNotifications { this.positionWatcherId = null; this.locationBg = null; + this.isBackground = false; + this.lastNotificationId = 0; this.requestNotificationPermission().then( () => { @@ -66,12 +68,13 @@ class ImmersiveNotifications { */ listen() { this.intervalId = setInterval(this.#sendNotifications.bind(this), this.test ? 10000 : 120000); + this.#startBgTracking(); App.addListener("appStateChange", (state) => { if (!state.isActive) { - this.#startBgTracking(); + this.isBackground = true; } else { - this.#stopBgTracking(); + this.isBackground = false; } }); } @@ -102,6 +105,10 @@ class ImmersiveNotifications { distanceFilter: 1000, }, async (position, error) => { + if (!this.isBackground) { + return; + } + if (error) { console.error("Geolocation error:", error); return; @@ -121,7 +128,7 @@ class ImmersiveNotifications { /** * Stops background location tracking for notifications */ - async #stopBgTracking() { + async stopBgTracking() { if (["denied", "prompt-with-rationale"].includes(this.permissionStatus.display)) { return; }