mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Merge pull request #7589 from element-hq/feature/bma/logGitSha
Log the SDK git Sha at application startup
This commit is contained in:
@@ -13,10 +13,14 @@ import androidx.compose.material3.ComposeMaterial3Flags.isAnchoredDraggableCompo
|
|||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.startup.AppInitializer
|
import androidx.startup.AppInitializer
|
||||||
import androidx.work.Configuration
|
import androidx.work.Configuration
|
||||||
|
import dev.zacsweers.metro.Inject
|
||||||
import dev.zacsweers.metro.createGraphFactory
|
import dev.zacsweers.metro.createGraphFactory
|
||||||
|
import io.element.android.libraries.architecture.bindings
|
||||||
import io.element.android.libraries.di.DependencyInjectionGraphOwner
|
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.libraries.workmanager.api.di.MetroWorkerFactory
|
||||||
import io.element.android.x.di.AppGraph
|
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.info.logApplicationInfo
|
||||||
import io.element.android.x.initializer.CacheCleanerInitializer
|
import io.element.android.x.initializer.CacheCleanerInitializer
|
||||||
import io.element.android.x.initializer.CrashInitializer
|
import io.element.android.x.initializer.CrashInitializer
|
||||||
@@ -29,6 +33,8 @@ class ElementXApplication : Application(), DependencyInjectionGraphOwner, Config
|
|||||||
.setWorkerFactory(MetroWorkerFactory(graph.workerProviders))
|
.setWorkerFactory(MetroWorkerFactory(graph.workerProviders))
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
@Inject lateinit var sdkMetadata: SdkMetadata
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
@@ -38,7 +44,8 @@ class ElementXApplication : Application(), DependencyInjectionGraphOwner, Config
|
|||||||
initializeComponent(CacheCleanerInitializer::class.java)
|
initializeComponent(CacheCleanerInitializer::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
logApplicationInfo(this)
|
bindings<ApplicationBindings>().inject(this)
|
||||||
|
logApplicationInfo(this, sdkMetadata.sdkGitSha)
|
||||||
|
|
||||||
// Disable the strict offset check for anchored draggable components, as it can cause issues with bottom sheets.
|
// 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.
|
// Remove once https://issuetracker.google.com/issues/477038695 is fixed.
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -10,32 +10,22 @@ package io.element.android.x.info
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
|
import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest
|
||||||
|
import io.element.android.libraries.core.log.logger.wrapInBox
|
||||||
import io.element.android.x.BuildConfig
|
import io.element.android.x.BuildConfig
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
fun logApplicationInfo(context: Context) {
|
fun logApplicationInfo(context: Context, sdkGitSha: String) {
|
||||||
val appVersion = buildString {
|
val appVersion = "${BuildConfig.VERSION_NAME} (${context.getVersionCodeFromManifest()}) - ${BuildConfig.BUILD_TYPE} / ${BuildConfig.FLAVOR}"
|
||||||
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)"
|
|
||||||
val date = SimpleDateFormat("MM-dd HH:mm:ss.SSSZ", Locale.US).format(Date())
|
val date = SimpleDateFormat("MM-dd HH:mm:ss.SSSZ", Locale.US).format(Date())
|
||||||
|
listOf(
|
||||||
Timber.d("----------------------------------------------------------------")
|
" Application version: $appVersion",
|
||||||
Timber.d("----------------------------------------------------------------")
|
" Element X: https://github.com/element-hq/element-x-android/commit/${BuildConfig.GIT_REVISION}",
|
||||||
Timber.d(" Application version: $appVersion")
|
" SDK : https://github.com/matrix-org/matrix-rust-sdk/commit/$sdkGitSha",
|
||||||
Timber.d(" Git SHA: ${BuildConfig.GIT_REVISION}")
|
" Local time: $date",
|
||||||
Timber.d(" SDK version: $sdkVersion")
|
)
|
||||||
Timber.d(" Local time: $date")
|
.wrapInBox(minBoxInsideWidth = 80)
|
||||||
Timber.d("----------------------------------------------------------------")
|
.forEach { Timber.d(it) }
|
||||||
Timber.d("----------------------------------------------------------------\n\n\n\n")
|
|
||||||
}
|
}
|
||||||
|
|||||||
+31
@@ -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<String>.wrapInBox(
|
||||||
|
minBoxInsideWidth: Int = 80,
|
||||||
|
): List<String> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user