Make SettingsModule.ignoringBattery async
This commit is contained in:
parent
5f2327de31
commit
fd09758ccf
|
@ -28,6 +28,7 @@ export default function EditWeight() {
|
|||
const { params } = useRoute<RouteProp<StackParams, "EditWeight">>();
|
||||
const { weight } = params;
|
||||
const { navigate } = useNavigation<NavigationProp<DrawerParams>>();
|
||||
const { navigate: stackNavigate, goBack } = useNavigation<NavigationProp<StackParams>>();
|
||||
const [settings, setSettings] = useState<Settings>({} as Settings);
|
||||
const [value, setValue] = useState(weight.value?.toString());
|
||||
const [unit, setUnit] = useState(weight.unit);
|
||||
|
@ -58,7 +59,8 @@ export default function EditWeight() {
|
|||
|
||||
await weightRepo.save(newWeight);
|
||||
if (settings.notify) await checkWeekly();
|
||||
navigate("Weight");
|
||||
goBack();
|
||||
stackNavigate("ViewWeightGraph");
|
||||
};
|
||||
|
||||
const checkWeekly = async () => {
|
||||
|
|
|
@ -71,7 +71,7 @@ export default function SettingsPage() {
|
|||
} = useAppTheme();
|
||||
|
||||
useEffect(() => {
|
||||
NativeModules.SettingsModule.ignoringBattery(setIgnoring);
|
||||
NativeModules.SettingsModule.ignoringBattery().then(setIgnoring);
|
||||
NativeModules.SettingsModule.is24().then((is24: boolean) => {
|
||||
console.log(`${SettingsPage.name}.focus:`, { is24 });
|
||||
if (is24) setFormatOptions(twentyFours);
|
||||
|
|
|
@ -21,13 +21,13 @@ class SettingsModule constructor(context: ReactApplicationContext?) :
|
|||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
@ReactMethod
|
||||
fun ignoringBattery(callback: Callback) {
|
||||
fun ignoringBattery(promise: Promise) {
|
||||
val packageName = reactApplicationContext.packageName
|
||||
val pm = reactApplicationContext.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
callback.invoke(pm.isIgnoringBatteryOptimizations(packageName))
|
||||
promise.resolve(pm.isIgnoringBatteryOptimizations(packageName))
|
||||
} else {
|
||||
callback.invoke(true)
|
||||
promise.resolve(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue