mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-05 10:49:26 +02:00
Cache suspended apps
This commit is contained in:
parent
303baca7a4
commit
9731350423
1 changed files with 7 additions and 1 deletions
|
@ -40,6 +40,7 @@ class SuspendAppsLogic(private val appLogic: AppLogic): Observer {
|
|||
private var batteryStatus = appLogic.platformIntegration.getBatteryStatus()
|
||||
private val pendingSync = AtomicBoolean(true)
|
||||
private val executor = Executors.newSingleThreadExecutor()
|
||||
private var lastSuspendedApps: List<String>? = null
|
||||
|
||||
private val backgroundRunnable = Runnable {
|
||||
while (pendingSync.getAndSet(false)) {
|
||||
|
@ -83,6 +84,7 @@ class SuspendAppsLogic(private val appLogic: AppLogic): Observer {
|
|||
|
||||
if (!enableBlocking) {
|
||||
appLogic.platformIntegration.stopSuspendingForAllApps()
|
||||
lastSuspendedApps = emptyList()
|
||||
|
||||
lastAllowedCategoryList = emptySet()
|
||||
lastCategoryApps = emptyList()
|
||||
|
@ -200,14 +202,18 @@ class SuspendAppsLogic(private val appLogic: AppLogic): Observer {
|
|||
}
|
||||
|
||||
private fun applySuspendedApps(packageNames: List<String>) {
|
||||
if (packageNames.isEmpty()) {
|
||||
if (packageNames == lastSuspendedApps) {
|
||||
// nothing to do
|
||||
} else if (packageNames.isEmpty()) {
|
||||
appLogic.platformIntegration.stopSuspendingForAllApps()
|
||||
lastSuspendedApps = emptyList()
|
||||
} else {
|
||||
val allApps = appLogic.platformIntegration.getLocalAppPackageNames()
|
||||
val appsToNotBlock = allApps.subtract(packageNames)
|
||||
|
||||
appLogic.platformIntegration.setSuspendedApps(appsToNotBlock.toList(), false)
|
||||
appLogic.platformIntegration.setSuspendedApps(packageNames, true)
|
||||
lastSuspendedApps = packageNames
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue