Fix build with telemetry

This commit is contained in:
Cuong-Tran 2025-03-24 01:49:50 +07:00
parent d8132eba1a
commit 06170a9d13
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
6 changed files with 14 additions and 11 deletions

View file

@ -47,6 +47,7 @@ jobs:
distribution: temurin
- name: Write google-services.json
if: github.repository == github.event.pull_request.head.repo.full_name
uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 # v1.3
with:
path: app/google-services.json
@ -54,6 +55,7 @@ jobs:
write-mode: overwrite
- name: Write client_secrets.json
if: github.repository == github.event.pull_request.head.repo.full_name
uses: DamianReeves/write-file-action@6929a9a6d1807689191dcc8bbe62b54d70a32b42 # v1.3
with:
path: app/src/main/assets/client_secrets.json

View file

@ -65,6 +65,7 @@ import eu.kanade.tachiyomi.util.system.WebViewUtil
import eu.kanade.tachiyomi.util.system.animatorDurationScale
import eu.kanade.tachiyomi.util.system.cancelNotification
import eu.kanade.tachiyomi.util.system.isDebugBuildType
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
import eu.kanade.tachiyomi.util.system.notify
import eu.kanade.tachiyomi.util.system.telemetryIncluded
import exh.log.CrashlyticsPrinter
@ -109,7 +110,11 @@ class App : Application(), DefaultLifecycleObserver, SingletonImageLoader.Factor
override fun onCreate() {
super<Application>.onCreate()
patchInjekt()
TelemetryConfig.init(applicationContext)
TelemetryConfig.init(
applicationContext,
isPreviewBuildType,
BuildConfig.COMMIT_COUNT,
)
// KMK -->
if (isDebugBuildType) Timber.plant(Timber.DebugTree())

View file

@ -3,7 +3,6 @@ package exh.log
import com.elvishew.xlog.printer.Printer
import com.google.firebase.Firebase
import com.google.firebase.crashlytics.crashlytics
import eu.kanade.tachiyomi.util.system.isDebugBuildType
class CrashlyticsPrinter(private val logLevel: Int) : Printer {
/**
@ -17,9 +16,7 @@ class CrashlyticsPrinter(private val logLevel: Int) : Printer {
if (logLevel >= this.logLevel) {
try {
Firebase.crashlytics.log("$logLevel/$tag: $msg")
} catch (t: Throwable) {
// Crash in debug if shit like this happens
if (isDebugBuildType) throw t
} catch (_: Throwable) {
}
}
}

View file

@ -4,20 +4,18 @@ import android.content.Context
import com.google.firebase.FirebaseApp
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.util.system.isPreviewBuildType
object TelemetryConfig {
private lateinit var analytics: FirebaseAnalytics
private lateinit var crashlytics: FirebaseCrashlytics
fun init(context: Context) {
fun init(context: Context, isPreviewBuildType: Boolean, commitCount: String) {
analytics = FirebaseAnalytics.getInstance(context)
FirebaseApp.initializeApp(context)
crashlytics = FirebaseCrashlytics.getInstance()
// KMK -->
if (isPreviewBuildType) {
analytics.setUserProperty("preview_version", BuildConfig.COMMIT_COUNT)
analytics.setUserProperty("preview_version", commitCount)
}
// KMK <--
}

View file

@ -2,6 +2,7 @@ package exh.log
import com.elvishew.xlog.printer.Printer
@Suppress("UNUSED_PARAMETER", "unused")
class CrashlyticsPrinter(private val logLevel: Int) : Printer {
/**
* Print log in new line.

View file

@ -2,9 +2,9 @@ package mihon.telemetry
import android.content.Context
@Suppress("UNUSED_PARAMETER")
@Suppress("UNUSED_PARAMETER", "unused")
object TelemetryConfig {
fun init(context: Context) = Unit
fun init(context: Context, isPreviewBuildType: Boolean, commitCount: String) = Unit
fun setAnalyticsEnabled(enabled: Boolean) = Unit