mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-05-25 02:52:11 +02:00
fix: Do not poll battery optimization status (#2491)
This commit is contained in:
parent
40a4317993
commit
f93085f782
@ -6,6 +6,7 @@ import android.net.Uri
|
|||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -264,9 +265,6 @@ fun DashboardScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val showBatteryOptimizationsWarning by vm.showBatteryOptimizationsWarningFlow.collectAsStateWithLifecycle(
|
|
||||||
false
|
|
||||||
)
|
|
||||||
Notifications(
|
Notifications(
|
||||||
if (!Aapt.supportsDevice()) {
|
if (!Aapt.supportsDevice()) {
|
||||||
{
|
{
|
||||||
@ -278,16 +276,23 @@ fun DashboardScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else null,
|
} else null,
|
||||||
if (showBatteryOptimizationsWarning) {
|
if (vm.showBatteryOptimizationsWarning) {
|
||||||
{
|
{
|
||||||
|
val batteryOptimizationsLauncher =
|
||||||
|
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
|
vm.updateBatteryOptimizationsWarning()
|
||||||
|
}
|
||||||
NotificationCard(
|
NotificationCard(
|
||||||
isWarning = true,
|
isWarning = true,
|
||||||
icon = Icons.Default.BatteryAlert,
|
icon = Icons.Default.BatteryAlert,
|
||||||
text = stringResource(R.string.battery_optimization_notification),
|
text = stringResource(R.string.battery_optimization_notification),
|
||||||
onClick = {
|
onClick = {
|
||||||
androidContext.startActivity(Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
|
batteryOptimizationsLauncher.launch(
|
||||||
data = Uri.parse("package:${androidContext.packageName}")
|
Intent(
|
||||||
})
|
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||||
|
Uri.fromParts("package", androidContext.packageName, null)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,7 @@ import app.revanced.manager.network.api.ReVancedAPI
|
|||||||
import app.revanced.manager.util.PM
|
import app.revanced.manager.util.PM
|
||||||
import app.revanced.manager.util.toast
|
import app.revanced.manager.util.toast
|
||||||
import app.revanced.manager.util.uiSafe
|
import app.revanced.manager.util.uiSafe
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.flow.flow
|
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@ -58,19 +56,13 @@ class DashboardViewModel(
|
|||||||
|
|
||||||
var updatedManagerVersion: String? by mutableStateOf(null)
|
var updatedManagerVersion: String? by mutableStateOf(null)
|
||||||
private set
|
private set
|
||||||
val showBatteryOptimizationsWarningFlow = flow {
|
var showBatteryOptimizationsWarning by mutableStateOf(false)
|
||||||
while (true) {
|
private set
|
||||||
// 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 {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
checkForManagerUpdates()
|
checkForManagerUpdates()
|
||||||
|
updateBatteryOptimizationsWarning()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +82,10 @@ class DashboardViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateBatteryOptimizationsWarning() {
|
||||||
|
showBatteryOptimizationsWarning = !powerManager.isIgnoringBatteryOptimizations(app.packageName)
|
||||||
|
}
|
||||||
|
|
||||||
fun setShowManagerUpdateDialogOnLaunch(value: Boolean) {
|
fun setShowManagerUpdateDialogOnLaunch(value: Boolean) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
prefs.showManagerUpdateDialogOnLaunch.update(value)
|
prefs.showManagerUpdateDialogOnLaunch.update(value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user