Skip to content

Commit

Permalink
✨ feat(data): Handle potential exception in language substring
Browse files Browse the repository at this point in the history
🐛 fix(dataStore): Improve language handling in DataStoreManager
  • Loading branch information
maxrave-dev committed Dec 31, 2024
1 parent aad061b commit e0392fc
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ class DataStoreManager(

val translationLanguage =
settingsDataStore.data.map { preferences ->
preferences[TRANSLATION_LANGUAGE] ?: if (language.first().length >= 2) {
language
.first()
val languageValue = language.first()
preferences[TRANSLATION_LANGUAGE] ?: if (languageValue.length >= 2) {
languageValue
.substring(0..1)
} else {
"en"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ class MainRepository(
combine(dataStoreManager.location, dataStoreManager.language) { location, language ->
Pair(location, language)
}.collectLatest { (location, language) ->
youTube.locale = YouTubeLocale(location, language.substring(0..1))
youTube.locale = YouTubeLocale(location, try {
language.substring(0..1)
} catch (e: Exception) {
"en"
})
}
}
val ytCookieJob =
Expand Down
Loading

0 comments on commit e0392fc

Please sign in to comment.