diff --git a/app/src/main/kotlin/io/element/android/x/ElementXApplication.kt b/app/src/main/kotlin/io/element/android/x/ElementXApplication.kt index 38952b144f..a3712ebbf6 100644 --- a/app/src/main/kotlin/io/element/android/x/ElementXApplication.kt +++ b/app/src/main/kotlin/io/element/android/x/ElementXApplication.kt @@ -13,10 +13,14 @@ import androidx.compose.material3.ComposeMaterial3Flags.isAnchoredDraggableCompo import androidx.compose.material3.ExperimentalMaterial3Api import androidx.startup.AppInitializer import androidx.work.Configuration +import dev.zacsweers.metro.Inject import dev.zacsweers.metro.createGraphFactory +import io.element.android.libraries.architecture.bindings import io.element.android.libraries.di.DependencyInjectionGraphOwner +import io.element.android.libraries.matrix.api.SdkMetadata import io.element.android.libraries.workmanager.api.di.MetroWorkerFactory import io.element.android.x.di.AppGraph +import io.element.android.x.di.ApplicationBindings import io.element.android.x.info.logApplicationInfo import io.element.android.x.initializer.CacheCleanerInitializer import io.element.android.x.initializer.CrashInitializer @@ -29,6 +33,8 @@ class ElementXApplication : Application(), DependencyInjectionGraphOwner, Config .setWorkerFactory(MetroWorkerFactory(graph.workerProviders)) .build() + @Inject lateinit var sdkMetadata: SdkMetadata + @OptIn(ExperimentalMaterial3Api::class) override fun onCreate() { super.onCreate() @@ -38,7 +44,8 @@ class ElementXApplication : Application(), DependencyInjectionGraphOwner, Config initializeComponent(CacheCleanerInitializer::class.java) } - logApplicationInfo(this) + bindings().inject(this) + logApplicationInfo(this, sdkMetadata.sdkGitSha) // Disable the strict offset check for anchored draggable components, as it can cause issues with bottom sheets. // Remove once https://issuetracker.google.com/issues/477038695 is fixed. diff --git a/app/src/main/kotlin/io/element/android/x/di/ApplicationBindings.kt b/app/src/main/kotlin/io/element/android/x/di/ApplicationBindings.kt new file mode 100644 index 0000000000..3bc2445f58 --- /dev/null +++ b/app/src/main/kotlin/io/element/android/x/di/ApplicationBindings.kt @@ -0,0 +1,17 @@ +/* + * 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.x.di + +import dev.zacsweers.metro.AppScope +import dev.zacsweers.metro.ContributesTo +import io.element.android.x.ElementXApplication + +@ContributesTo(AppScope::class) +interface ApplicationBindings { + fun inject(application: ElementXApplication) +} diff --git a/app/src/main/kotlin/io/element/android/x/info/Logs.kt b/app/src/main/kotlin/io/element/android/x/info/Logs.kt index 2b66fef55e..a9c6f6cee6 100644 --- a/app/src/main/kotlin/io/element/android/x/info/Logs.kt +++ b/app/src/main/kotlin/io/element/android/x/info/Logs.kt @@ -10,32 +10,22 @@ package io.element.android.x.info import android.content.Context import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest +import io.element.android.libraries.core.log.logger.wrapInBox import io.element.android.x.BuildConfig import timber.log.Timber import java.text.SimpleDateFormat import java.util.Date import java.util.Locale -fun logApplicationInfo(context: Context) { - val appVersion = buildString { - append(BuildConfig.VERSION_NAME) - append(" (") - append(context.getVersionCodeFromManifest()) - append(") - ") - append(BuildConfig.BUILD_TYPE) - append(" / ") - append(BuildConfig.FLAVOR) - } - // TODO Get SDK version somehow - val sdkVersion = "SDK VERSION (TODO)" +fun logApplicationInfo(context: Context, sdkGitSha: String) { + val appVersion = "${BuildConfig.VERSION_NAME} (${context.getVersionCodeFromManifest()}) - ${BuildConfig.BUILD_TYPE} / ${BuildConfig.FLAVOR}" val date = SimpleDateFormat("MM-dd HH:mm:ss.SSSZ", Locale.US).format(Date()) - - Timber.d("----------------------------------------------------------------") - Timber.d("----------------------------------------------------------------") - Timber.d(" Application version: $appVersion") - Timber.d(" Git SHA: ${BuildConfig.GIT_REVISION}") - Timber.d(" SDK version: $sdkVersion") - Timber.d(" Local time: $date") - Timber.d("----------------------------------------------------------------") - Timber.d("----------------------------------------------------------------\n\n\n\n") + listOf( + " Application version: $appVersion", + " Element X: https://github.com/element-hq/element-x-android/commit/${BuildConfig.GIT_REVISION}", + " SDK : https://github.com/matrix-org/matrix-rust-sdk/commit/$sdkGitSha", + " Local time: $date", + ) + .wrapInBox(minBoxInsideWidth = 80) + .forEach { Timber.d(it) } } diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/log/logger/BoxWrapper.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/log/logger/BoxWrapper.kt new file mode 100644 index 0000000000..ed69332b72 --- /dev/null +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/log/logger/BoxWrapper.kt @@ -0,0 +1,31 @@ +/* + * 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.libraries.core.log.logger + +import kotlin.math.max + +/** + * Wraps a list of strings in a box with borders. + * Allow to print pretty logs. + * + * @param minBoxInsideWidth The minimum width of the box inside, default is 80. + * @return A list of strings representing the boxed lines. + */ +fun List.wrapInBox( + minBoxInsideWidth: Int = 80, +): List { + val maxLength = maxOfOrNull { it.length } ?: 0 + val boxWidth = max(maxLength, minBoxInsideWidth) + 4 + val topBorder = "┌" + "─".repeat(boxWidth - 2) + "┐" + val bottomBorder = "└" + "─".repeat(boxWidth - 2) + "┘" + val boxedLines = map { line -> + val padding = " ".repeat(max(0, boxWidth - line.length - 4)) + "│ $line$padding │" + } + return listOf(topBorder) + boxedLines + listOf(bottomBorder) +}