diff --git a/src/notifications/channels/notifGeolocationHeartbeatSync.js b/src/notifications/channels/notifGeolocationHeartbeatSync.js new file mode 100644 index 0000000..4bce333 --- /dev/null +++ b/src/notifications/channels/notifGeolocationHeartbeatSync.js @@ -0,0 +1,38 @@ +import { createLogger } from "~/lib/logger"; +import { BACKGROUND_SCOPES } from "~/lib/logger/scopes"; +import { executeHeartbeatSync } from "~/location/backgroundTask"; + +const heartbeatLogger = createLogger({ + module: BACKGROUND_SCOPES.NOTIFICATIONS, + feature: "geolocation-heartbeat-sync", +}); + +export default async function notifGeolocationHeartbeatSync(data) { + try { + heartbeatLogger.info( + "Received iOS geolocation heartbeat sync notification", + { + data, + }, + ); + + // This is a silent notification - no visible notification is displayed + // Instead, we trigger the geolocation heartbeat sync directly + + heartbeatLogger.info("Triggering geolocation heartbeat sync"); + + // Execute the heartbeat sync to force location update + await executeHeartbeatSync(); + + heartbeatLogger.info("Geolocation heartbeat sync completed successfully"); + } catch (error) { + heartbeatLogger.error("Failed to execute geolocation heartbeat sync", { + error: error.message, + stack: error.stack, + data, + }); + + // Don't throw the error - this is a background operation + // and we don't want to crash the notification handler + } +} diff --git a/src/notifications/displayNotificationHandler.js b/src/notifications/displayNotificationHandler.js index dae822c..5c341fa 100644 --- a/src/notifications/displayNotificationHandler.js +++ b/src/notifications/displayNotificationHandler.js @@ -8,6 +8,7 @@ import notifSuggestKeepOpen from "./channels/notifSuggestKeepOpen"; import notifRelativeAllowAsk from "./channels/notifRelativeAllowAsk"; import notifRelativeInvitation from "./channels/notifRelativeInvitation"; import notifBackgroundGeolocationLost from "./channels/notifBackgroundGeolocationLost"; +import notifGeolocationHeartbeatSync from "./channels/notifGeolocationHeartbeatSync"; const displayLogger = createLogger({ module: BACKGROUND_SCOPES.NOTIFICATIONS, @@ -22,6 +23,7 @@ const SUPPORTED_ACTIONS = { "relative-allow-ask": notifRelativeAllowAsk, "relative-invitation": notifRelativeInvitation, "background-geolocation-lost": notifBackgroundGeolocationLost, + "geolocation-heartbeat-sync": notifGeolocationHeartbeatSync, }; export default async function displayNotificationHandler(data) {