Skip to content

Commit

Permalink
fix(fonts): fix crash when fonts folder isn't set
Browse files Browse the repository at this point in the history
 * don't copy non-fonts files
  • Loading branch information
abdallahmehiz committed Aug 1, 2024
1 parent 031062b commit 6c50703
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ class PlayerActivity : AppCompatActivity() {
.copyTo(File("$cachePath/fonts/subfont.ttf").outputStream())
}
DocumentFile.fromTreeUri(this, Uri.parse(subtitlesPreferences.fontsFolder.get()))?.listFiles()?.forEach {
if (it.isDirectory || fontsDir.findFile(it.name!!)?.exists() == true) return
if (it.isDirectory || fontsDir.findFile(it.name!!)?.exists() == true) return@forEach
if (!it.name!!.endsWith("ttf", true) || !it.name!!.endsWith("otf")) return@forEach
val input = contentResolver.openInputStream(it.uri)
input!!.copyTo(File("$cachePath/fonts/${it.name}").outputStream())
input.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ fun SubtitleSettingsTypographyCard(
mutableStateOf(indicator)
}
LaunchedEffect(Unit) {
if (!preferences.fontsFolder.isSet()) {
fontsLoadingIndicator = null
return@LaunchedEffect
}
withContext(Dispatchers.IO) {
fonts.addAll(
DocumentFile.fromTreeUri(context, Uri.parse(preferences.fontsFolder.get()))!!.listFiles().filter {
DocumentFile.fromTreeUri(
context,
Uri.parse(preferences.fontsFolder.get()),
)!!.listFiles().filter {
it.isFile && (it.name!!.endsWith("ttf", true) || it.name!!.endsWith("otf", true))
}.map { TTFFile.open(context.contentResolver.openInputStream(it.uri)!!).families.values.first() },
)
Expand Down

0 comments on commit 6c50703

Please sign in to comment.