From 712fe5b2179097feb5a14b171aee316680300744 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 27 Aug 2026 19:19:01 +0100 Subject: [PATCH] Implement a hook allowing enterprise modules to perform actions on startup Add an interface `io.element.android.features.enterprise.api.AppStartupHook`, which can be implemented in the enterprise build to perform certain actions on startup. It's a bit of a kludge for now since it doesn't block the rest of the app from proceeding, but it will serve our purposes for now. --- .../io/element/android/x/MainActivity.kt | 7 +++++++ .../io/element/android/x/di/AppBindings.kt | 5 +++++ .../features/enterprise/api/AppStartupHook.kt | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/AppStartupHook.kt 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) +}