diff --git a/app/src/main/kotlin/io/element/android/x/MainActivity.kt b/app/src/main/kotlin/io/element/android/x/MainActivity.kt index a882dd8769..c5551f11aa 100644 --- a/app/src/main/kotlin/io/element/android/x/MainActivity.kt +++ b/app/src/main/kotlin/io/element/android/x/MainActivity.kt @@ -61,6 +61,13 @@ class MainActivity : NodeActivity() { setContent { MainContent(appBindings) } + + val activity = this + appBindings.appStartupHooks().forEach { + lifecycleScope.launch { + it.onAppStartup(activity) + } + } } @Composable diff --git a/app/src/main/kotlin/io/element/android/x/di/AppBindings.kt b/app/src/main/kotlin/io/element/android/x/di/AppBindings.kt index 6768d0d8db..638ba0e38c 100644 --- a/app/src/main/kotlin/io/element/android/x/di/AppBindings.kt +++ b/app/src/main/kotlin/io/element/android/x/di/AppBindings.kt @@ -10,7 +10,9 @@ package io.element.android.x.di import dev.zacsweers.metro.AppScope import dev.zacsweers.metro.ContributesTo +import dev.zacsweers.metro.Multibinds import io.element.android.features.api.MigrationEntryPoint +import io.element.android.features.enterprise.api.AppStartupHook import io.element.android.features.enterprise.api.EnterpriseService import io.element.android.features.lockscreen.api.LockScreenEntryPoint import io.element.android.features.lockscreen.api.LockScreenService @@ -51,4 +53,7 @@ interface AppBindings { fun buildMeta(): BuildMeta fun sentrySdkDsn(): SentrySdkDsn? + + @Multibinds(allowEmpty = true) + fun appStartupHooks(): Set } diff --git a/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/AppStartupHook.kt b/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/AppStartupHook.kt new file mode 100644 index 0000000000..15922291f7 --- /dev/null +++ b/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/AppStartupHook.kt @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2026 Element Creations Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.features.enterprise.api + +import android.app.Activity + +/** + * A hook that is called during app startup, from the `MainActivity`. + * + * Note that the hook is run in the background: it will not block startup of the app. + */ +fun interface AppStartupHook { + /** @param activity The activity which is active while the app starts (i.e. the `MainActivity`). */ + suspend fun onAppStartup(activity: Activity) +}