aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2018-10-08 21:11:03 -0400
committerGitHub <noreply@github.com>2018-10-08 21:11:03 -0400
commit49d829355be470889a5624f562be24cc81b7442e (patch)
tree2c74c35e2de90f1ab40d1dd4153627ac5fd380d0 /app
parente113308923e319a98a8800f95aaba1998d50e7a2 (diff)
downloadfrost-49d829355be470889a5624f562be24cc81b7442e.tar.gz
frost-49d829355be470889a5624f562be24cc81b7442e.tar.bz2
frost-49d829355be470889a5624f562be24cc81b7442e.zip
Update when bugsnag gets added (#1128)
Diffstat (limited to 'app')
-rw-r--r--app/build.gradle2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt45
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/BuildUtils.kt25
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Const.kt9
-rw-r--r--app/src/test/kotlin/com/pitchedapps/frost/utils/BuildUtilsTest.kt22
5 files changed, 69 insertions, 34 deletions
diff --git a/app/build.gradle b/app/build.gradle
index b4a3a42e..cc50c583 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -10,7 +10,7 @@ android {
androidGitVersion {
codeFormat = 'MMNNPPXX'
- format = '%tag%%.count%%-commit%'
+ format = '%tag%%-count%%-commit%'
prefix 'v'
}
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
diff --git a/app/src/test/kotlin/com/pitchedapps/frost/utils/BuildUtilsTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/utils/BuildUtilsTest.kt
new file mode 100644
index 00000000..02c879f2
--- /dev/null
+++ b/app/src/test/kotlin/com/pitchedapps/frost/utils/BuildUtilsTest.kt
@@ -0,0 +1,22 @@
+package com.pitchedapps.frost.utils
+
+import com.pitchedapps.frost.BuildConfig
+import org.junit.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertNull
+
+class BuildUtilsTest {
+
+ @Test
+ fun matchingVersions() {
+ assertNull(BuildUtils.match("unknown"))
+ assertEquals(BuildUtils.Data("1.0.0", ""), BuildUtils.match("1.0.0"))
+ assertEquals(BuildUtils.Data("1.0.1", "22-asdf"), BuildUtils.match("1.0.1-22-asdf"))
+ }
+
+ @Test
+ fun androidTests() {
+ assertNotNull(BuildUtils.match(BuildConfig.VERSION_NAME))
+ }
+} \ No newline at end of file