diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 755691a..43a20e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,9 +2,15 @@ name: Build the app on: [push] +env: + ACRA_LOGIN: ${{ secrets.ACRARIUM_BASIC_AUTH_LOGIN }} + ACRA_PASS: ${{ secrets.ACRARIUM_BASIC_AUTH_PASSWORD }} + ACRA_URI: ${{ secrets.ACRARIUM_URI }} + jobs: build: runs-on: ubuntu-latest + environment: Development steps: - uses: actions/checkout@v3 diff --git a/app/build.gradle b/app/build.gradle index 2fcb26f..211d884 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,6 +15,12 @@ android { versionCode 1 versionName "1.0" setProperty("archivesBaseName", "ark-shelf") + def login = System.getenv("ACRA_LOGIN") ?: "" + def password = System.getenv("ACRA_PASS") ?: "" + def uri = System.getenv("ACRA_URI") ?: "" + buildConfigField "String", "ACRA_LOGIN", "\"$login\"" + buildConfigField "String", "ACRA_PASS", "\"$password\"" + buildConfigField "String", "ACRA_URI", "\"$uri\"" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -90,6 +96,9 @@ dependencies { implementation "org.orbit-mvi:orbit-viewmodel:4.3.2" implementation "com.ericktijerou.koleton:koleton:1.0.0-beta01" + implementation "ch.acra:acra-http:5.9.3" + implementation "ch.acra:acra-dialog:5.9.3" + implementation 'com.github.ARK-Builders:ark-filepicker:c6d66141c1' testImplementation 'junit:junit:4.+' diff --git a/app/src/main/java/space/taran/arkshelf/data/UserPreferencesImpl.kt b/app/src/main/java/space/taran/arkshelf/data/UserPreferencesImpl.kt index d31a01d..44375b3 100644 --- a/app/src/main/java/space/taran/arkshelf/data/UserPreferencesImpl.kt +++ b/app/src/main/java/space/taran/arkshelf/data/UserPreferencesImpl.kt @@ -3,9 +3,11 @@ package space.taran.arkshelf.data import android.content.Context import android.os.Environment import space.taran.arkshelf.domain.UserPreferences +import timber.log.Timber import java.nio.file.Path import javax.inject.Inject import kotlin.io.path.Path +import kotlin.io.path.exists class UserPreferencesImpl @Inject constructor( private val context: Context @@ -13,7 +15,20 @@ class UserPreferencesImpl @Inject constructor( private val prefs = context.getSharedPreferences("prefs", Context.MODE_PRIVATE) override fun getLinkFolder() = - prefs.getString(SAVE_PATH_KEY, null)?.let { Path(it) } + prefs.getString(SAVE_PATH_KEY, null) + ?.let { + val linkFolder = Path(it) + // Permission to access files may have been revoked + try { + if (linkFolder.exists()) + linkFolder + else + null + } catch (e: Throwable) { + Timber.e(e) + null + } + } override fun setLinkFolder(path: Path) = with(prefs.edit()) { diff --git a/app/src/main/java/space/taran/arkshelf/presentation/App.kt b/app/src/main/java/space/taran/arkshelf/presentation/App.kt index 44d905f..2f2a75d 100644 --- a/app/src/main/java/space/taran/arkshelf/presentation/App.kt +++ b/app/src/main/java/space/taran/arkshelf/presentation/App.kt @@ -4,9 +4,16 @@ import android.app.Application import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch +import org.acra.config.dialog +import org.acra.config.httpSender +import org.acra.data.StringFormat +import org.acra.ktx.initAcra +import org.acra.sender.HttpSender import space.taran.arkfilepicker.folders.FoldersRepo import space.taran.arklib.initArkLib import space.taran.arklib.initRustLogger +import space.taran.arkshelf.BuildConfig +import space.taran.arkshelf.R import space.taran.arkshelf.di.DIManager import timber.log.Timber @@ -25,9 +32,28 @@ class App : Application() { initArkLib() initRustLogger() Timber.plant(Timber.DebugTree()) + initAcra() instance = this DIManager.init(this) } + + private fun initAcra() { + initAcra { + buildConfigClass = BuildConfig::class.java + reportFormat = StringFormat.JSON + dialog { + text = getString(R.string.crash_dialog_description) + title = getString(R.string.crash_dialog_title) + commentPrompt = getString(R.string.crash_dialog_comment) + } + httpSender { + uri = BuildConfig.ACRA_URI + basicAuthLogin = BuildConfig.ACRA_LOGIN + basicAuthPassword = BuildConfig.ACRA_PASS + httpMethod = HttpSender.Method.POST + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e5eb23e..221922c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,6 +17,9 @@ Pick Pick link folder Link copied + Sorry, the application crashed. Please send a report to the developers. + Crash + You can add a comment here: %d item %d items