feat(notifications): refresh native fetcher on WAKEUP_PING silent push
Add refreshNotifications (configureNativeFetcherIfReady) and handleCapacitorPushNotificationReceived for data.type WAKEUP_PING; invoke from Capacitor pushNotificationReceived without UI.
This commit is contained in:
@@ -12,8 +12,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Capacitor } from "@capacitor/core";
|
import { Capacitor } from "@capacitor/core";
|
||||||
|
import type { PushNotificationSchema } from "@capacitor/push-notifications";
|
||||||
import { DailyNotification } from "@/plugins/DailyNotificationPlugin";
|
import { DailyNotification } from "@/plugins/DailyNotificationPlugin";
|
||||||
import { REMINDER_ID_DAILY_REMINDER } from "./reminderIds";
|
import { REMINDER_ID_DAILY_REMINDER } from "./reminderIds";
|
||||||
|
import { configureNativeFetcherIfReady } from "./nativeFetcherConfig";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extended type for DailyNotification that includes the actual Swift implementation
|
* Extended type for DailyNotification that includes the actual Swift implementation
|
||||||
@@ -542,3 +544,25 @@ export class NativeNotificationService implements NotificationServiceInterface {
|
|||||||
return this.platformName;
|
return this.platformName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-applies native API fetcher credentials (JWT pool, active DID) so background
|
||||||
|
* notification workers can run. No UI; safe from push handlers while backgrounded.
|
||||||
|
*/
|
||||||
|
export async function refreshNotifications(): Promise<void> {
|
||||||
|
if (!Capacitor.isNativePlatform()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await configureNativeFetcherIfReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Silent FCM/APNs data push: refresh native notification pipeline when requested by backend.
|
||||||
|
*/
|
||||||
|
export async function handleCapacitorPushNotificationReceived(
|
||||||
|
notification: PushNotificationSchema,
|
||||||
|
): Promise<void> {
|
||||||
|
if (notification.data?.type === "WAKEUP_PING") {
|
||||||
|
await refreshNotifications();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
onMessage,
|
onMessage,
|
||||||
} from "firebase/messaging";
|
} from "firebase/messaging";
|
||||||
import { logger } from "@/utils/logger";
|
import { logger } from "@/utils/logger";
|
||||||
|
import { handleCapacitorPushNotificationReceived } from "./NativeNotificationService";
|
||||||
import { registerToken } from "./NotificationService";
|
import { registerToken } from "./NotificationService";
|
||||||
|
|
||||||
const LOG = "[FirebaseMessaging]";
|
const LOG = "[FirebaseMessaging]";
|
||||||
@@ -167,6 +168,14 @@ async function initializeNativePushAndFirebaseMessagingImpl(): Promise<void> {
|
|||||||
"pushNotificationReceived",
|
"pushNotificationReceived",
|
||||||
(notification) => {
|
(notification) => {
|
||||||
logger.debug(`${LOG} pushNotificationReceived`, notification);
|
logger.debug(`${LOG} pushNotificationReceived`, notification);
|
||||||
|
void handleCapacitorPushNotificationReceived(notification).catch(
|
||||||
|
(err) => {
|
||||||
|
logger.warn(
|
||||||
|
`${LOG} handleCapacitorPushNotificationReceived failed`,
|
||||||
|
err,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user