diff options
Diffstat (limited to 'app/src/main/kotlin/com')
3 files changed, 46 insertions, 33 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt index 178aa8bb..a12745bf 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt @@ -64,32 +64,8 @@ class FrostApp : Application() { Prefs.initialize(this, "${BuildConfig.APPLICATION_ID}.prefs") // if (LeakCanary.isInAnalyzerProcess(this)) return // refWatcher = LeakCanary.install(this) - if (!BuildConfig.DEBUG) { - Bugsnag.init(this) - val releaseStage = setOf(FLAVOUR_PRODUCTION, - FLAVOUR_TEST, - FLAVOUR_GITHUB, - FLAVOUR_RELEASE) - Bugsnag.setNotifyReleaseStages(*releaseStage.toTypedArray(), FLAVOUR_UNNAMED) - val versionSegments = BuildConfig.VERSION_NAME.split("_") - if (versionSegments.size > 1) { - Bugsnag.setAppVersion(versionSegments.first()) - Bugsnag.setReleaseStage(if (versionSegments.last() in releaseStage) versionSegments.last() - else FLAVOUR_UNNAMED) - Bugsnag.setUserName(BuildConfig.VERSION_NAME) - } - - Bugsnag.setAutoCaptureSessions(true) - Bugsnag.setUserId(Prefs.frostId) - Bugsnag.beforeNotify { error -> - when { - error.exception is UndeliverableException -> false - error.exception.stackTrace.any { it.className.contains("XposedBridge") } -> false - else -> true - } - } - } KL.shouldLog = { BuildConfig.DEBUG } + initBugsnag() Prefs.verboseLogging = false L.i { "Begin Frost for Facebook" } try { @@ -152,5 +128,24 @@ class FrostApp : Application() { } + private fun initBugsnag() { + if (BuildConfig.DEBUG) return + if (!BuildConfig.APPLICATION_ID.startsWith("com.pitchedapps.frost")) return + val version = BuildUtils.match(BuildConfig.VERSION_NAME) + ?: return L.d { "Bugsnag disabled for ${BuildConfig.VERSION_NAME}" } + Bugsnag.init(this) + Bugsnag.setNotifyReleaseStages(*BuildUtils.getAllStages()) + Bugsnag.setAppVersion(version.versionName) + Bugsnag.setReleaseStage(BuildUtils.getStage(BuildConfig.BUILD_TYPE)) + Bugsnag.setAutoCaptureSessions(true) + Bugsnag.setUserId(Prefs.frostId) + Bugsnag.beforeNotify { error -> + when { + error.exception is UndeliverableException -> false + error.exception.stackTrace.any { it.className.contains("XposedBridge") } -> false + else -> true + } + } + } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/BuildUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/BuildUtils.kt new file mode 100644 index 00000000..76af5359 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/BuildUtils.kt @@ -0,0 +1,25 @@ +package com.pitchedapps.frost.utils + +object BuildUtils { + + data class Data(val versionName: String, val tail: String) + + // Builds + const val BUILD_PRODUCTION = "production" + const val BUILD_TEST = "releaseTest" + const val BUILD_GITHUB = "github" + const val BUILD_RELEASE = "release" + const val BUILD_UNNAMED = "unnamed" + + fun match(version: String): Data? { + val regex = Regex("([0-9]+\\.[0-9]+\\.[0-9]+)-?([0-9]*-?[0-9a-zA-Z]*)") + val result = regex.matchEntire(version)?.groupValues ?: return null + return Data(result[1], result[2]) + } + + fun getAllStages(): Array<String> = + arrayOf(BUILD_PRODUCTION, BUILD_TEST, BUILD_GITHUB, BUILD_RELEASE, BUILD_UNNAMED) + + fun getStage(build: String): String = build.takeIf { it in getAllStages() } ?: BUILD_UNNAMED + +}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt index 7909f125..0cb57ed5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt @@ -15,11 +15,4 @@ const val REQUEST_TEXT_ZOOM = 1 shl 14 const val REQUEST_NAV = 1 shl 15 const val REQUEST_SEARCH = 1 shl 16 -const val MAIN_TIMEOUT_DURATION = 30 * 60 * 1000 // 30 min - -// Flavours -const val FLAVOUR_PRODUCTION = "production" -const val FLAVOUR_TEST = "releaseTest" -const val FLAVOUR_GITHUB = "github" -const val FLAVOUR_RELEASE = "release" -const val FLAVOUR_UNNAMED = "unnamed"
\ No newline at end of file +const val MAIN_TIMEOUT_DURATION = 30 * 60 * 1000 // 30 min
\ No newline at end of file |