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:
Jose Olarte III
2026-05-06 16:04:01 +08:00
parent c523c14d96
commit 35a1b92559
2 changed files with 33 additions and 0 deletions

View File

@@ -12,8 +12,10 @@
*/
import { Capacitor } from "@capacitor/core";
import type { PushNotificationSchema } from "@capacitor/push-notifications";
import { DailyNotification } from "@/plugins/DailyNotificationPlugin";
import { REMINDER_ID_DAILY_REMINDER } from "./reminderIds";
import { configureNativeFetcherIfReady } from "./nativeFetcherConfig";
/**
* Extended type for DailyNotification that includes the actual Swift implementation
@@ -542,3 +544,25 @@ export class NativeNotificationService implements NotificationServiceInterface {
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();
}
}

View File

@@ -21,6 +21,7 @@ import {
onMessage,
} from "firebase/messaging";
import { logger } from "@/utils/logger";
import { handleCapacitorPushNotificationReceived } from "./NativeNotificationService";
import { registerToken } from "./NotificationService";
const LOG = "[FirebaseMessaging]";
@@ -167,6 +168,14 @@ async function initializeNativePushAndFirebaseMessagingImpl(): Promise<void> {
"pushNotificationReceived",
(notification) => {
logger.debug(`${LOG} pushNotificationReceived`, notification);
void handleCapacitorPushNotificationReceived(notification).catch(
(err) => {
logger.warn(
`${LOG} handleCapacitorPushNotificationReceived failed`,
err,
);
},
);
},
);