mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
Make offline flavor not require ConnectivityService
- Guard `startService()` in Amber.kt to skip service startup for the offline flavor (the manifest doesn't declare ConnectivityService, so attempts to start it would fail) - Move the periodic DB maintenance tasks (expiring permissions and deleting stale application entries) from ConnectivityService's timer into ClearLogsWorker, which already runs daily via WorkManager for both flavors https://claude.ai/code/session_014Zqb1AEPPF2RrzmEyPnmei
This commit is contained in:
@@ -339,6 +339,7 @@ class Amber :
|
||||
}
|
||||
|
||||
fun startService() {
|
||||
if (BuildFlavorChecker.isOfflineFlavor()) return
|
||||
try {
|
||||
Log.d(TAG, "Starting ConnectivityService")
|
||||
val operation = PendingIntent.getForegroundService(
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.work.CoroutineWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import com.greenart7c3.nostrsigner.Amber
|
||||
import com.greenart7c3.nostrsigner.LocalPreferences
|
||||
import com.greenart7c3.nostrsigner.database.LogEntity
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils.ONE_WEEK
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
@@ -15,8 +16,10 @@ class ClearLogsWorker(appContext: Context, workerParams: WorkerParameters) : Cor
|
||||
override suspend fun doWork(): Result {
|
||||
LocalPreferences.allSavedAccounts(Amber.instance).forEach {
|
||||
try {
|
||||
val oneWeek = System.currentTimeMillis() - (ONE_WEEK * 1000L)
|
||||
val now = System.currentTimeMillis()
|
||||
val oneWeek = now - (ONE_WEEK * 1000L)
|
||||
val oneWeekAgo = TimeUtils.oneWeekAgo()
|
||||
|
||||
val historyDatabase = Amber.instance.getHistoryDatabase(it.npub)
|
||||
val deletedHistory = historyDatabase.dao().deleteOldHistory(oneWeekAgo)
|
||||
if (deletedHistory > 0) {
|
||||
@@ -28,9 +31,24 @@ class ClearLogsWorker(appContext: Context, workerParams: WorkerParameters) : Cor
|
||||
if (deletedLogs > 0) {
|
||||
Log.d(Amber.TAG, "Deleted $deletedLogs old log entries")
|
||||
}
|
||||
|
||||
val database = Amber.instance.getDatabase(it.npub)
|
||||
database.dao().updateExpiredPermissions(TimeUtils.now())
|
||||
val deleted = database.dao().deleteOldApplications(now / 1000)
|
||||
if (deleted > 0) {
|
||||
logDatabase.dao().insertLog(
|
||||
LogEntity(
|
||||
id = 0,
|
||||
url = "",
|
||||
type = "deleteApplications",
|
||||
message = "Deleted $deleted expired applications",
|
||||
time = now,
|
||||
),
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
if (e is CancellationException) throw e
|
||||
Log.e(Amber.TAG, "Error deleting old log entries", e)
|
||||
Log.e(Amber.TAG, "Error in ClearLogsWorker", e)
|
||||
}
|
||||
}
|
||||
return Result.success()
|
||||
|
||||
Reference in New Issue
Block a user