Skip to content
Draft
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
9 changes: 4 additions & 5 deletions src/js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, {});
Expand Down
2 changes: 1 addition & 1 deletion src/js/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
13 changes: 10 additions & 3 deletions src/js/immersive-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ImmersiveNotifications {
this.positionWatcherId = null;
this.locationBg = null;

this.isBackground = false;

this.lastNotificationId = 0;

this.requestNotificationPermission().then( () => {
Expand Down Expand Up @@ -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;
}
});
}
Expand Down Expand Up @@ -102,6 +105,10 @@ class ImmersiveNotifications {
distanceFilter: 1000,
},
async (position, error) => {
if (!this.isBackground) {
return;
}

if (error) {
console.error("Geolocation error:", error);
return;
Expand All @@ -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;
}
Expand Down