Skip to content

Commit

Permalink
Developer mode: Fail-fast (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Jan 8, 2020
1 parent 8ef5c60 commit 17c4013
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Improvements 🙌:
- The initial sync is now handled by a foreground service
- Render aliases and canonical alias change in the timeline
- Fix autocompletion issues and add support for rooms and groups
- Introduce developer mode in the settings (#796)
- Introduce developer mode in the settings (#745, #796)
- Improve devices list screen
- Add settings for rageshake sensibility
- Fix autocompletion issues and add support for rooms, groups, and emoji (#780)
Expand Down
5 changes: 3 additions & 2 deletions vector/src/main/java/im/vector/riotx/VectorApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import im.vector.riotx.core.di.DaggerVectorComponent
import im.vector.riotx.core.di.HasVectorInjector
import im.vector.riotx.core.di.VectorComponent
import im.vector.riotx.core.extensions.configureAndStart
import im.vector.riotx.core.rx.setupRxPlugin
import im.vector.riotx.core.rx.RxConfig
import im.vector.riotx.features.configuration.VectorConfiguration
import im.vector.riotx.features.lifecycle.VectorActivityLifecycleCallbacks
import im.vector.riotx.features.notifications.NotificationDrawerManager
Expand Down Expand Up @@ -75,6 +75,7 @@ class VectorApplication : Application(), HasVectorInjector, MatrixConfiguration.
@Inject lateinit var versionProvider: VersionProvider
@Inject lateinit var notificationUtils: NotificationUtils
@Inject lateinit var appStateHandler: AppStateHandler
@Inject lateinit var rxConfig: RxConfig
lateinit var vectorComponent: VectorComponent
private var fontThreadHandler: Handler? = null

Expand All @@ -84,7 +85,7 @@ class VectorApplication : Application(), HasVectorInjector, MatrixConfiguration.
vectorComponent = DaggerVectorComponent.factory().create(this)
vectorComponent.inject(this)
vectorUncaughtExceptionHandler.activate(this)
setupRxPlugin()
rxConfig.setupRxPlugin()

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
Expand Down
25 changes: 16 additions & 9 deletions vector/src/main/java/im/vector/riotx/core/rx/Rx.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,26 @@
package im.vector.riotx.core.rx

import im.vector.riotx.BuildConfig
import im.vector.riotx.features.settings.VectorPreferences
import io.reactivex.plugins.RxJavaPlugins
import timber.log.Timber
import javax.inject.Inject

/**
* Make sure unhandled Rx error does not crash the app in production
*/
fun setupRxPlugin() {
RxJavaPlugins.setErrorHandler { throwable ->
Timber.e(throwable, "RxError")
class RxConfig @Inject constructor(
private val vectorPreferences: VectorPreferences
) {

/**
* Make sure unhandled Rx error does not crash the app in production
*/
fun setupRxPlugin() {
RxJavaPlugins.setErrorHandler { throwable ->
Timber.e(throwable, "RxError")

// Avoid crash in production
if (BuildConfig.DEBUG) {
throw throwable
// Avoid crash in production
if (BuildConfig.DEBUG || vectorPreferences.failFast()) {
throw throwable
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private const val SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY = "SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY"
private const val SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY = "SETTINGS_LABS_SHOW_HIDDEN_EVENTS_PREFERENCE_KEY"
private const val SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY = "SETTINGS_LABS_ENABLE_SWIPE_TO_REPLY"
private const val SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY = "SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY"

// analytics
const val SETTINGS_USE_ANALYTICS_KEY = "SETTINGS_USE_ANALYTICS_KEY"
Expand Down Expand Up @@ -266,6 +267,10 @@ class VectorPreferences @Inject constructor(private val context: Context) {
return developerMode() && defaultPrefs.getBoolean(SETTINGS_LABS_ALLOW_EXTENDED_LOGS, false)
}

fun failFast(): Boolean {
return developerMode() && defaultPrefs.getBoolean(SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY, false)
}

/**
* Tells if we have already asked the user to disable battery optimisations on android >= M devices.
*
Expand Down
3 changes: 3 additions & 0 deletions vector/src/main/res/values/strings_riotX.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

<string name="autocomplete_limited_results">Showing only the first results, type more letters…</string>

<string name="settings_developer_mode_fail_fast_title">Fail-fast</string>
<string name="settings_developer_mode_fail_fast_summary">RiotX may crash more often when an unexpected error occurs</string>

</resources>
7 changes: 7 additions & 0 deletions vector/src/main/res/xml/vector_settings_advanced_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
android:summary="@string/labs_allow_extended_logging_summary"
android:title="@string/labs_allow_extended_logging" />

<im.vector.riotx.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:dependency="SETTINGS_DEVELOPER_MODE_PREFERENCE_KEY"
android:key="SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY"
android:summary="@string/settings_developer_mode_fail_fast_summary"
android:title="@string/settings_developer_mode_fail_fast_title" />

<!-- TODO Display unsupported events -->

</im.vector.riotx.core.preference.VectorPreferenceCategory>
Expand Down

0 comments on commit 17c4013

Please sign in to comment.