diff --git a/composeApp/src/androidMain/kotlin/org/ooni/probe/background/AppWorkerManager.kt b/composeApp/src/androidMain/kotlin/org/ooni/probe/background/AppWorkerManager.kt index be6a9963..6e2f98ca 100644 --- a/composeApp/src/androidMain/kotlin/org/ooni/probe/background/AppWorkerManager.kt +++ b/composeApp/src/androidMain/kotlin/org/ooni/probe/background/AppWorkerManager.kt @@ -62,6 +62,7 @@ class AppWorkerManager( suspend fun configureDescriptorAutoUpdate(): Boolean { return withContext(backgroundDispatcher) { val request = PeriodicWorkRequestBuilder(1, TimeUnit.DAYS) + .setInitialDelay(1, TimeUnit.DAYS) // avoid immediate start .build() workManager.enqueueUniquePeriodicWork( DescriptorUpdateWorker.AutoUpdateWorkerName, diff --git a/composeApp/src/androidMain/kotlin/org/ooni/probe/background/DescriptorUpdateWorker.kt b/composeApp/src/androidMain/kotlin/org/ooni/probe/background/DescriptorUpdateWorker.kt index afac9b82..c18ee2b1 100644 --- a/composeApp/src/androidMain/kotlin/org/ooni/probe/background/DescriptorUpdateWorker.kt +++ b/composeApp/src/androidMain/kotlin/org/ooni/probe/background/DescriptorUpdateWorker.kt @@ -12,7 +12,6 @@ import androidx.work.ForegroundInfo import androidx.work.WorkerParameters import androidx.work.workDataOf import co.touchlab.kermit.Logger -import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.first import kotlinx.serialization.encodeToString import ooniprobe.composeapp.generated.resources.Dashboard_Running_Running @@ -41,19 +40,21 @@ class DescriptorUpdateWorker( } override suspend fun doWork(): Result { - return coroutineScope { - val descriptors = getDescriptors() ?: return@coroutineScope Result.failure() - if (descriptors.isEmpty()) return@coroutineScope Result.success(buildWorkData(descriptors.map { it.id })) - dependencies.getDescriptorUpdate.invoke(descriptors) - return@coroutineScope Result.success(buildWorkData(descriptors.map { it.id })) + val descriptors = getDescriptors() ?: return Result.failure() + if (descriptors.isEmpty()) { + Logger.i("Skipping DescriptorUpdateWorker: no descriptors to update") + return Result.success(buildWorkData(descriptors.map { it.id })) } + dependencies.getDescriptorUpdate.invoke(descriptors) + return Result.success(buildWorkData(descriptors.map { it.id })) } private suspend fun getDescriptors(): List? { val descriptorsJson = inputData.getString(DATA_KEY_DESCRIPTORS) if (descriptorsJson != null) { try { - val ids = json.decodeFromString>(descriptorsJson) + val ids = + json.decodeFromString>(descriptorsJson) return testDescriptorRepository.selectByRunIds(ids).first() } catch (e: Exception) { Logger.w("Could not start update worker: invalid configuration", e) diff --git a/composeApp/src/commonMain/debug/kotlin/org/ooni/probe/config/OrganizationConfigInterface.kt b/composeApp/src/commonMain/debug/kotlin/org/ooni/probe/config/OrganizationConfigInterface.kt index 1d38bf95..3ec9094d 100644 --- a/composeApp/src/commonMain/debug/kotlin/org/ooni/probe/config/OrganizationConfigInterface.kt +++ b/composeApp/src/commonMain/debug/kotlin/org/ooni/probe/config/OrganizationConfigInterface.kt @@ -5,13 +5,13 @@ interface OrganizationConfigInterface { val baseSoftwareName: String val ooniApiBaseUrl: String - get() = "https://api.ooni.org" + get() = "https://api.dev.ooni.io" val ooniRunDomain: String - get() = "run.ooni.org" + get() = "run.test.ooni.org" val ooniRunDashboardUrl: String - get() = "https://run.ooni.org" + get() = "https://run.test.ooni.org" val explorerUrl: String get() = "https://explorer.test.ooni.org" diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt index 884d4273..dcfcc190 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/App.kt @@ -97,6 +97,8 @@ fun App( LaunchedEffect(Unit) { dependencies.bootstrapTestDescriptors() dependencies.bootstrapPreferences() + dependencies.configureDescriptorAutoUpdate() + dependencies.fetchDescriptorUpdate(null) } LaunchedEffect(Unit) { dependencies.finishInProgressData() @@ -104,10 +106,6 @@ fun App( LaunchedEffect(Unit) { dependencies.observeAndConfigureAutoRun() } - LaunchedEffect(Unit) { - dependencies.configureDescriptorAutoUpdate() - dependencies.fetchDescriptorUpdate(null) - } LaunchedEffect(deepLink) { when (deepLink) { diff --git a/composeApp/src/dwMain/kotlin/org/ooni/probe/domain/OrganizationSettings.kt b/composeApp/src/dwMain/kotlin/org/ooni/probe/domain/OrganizationSettings.kt index 05538846..98fb257b 100644 --- a/composeApp/src/dwMain/kotlin/org/ooni/probe/domain/OrganizationSettings.kt +++ b/composeApp/src/dwMain/kotlin/org/ooni/probe/domain/OrganizationSettings.kt @@ -11,6 +11,6 @@ fun webConnectivityPreferences( return emptyList() } -fun preferenceDefaults(): List> { +fun preferenceDefaults(): List> { return emptyList() }