fix: remove battery optimization notification if user grants the permission

This commit is contained in:
Ax333l 2024-12-23 14:39:57 +01:00
parent 5d3a81f4b9
commit cf3866f892
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
2 changed files with 14 additions and 7 deletions

View File

@ -109,7 +109,6 @@ fun DashboardScreen(
)
}
val context = LocalContext.current
var showAndroid11Dialog by rememberSaveable { mutableStateOf(false) }
val installAppsPermissionLauncher =
rememberLauncherForActivityResult(RequestInstallAppsContract) { granted ->
@ -121,7 +120,7 @@ fun DashboardScreen(
showAndroid11Dialog = false
},
onContinue = {
installAppsPermissionLauncher.launch(context.packageName)
installAppsPermissionLauncher.launch(androidContext.packageName)
}
)
@ -239,6 +238,7 @@ fun DashboardScreen(
}
}
val showBatteryOptimizationsWarning by vm.showBatteryOptimizationsWarningFlow.collectAsStateWithLifecycle(false)
Notifications(
if (!Aapt.supportsDevice()) {
{
@ -250,7 +250,7 @@ fun DashboardScreen(
)
}
} else null,
if (vm.showBatteryOptimizationsWarning) {
if (showBatteryOptimizationsWarning) {
{
NotificationCard(
isWarning = true,

View File

@ -24,7 +24,9 @@ import app.revanced.manager.network.api.ReVancedAPI
import app.revanced.manager.util.PM
import app.revanced.manager.util.toast
import app.revanced.manager.util.uiSafe
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
@ -56,14 +58,19 @@ class DashboardViewModel(
var updatedManagerVersion: String? by mutableStateOf(null)
private set
var showBatteryOptimizationsWarning by mutableStateOf(false)
private set
val showBatteryOptimizationsWarningFlow = flow {
while (true) {
// There is no callback for this, so we have to poll it.
val result = !powerManager.isIgnoringBatteryOptimizations(app.packageName)
emit(result)
if (!result) return@flow
delay(500L)
}
}
init {
viewModelScope.launch {
checkForManagerUpdates()
showBatteryOptimizationsWarning =
!powerManager.isIgnoringBatteryOptimizations(app.packageName)
}
}