diff --git a/androidApp/src/google/kotlin/org/meshtastic/app/GoogleMeshUtilApplication.kt b/androidApp/src/google/kotlin/org/meshtastic/app/GoogleMeshUtilApplication.kt index 9e9970235..b3eaef210 100644 --- a/androidApp/src/google/kotlin/org/meshtastic/app/GoogleMeshUtilApplication.kt +++ b/androidApp/src/google/kotlin/org/meshtastic/app/GoogleMeshUtilApplication.kt @@ -18,6 +18,7 @@ package org.meshtastic.app import androidx.appfunctions.service.AppFunctionConfiguration import org.koin.java.KoinJavaComponent.getKoin +import org.meshtastic.app.ai.appfunctions.AppFunctionStateSync import org.meshtastic.app.ai.appfunctions.MeshtasticAppFunctions /** @@ -30,6 +31,14 @@ class GoogleMeshUtilApplication : MeshUtilApplication(), AppFunctionConfiguration.Provider { + override fun onCreate() { + super.onCreate() + // Start the AppFunctions enabled-state sync. Resolved here (after startKoin has bound + // androidContext) rather than via createdAtStart so that Koin graphs built outside a + // running app — verification tests, previews — stay lazily constructible. + getKoin().get() + } + override val appFunctionConfiguration: AppFunctionConfiguration get() = AppFunctionConfiguration.Builder() diff --git a/androidApp/src/google/kotlin/org/meshtastic/app/di/AppFunctionsModule.kt b/androidApp/src/google/kotlin/org/meshtastic/app/di/AppFunctionsModule.kt index c632f1488..a2a8659ef 100644 --- a/androidApp/src/google/kotlin/org/meshtastic/app/di/AppFunctionsModule.kt +++ b/androidApp/src/google/kotlin/org/meshtastic/app/di/AppFunctionsModule.kt @@ -32,7 +32,11 @@ class AppFunctionsModule { @Single fun meshtasticAppFunctions(provider: AiFunctionProvider): MeshtasticAppFunctions = MeshtasticAppFunctions(provider) - @Single(createdAtStart = true) + // NOT createdAtStart: eager creation needs the androidContext binding and spawns the sync + // coroutine, which breaks (and is wrong for) any Koin graph built outside a running app — + // e.g. KoinVerificationTest's typed-bootstrap check. GoogleMeshUtilApplication starts it + // explicitly at app startup instead. + @Single fun appFunctionStateSync( context: Context, prefs: AppFunctionsPrefs,