From 2fa7b4839aedec61a5fdf2e5292440b3b0bb9c6b Mon Sep 17 00:00:00 2001 From: devthejo Date: Fri, 4 Jul 2025 09:02:18 +0200 Subject: [PATCH] fix: bg location lost notif --- .../actions/actionOpenSettings.js | 9 +++ .../notifBackgroundGeolocationLost.js | 55 +++++++++++++++++++ src/notifications/channels/notifSystem.js | 10 ++++ src/notifications/content.js | 6 +- .../displayNotificationHandler.js | 2 + src/notifications/notificationTypes.js | 9 ++- src/notifications/onEvent.js | 5 ++ src/notifications/setActionCategories.js | 12 ++++ 8 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/notifications/actions/actionOpenSettings.js create mode 100644 src/notifications/channels/notifBackgroundGeolocationLost.js create mode 100644 src/notifications/channels/notifSystem.js diff --git a/src/notifications/actions/actionOpenSettings.js b/src/notifications/actions/actionOpenSettings.js new file mode 100644 index 0000000..87fd5f8 --- /dev/null +++ b/src/notifications/actions/actionOpenSettings.js @@ -0,0 +1,9 @@ +import { navActions } from "~/stores"; + +export default function actionOpenSettings({ data }) { + navActions.setNextNavigation([ + { + name: "Params", + }, + ]); +} diff --git a/src/notifications/channels/notifBackgroundGeolocationLost.js b/src/notifications/channels/notifBackgroundGeolocationLost.js new file mode 100644 index 0000000..ad8c9f2 --- /dev/null +++ b/src/notifications/channels/notifBackgroundGeolocationLost.js @@ -0,0 +1,55 @@ +import { createLogger } from "~/lib/logger"; +import { BACKGROUND_SCOPES } from "~/lib/logger/scopes"; +import { Light } from "~/theme/app"; +import { displayNotification } from "../helpers"; +import { generateBackgroundGeolocationLostContent } from "../content"; + +const { colors } = Light; + +const backgroundGeolocationLogger = createLogger({ + module: BACKGROUND_SCOPES.NOTIFICATIONS, + feature: "background-geolocation-channel", +}); + +const channelId = "system"; + +export default async function notifBackgroundGeolocationLost(data) { + backgroundGeolocationLogger.debug( + "Displaying background geolocation lost notification", + { + data, + }, + ); + + // Generate notification content + const { title, body, bigText } = + generateBackgroundGeolocationLostContent(data); + + await displayNotification({ + channelId, + title, + body, + data, + color: colors.warning || colors.primary, + bigText, + android: { + pressAction: { + id: "open-settings", + launchActivity: "default", + }, + actions: [ + { + title: "Paramètres", + pressAction: { + id: "open-settings", + launchActivity: "default", + }, + }, + ], + }, + }); + + backgroundGeolocationLogger.info( + "Background geolocation lost notification displayed successfully", + ); +} diff --git a/src/notifications/channels/notifSystem.js b/src/notifications/channels/notifSystem.js new file mode 100644 index 0000000..45995ea --- /dev/null +++ b/src/notifications/channels/notifSystem.js @@ -0,0 +1,10 @@ +import { createChannel } from "../helpers"; + +const channelId = "system"; + +export async function createNotificationChannel() { + await createChannel({ + id: channelId, + name: "System", + }); +} diff --git a/src/notifications/content.js b/src/notifications/content.js index 448e4d1..ccb75cc 100644 --- a/src/notifications/content.js +++ b/src/notifications/content.js @@ -88,9 +88,9 @@ export const generateSuggestKeepOpenContent = (data) => { export const generateBackgroundGeolocationLostContent = (data) => { return { - title: `Localisation en arrière-plan désactivée`, - body: `Votre localisation en arrière-plan a été désactivée. Veuillez vérifier les paramètres de l'application.`, - bigText: `Votre localisation en arrière-plan a été désactivée. Pour continuer à utiliser pleinement l'application, veuillez vérifier les paramètres de votre appareil.`, + title: `Alerte-Secours ne peut plus accéder à votre position`, + body: `Vous ne pouvez plus recevoir d'alertes de proximité. Vérifiez les paramètres.`, + bigText: `Alerte-Secours ne peut plus accéder à votre position en arrière-plan. Vous ne pouvez plus recevoir d'alertes de proximité. Causes possibles : permissions révoquées, optimisation de batterie active, ou actualisation désactivée. Accédez aux paramètres de l'application pour réactiver.`, }; }; diff --git a/src/notifications/displayNotificationHandler.js b/src/notifications/displayNotificationHandler.js index 2a254af..dae822c 100644 --- a/src/notifications/displayNotificationHandler.js +++ b/src/notifications/displayNotificationHandler.js @@ -7,6 +7,7 @@ import notifSuggestClose from "./channels/notifSuggestClose"; import notifSuggestKeepOpen from "./channels/notifSuggestKeepOpen"; import notifRelativeAllowAsk from "./channels/notifRelativeAllowAsk"; import notifRelativeInvitation from "./channels/notifRelativeInvitation"; +import notifBackgroundGeolocationLost from "./channels/notifBackgroundGeolocationLost"; const displayLogger = createLogger({ module: BACKGROUND_SCOPES.NOTIFICATIONS, @@ -20,6 +21,7 @@ const SUPPORTED_ACTIONS = { "suggest-keep-open": notifSuggestKeepOpen, "relative-allow-ask": notifRelativeAllowAsk, "relative-invitation": notifRelativeInvitation, + "background-geolocation-lost": notifBackgroundGeolocationLost, }; export default async function displayNotificationHandler(data) { diff --git a/src/notifications/notificationTypes.js b/src/notifications/notificationTypes.js index 65c3298..131c710 100644 --- a/src/notifications/notificationTypes.js +++ b/src/notifications/notificationTypes.js @@ -1,6 +1,7 @@ import { VirtualNotificationTypes } from "./virtualNotifications"; import { getNotificationContent } from "./content"; import openSettings from "~/lib/native/openSettings"; +import { navActions } from "~/stores"; export const getNotificationColor = (notification, theme) => { const { colors } = theme; @@ -83,7 +84,13 @@ export const createNotificationHandlers = (handlers) => { suggest_keep_open: async (data) => await openAlert({ data }), relative_invitation: async (data) => await openRelatives({ data }), relative_allow_ask: async (data) => await openRelatives({ data }), - background_geolocation_lost: async (data) => openSettings(), + background_geolocation_lost: async (data) => { + navActions.setNextNavigation([ + { + name: "Params", + }, + ]); + }, }; return { diff --git a/src/notifications/onEvent.js b/src/notifications/onEvent.js index c079be1..459f7b4 100644 --- a/src/notifications/onEvent.js +++ b/src/notifications/onEvent.js @@ -14,6 +14,7 @@ import actionRelativeAllowAccept from "./actions/actionRelativeAllowAccept"; import actionRelativeAllowReject from "./actions/actionRelativeAllowReject"; import actionRelativeInvitationAccept from "./actions/actionRelativeInvitationAccept"; import actionRelativeInvitationReject from "./actions/actionRelativeInvitationReject"; +import actionOpenSettings from "./actions/actionOpenSettings"; import { navActions } from "~/stores"; @@ -273,5 +274,9 @@ export const onEvent = async ({ type, notification, pressAction }) => { await actionRelativeInvitationReject({ data }); break; } + case "open-settings": { + await actionOpenSettings({ data }); + break; + } } }; diff --git a/src/notifications/setActionCategories.js b/src/notifications/setActionCategories.js index cad8d72..0b99cfd 100644 --- a/src/notifications/setActionCategories.js +++ b/src/notifications/setActionCategories.js @@ -6,6 +6,7 @@ import { createNotificationChannel as createSuggestCloseChannel } from "./channe import { createNotificationChannel as createSuggestKeepOpenChannel } from "./channels/notifSuggestKeepOpen"; import { createNotificationChannel as createRelativeAllowAskChannel } from "./channels/notifRelativeAllowAsk"; import { createNotificationChannel as createRelativeInvitationChannel } from "./channels/notifRelativeInvitation"; +import { createNotificationChannel as createSystemChannel } from "./channels/notifSystem"; export default async function setActionCategories() { // Create all notification channels @@ -17,6 +18,7 @@ export default async function setActionCategories() { createSuggestKeepOpenChannel(), createRelativeAllowAskChannel(), createRelativeInvitationChannel(), + createSystemChannel(), ]); } catch (error) { const errorData = { @@ -113,5 +115,15 @@ export default async function setActionCategories() { }, ], }, + { + id: "system", + actions: [ + { + id: "open-settings", + title: "Paramètres", + foreground: true, + }, + ], + }, ]); }