Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.

Commit 2943744

Browse files
authored
feat: ajout de la gestion des erreurs et de la reconnexion pour le compte Pronote désactivées par des flags (#927)
2 parents 2831044 + 9a31fb9 commit 2943744

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/background/BackgroundTasks.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { fetchAttendance } from "./data/Attendance";
1313
import { fetchEvaluation } from "./data/Evaluation";
1414
import { papillonNotify } from "./Notifications";
1515

16+
import { useFlagsStore } from "@/stores/flags";
17+
1618
const notifeeEvent = async () => {
1719
const notifee = (await import("@notifee/react-native")).default;
1820
const EventType = (await import("@notifee/react-native")).EventType;
@@ -24,10 +26,10 @@ const notifeeEvent = async () => {
2426
switch (type) {
2527
case EventType.ACTION_PRESS:
2628
console.log(`[Notifee] Action press: ${pressAction?.id}`);
27-
29+
break;
2830
case EventType.DISMISSED:
2931
let badgeCount = await notifee.getBadgeCount();
30-
badgeCount--;
32+
badgeCount = Math.max(badgeCount - 1, 0);
3133
await notifee.setBadgeCount(badgeCount);
3234
break;
3335
}
@@ -40,10 +42,10 @@ const notifeeEvent = async () => {
4042
switch (type) {
4143
case EventType.ACTION_PRESS:
4244
console.log(`[Notifee] Action press: ${pressAction?.id}`);
43-
45+
break;
4446
case EventType.DISMISSED:
4547
let badgeCount = await notifee.getBadgeCount();
46-
badgeCount--;
48+
badgeCount = Math.max(badgeCount - 1, 0);
4749
await notifee.setBadgeCount(badgeCount);
4850
break;
4951
}
@@ -55,6 +57,12 @@ if (!isExpoGo()) notifeeEvent();
5557
let isBackgroundFetchRunning = false;
5658

5759
const backgroundFetch = async () => {
60+
const disableBackgroundTasks = useFlagsStore.getState().defined("disablebackgroundtasks");
61+
if (disableBackgroundTasks) {
62+
warn("⚠️ Background fetch disabled by flags.", "BACKGROUND");
63+
return BackgroundFetchResult.NoData;
64+
}
65+
5866
const notifee = (await import("@notifee/react-native")).default;
5967

6068
if (isBackgroundFetchRunning) {
@@ -132,6 +140,17 @@ const setBackgroundFetch = async () =>
132140
});
133141

134142
const registerBackgroundTasks = async () => {
143+
const disableBackgroundTasks = useFlagsStore.getState().defined("disablebackgroundtasks");
144+
if (disableBackgroundTasks) {
145+
warn("⚠️ Background tasks registration skipped because disabled by flag.", "BACKGROUND");
146+
await unsetBackgroundFetch()
147+
.then(() => log("✅ Background task unregistered (flag)", "BACKGROUND"))
148+
.catch((ERRfatal) =>
149+
error(`❌ Failed to unregister background task (flag): ${ERRfatal}`, "BACKGROUND")
150+
);
151+
return;
152+
}
153+
135154
const isRegistered = await TaskManager.isTaskRegisteredAsync(
136155
"background-fetch"
137156
);
@@ -161,4 +180,4 @@ const registerBackgroundTasks = async () => {
161180
);
162181
};
163182

164-
export { registerBackgroundTasks, unsetBackgroundFetch };
183+
export { registerBackgroundTasks, unsetBackgroundFetch };

0 commit comments

Comments
 (0)