diff --git a/app.json b/app.json index 521923b..5299a5b 100644 --- a/app.json +++ b/app.json @@ -32,7 +32,8 @@ "BLUETOOTH", "BLUETOOTH_ADMIN", "BLUETOOTH_SCAN", - "BLUETOOTH_CONNECT" + "BLUETOOTH_CONNECT", + "REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" ] }, "web": { diff --git a/src/services/batteryOptimization.ts b/src/services/batteryOptimization.ts index ad1dc9a..bf408b8 100644 --- a/src/services/batteryOptimization.ts +++ b/src/services/batteryOptimization.ts @@ -4,6 +4,10 @@ import AsyncStorage from '@react-native-async-storage/async-storage'; const PROMPT_SHOWN_KEY = 'batteryOptPromptShown'; +export async function resetBatteryOptPrompt(): Promise { + await AsyncStorage.removeItem(PROMPT_SHOWN_KEY); +} + export async function promptBatteryOptimizationIfNeeded(): Promise { if (Platform.OS !== 'android') return; @@ -18,16 +22,23 @@ export async function promptBatteryOptimizationIfNeeded(): Promise { [ { text: 'Open settings', - onPress: () => - IntentLauncher.startActivityAsync( - IntentLauncher.ActivityAction.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, - { data: 'package:com.bincio.rec' }, - ).catch(() => + onPress: async () => { + try { + await IntentLauncher.startActivityAsync( + IntentLauncher.ActivityAction.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, + { data: 'package:com.bincio.rec' }, + ); + } catch { // Fallback: some OEMs don't support the direct intent — open the general page - IntentLauncher.startActivityAsync( - IntentLauncher.ActivityAction.IGNORE_BATTERY_OPTIMIZATION_SETTINGS, - ), - ), + try { + await IntentLauncher.startActivityAsync( + IntentLauncher.ActivityAction.IGNORE_BATTERY_OPTIMIZATION_SETTINGS, + ); + } catch { + // Nothing more we can do + } + } + }, }, { text: 'Later', style: 'cancel' }, ],