@@ -13,6 +13,8 @@ import { fetchAttendance } from "./data/Attendance";
13
13
import { fetchEvaluation } from "./data/Evaluation" ;
14
14
import { papillonNotify } from "./Notifications" ;
15
15
16
+ import { useFlagsStore } from "@/stores/flags" ;
17
+
16
18
const notifeeEvent = async ( ) => {
17
19
const notifee = ( await import ( "@notifee/react-native" ) ) . default ;
18
20
const EventType = ( await import ( "@notifee/react-native" ) ) . EventType ;
@@ -24,10 +26,10 @@ const notifeeEvent = async () => {
24
26
switch ( type ) {
25
27
case EventType . ACTION_PRESS :
26
28
console . log ( `[Notifee] Action press: ${ pressAction ?. id } ` ) ;
27
-
29
+ break ;
28
30
case EventType . DISMISSED :
29
31
let badgeCount = await notifee . getBadgeCount ( ) ;
30
- badgeCount -- ;
32
+ badgeCount = Math . max ( badgeCount - 1 , 0 ) ;
31
33
await notifee . setBadgeCount ( badgeCount ) ;
32
34
break ;
33
35
}
@@ -40,10 +42,10 @@ const notifeeEvent = async () => {
40
42
switch ( type ) {
41
43
case EventType . ACTION_PRESS :
42
44
console . log ( `[Notifee] Action press: ${ pressAction ?. id } ` ) ;
43
-
45
+ break ;
44
46
case EventType . DISMISSED :
45
47
let badgeCount = await notifee . getBadgeCount ( ) ;
46
- badgeCount -- ;
48
+ badgeCount = Math . max ( badgeCount - 1 , 0 ) ;
47
49
await notifee . setBadgeCount ( badgeCount ) ;
48
50
break ;
49
51
}
@@ -55,6 +57,12 @@ if (!isExpoGo()) notifeeEvent();
55
57
let isBackgroundFetchRunning = false ;
56
58
57
59
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
+
58
66
const notifee = ( await import ( "@notifee/react-native" ) ) . default ;
59
67
60
68
if ( isBackgroundFetchRunning ) {
@@ -132,6 +140,17 @@ const setBackgroundFetch = async () =>
132
140
} ) ;
133
141
134
142
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
+
135
154
const isRegistered = await TaskManager . isTaskRegisteredAsync (
136
155
"background-fetch"
137
156
) ;
@@ -161,4 +180,4 @@ const registerBackgroundTasks = async () => {
161
180
) ;
162
181
} ;
163
182
164
- export { registerBackgroundTasks , unsetBackgroundFetch } ;
183
+ export { registerBackgroundTasks , unsetBackgroundFetch } ;
0 commit comments