From ed7c7f4a7ada9f20cd0e699fccb5185fbc4243cd Mon Sep 17 00:00:00 2001 From: Toby Bridle Date: Fri, 12 Jan 2024 13:54:33 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20crash=20when=20document?= =?UTF-8?q?=20dir=20is=20blank?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/data/repository/ModuleRepositoryImpl.kt | 1 + app/src/main/java/com/chouten/app/di/AppModule.kt | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/chouten/app/data/repository/ModuleRepositoryImpl.kt b/app/src/main/java/com/chouten/app/data/repository/ModuleRepositoryImpl.kt index 974c86d..4281547 100644 --- a/app/src/main/java/com/chouten/app/data/repository/ModuleRepositoryImpl.kt +++ b/app/src/main/java/com/chouten/app/data/repository/ModuleRepositoryImpl.kt @@ -31,6 +31,7 @@ class ModuleRepositoryImpl @Inject constructor( override suspend fun getModuleDirs(): List { val preferences = context.filepathDatastore.data.first() + if (preferences.CHOUTEN_ROOT_DIR == Uri.EMPTY) return emptyList() val contentResolver = context.contentResolver return withContext(Dispatchers.IO) { diff --git a/app/src/main/java/com/chouten/app/di/AppModule.kt b/app/src/main/java/com/chouten/app/di/AppModule.kt index 63042c4..3779baa 100644 --- a/app/src/main/java/com/chouten/app/di/AppModule.kt +++ b/app/src/main/java/com/chouten/app/di/AppModule.kt @@ -124,9 +124,13 @@ object AppModule { @Provides fun provideModuleRepository(app: Application, httpClient: Requests): ModuleRepository { val moduleDirGetter: suspend (Uri) -> Uri = { uri: Uri -> - GetModuleDirUseCase( - app.applicationContext - )(uri) + try { + GetModuleDirUseCase( + app.applicationContext + )(uri) + } catch (e: Exception) { + Uri.EMPTY + } } return ModuleRepositoryImpl(app.applicationContext, moduleDirGetter) }