From 1d9218ed9e8f4bed13455feb2b97b060e6171305 Mon Sep 17 00:00:00 2001 From: mdrlzy Date: Sun, 30 Jul 2023 21:08:10 +0600 Subject: [PATCH 1/5] Crashes reporting implemented (ACRA) --- .github/workflows/build.yml | 5 ++++ app/build.gradle | 9 +++++++ .../space/taran/arkshelf/presentation/App.kt | 26 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 +++ 4 files changed, 43 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 755691a..b8bfea0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,6 +5,11 @@ on: [push] jobs: build: runs-on: ubuntu-latest + environment: Development + env: + ACRA_LOGIN: ${{ secrets.ACRARIUM_BASIC_AUTH_LOGIN }} + ACRA_PASS: ${{ secrets.ACRARIUM_BASIC_AUTH_PASSWORD }} + ACRA_URI: ${{ secrets.ACRARIUM_URI }} 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/presentation/App.kt b/app/src/main/java/space/taran/arkshelf/presentation/App.kt index 44d905f..4df946d 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() = CoroutineScope(Dispatchers.IO).launch { + 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 From 8ff541afbf435d61028e8c3390320662154ce530 Mon Sep 17 00:00:00 2001 From: mdrlzy Date: Fri, 28 Jul 2023 01:52:19 +0600 Subject: [PATCH 2/5] Handle absence of the folder --- .../space/taran/arkshelf/data/UserPreferencesImpl.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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..623ee51 100644 --- a/app/src/main/java/space/taran/arkshelf/data/UserPreferencesImpl.kt +++ b/app/src/main/java/space/taran/arkshelf/data/UserPreferencesImpl.kt @@ -6,6 +6,7 @@ import space.taran.arkshelf.domain.UserPreferences 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 +14,14 @@ 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) + if (linkFolder.exists()) + linkFolder + else + null + } override fun setLinkFolder(path: Path) = with(prefs.edit()) { From 5e90f35841f67a5ed45ab69af469b30e4ea65dc2 Mon Sep 17 00:00:00 2001 From: mdrlzy Date: Mon, 31 Jul 2023 01:02:42 +0600 Subject: [PATCH 3/5] tmp --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b8bfea0..1e916d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ jobs: build: runs-on: ubuntu-latest environment: Development - env: + env: ACRA_LOGIN: ${{ secrets.ACRARIUM_BASIC_AUTH_LOGIN }} ACRA_PASS: ${{ secrets.ACRARIUM_BASIC_AUTH_PASSWORD }} ACRA_URI: ${{ secrets.ACRARIUM_URI }} From a6a7decd970a100d060265c6698c3cdda3205572 Mon Sep 17 00:00:00 2001 From: Kirill Taran Date: Tue, 1 Aug 2023 20:29:15 +0300 Subject: [PATCH 4/5] Indentation fixed --- .github/workflows/build.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1e916d6..43a20e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,14 +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 - env: - ACRA_LOGIN: ${{ secrets.ACRARIUM_BASIC_AUTH_LOGIN }} - ACRA_PASS: ${{ secrets.ACRARIUM_BASIC_AUTH_PASSWORD }} - ACRA_URI: ${{ secrets.ACRARIUM_URI }} steps: - uses: actions/checkout@v3 From 4ee58ad84c3e34a71a4b26ab3627797ab2a07609 Mon Sep 17 00:00:00 2001 From: mdrlzy Date: Wed, 2 Aug 2023 01:21:07 +0600 Subject: [PATCH 5/5] tmp --- .../taran/arkshelf/data/UserPreferencesImpl.kt | 13 ++++++++++--- .../java/space/taran/arkshelf/presentation/App.kt | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) 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 623ee51..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,6 +3,7 @@ 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 @@ -17,10 +18,16 @@ class UserPreferencesImpl @Inject constructor( prefs.getString(SAVE_PATH_KEY, null) ?.let { val linkFolder = Path(it) - if (linkFolder.exists()) - linkFolder - else + // Permission to access files may have been revoked + try { + if (linkFolder.exists()) + linkFolder + else + null + } catch (e: Throwable) { + Timber.e(e) null + } } 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 4df946d..2f2a75d 100644 --- a/app/src/main/java/space/taran/arkshelf/presentation/App.kt +++ b/app/src/main/java/space/taran/arkshelf/presentation/App.kt @@ -39,7 +39,7 @@ class App : Application() { DIManager.init(this) } - private fun initAcra() = CoroutineScope(Dispatchers.IO).launch { + private fun initAcra() { initAcra { buildConfigClass = BuildConfig::class.java reportFormat = StringFormat.JSON