fix: bettery optimization glitch
This commit is contained in:
parent
774f7dc163
commit
b4b7441bac
1 changed files with 16 additions and 12 deletions
|
@ -9,10 +9,6 @@ import {
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import { Title } from "react-native-paper";
|
import { Title } from "react-native-paper";
|
||||||
import { Ionicons, Entypo } from "@expo/vector-icons";
|
import { Ionicons, Entypo } from "@expo/vector-icons";
|
||||||
import {
|
|
||||||
RequestDisableOptimization,
|
|
||||||
BatteryOptEnabled,
|
|
||||||
} from "react-native-battery-optimization-check";
|
|
||||||
import {
|
import {
|
||||||
permissionsActions,
|
permissionsActions,
|
||||||
usePermissionsState,
|
usePermissionsState,
|
||||||
|
@ -20,6 +16,10 @@ import {
|
||||||
} from "~/stores";
|
} from "~/stores";
|
||||||
import { createStyles, useTheme } from "~/theme";
|
import { createStyles, useTheme } from "~/theme";
|
||||||
import openSettings from "~/lib/native/openSettings";
|
import openSettings from "~/lib/native/openSettings";
|
||||||
|
import {
|
||||||
|
RequestDisableOptimization,
|
||||||
|
BatteryOptEnabled,
|
||||||
|
} from "react-native-battery-optimization-check";
|
||||||
|
|
||||||
import requestPermissionLocationBackground from "~/permissions/requestPermissionLocationBackground";
|
import requestPermissionLocationBackground from "~/permissions/requestPermissionLocationBackground";
|
||||||
import requestPermissionMotion from "~/permissions/requestPermissionMotion";
|
import requestPermissionMotion from "~/permissions/requestPermissionMotion";
|
||||||
|
@ -73,6 +73,8 @@ const HeroMode = () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setBatteryOptInProgress(true);
|
setBatteryOptInProgress(true);
|
||||||
|
|
||||||
|
// Check if battery optimization is enabled
|
||||||
const isEnabled = await BatteryOptEnabled();
|
const isEnabled = await BatteryOptEnabled();
|
||||||
setBatteryOptimizationEnabled(isEnabled);
|
setBatteryOptimizationEnabled(isEnabled);
|
||||||
|
|
||||||
|
@ -80,11 +82,12 @@ const HeroMode = () => {
|
||||||
console.log(
|
console.log(
|
||||||
"Battery optimization is enabled, requesting to disable...",
|
"Battery optimization is enabled, requesting to disable...",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Request to disable battery optimization (opens Android Settings)
|
||||||
RequestDisableOptimization();
|
RequestDisableOptimization();
|
||||||
setBatteryOptAttempted(true);
|
setBatteryOptAttempted(true);
|
||||||
|
|
||||||
// Give some time for the user to interact with the system dialog
|
// Return false to indicate user needs to complete action in Settings
|
||||||
// We'll check the status again in the retry flow
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
console.log("Battery optimization already disabled");
|
console.log("Battery optimization already disabled");
|
||||||
|
@ -106,20 +109,21 @@ const HeroMode = () => {
|
||||||
// Don't change step immediately to avoid race conditions
|
// Don't change step immediately to avoid race conditions
|
||||||
console.log("Starting permission requests...");
|
console.log("Starting permission requests...");
|
||||||
|
|
||||||
// Request motion permission first
|
// Request battery optimization FIRST (opens Android Settings)
|
||||||
|
// This prevents the bubbling issue by handling Settings-based permissions before in-app dialogs
|
||||||
|
const batteryOptDisabled = await handleBatteryOptimization();
|
||||||
|
console.log("Battery optimization disabled:", batteryOptDisabled);
|
||||||
|
|
||||||
|
// Request motion permission second
|
||||||
const motionGranted = await requestPermissionMotion.requestPermission();
|
const motionGranted = await requestPermissionMotion.requestPermission();
|
||||||
permissionsActions.setMotion(motionGranted);
|
permissionsActions.setMotion(motionGranted);
|
||||||
console.log("Motion permission:", motionGranted);
|
console.log("Motion permission:", motionGranted);
|
||||||
|
|
||||||
// Then request background location
|
// Request background location last (after user returns from Settings if needed)
|
||||||
const locationGranted = await requestPermissionLocationBackground();
|
const locationGranted = await requestPermissionLocationBackground();
|
||||||
permissionsActions.setLocationBackground(locationGranted);
|
permissionsActions.setLocationBackground(locationGranted);
|
||||||
console.log("Location background permission:", locationGranted);
|
console.log("Location background permission:", locationGranted);
|
||||||
|
|
||||||
// Handle battery optimization separately to avoid dialog conflicts
|
|
||||||
const batteryOptDisabled = await handleBatteryOptimization();
|
|
||||||
console.log("Battery optimization disabled:", batteryOptDisabled);
|
|
||||||
|
|
||||||
// Only set step to tracking after all permission requests are complete
|
// Only set step to tracking after all permission requests are complete
|
||||||
permissionWizardActions.setCurrentStep("tracking");
|
permissionWizardActions.setCurrentStep("tracking");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue