Skip to content

Commit a16a98a

Browse files
Improved the creation of SpellingsDB on the IO thread.
* Fixed a native crash that occurred when the `SpellingsDB` creation was incomplete and the user closed the application. In such cases, a temporary folder (.tmp) remained, causing a `DatabaseCreateError` during the next initialization. * Improved the font of "Do you mean:" text so that it could be show different from our suggestion items.
1 parent fc1fccc commit a16a98a

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

core/src/main/java/org/kiwix/kiwixmobile/core/reader/ZimFileReader.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class ZimFileReader constructor(
6363
val jniKiwixReader: Archive,
6464
private val searcher: SuggestionSearcher
6565
) {
66-
private val spellingsDBCreationMutex = Mutex()
67-
6866
interface Factory {
6967
suspend fun create(
7068
zimReaderSource: ZimReaderSource,
@@ -468,6 +466,8 @@ class ZimFileReader constructor(
468466
}
469467

470468
companion object {
469+
private val spellingsDBCreationMutex = Mutex()
470+
471471
/*
472472
* these uris aren't actually nullable but unit tests fail to compile as
473473
* Uri.parse returns null without android dependencies loaded

core/src/main/java/org/kiwix/kiwixmobile/core/search/SearchScreen.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import androidx.compose.ui.res.stringResource
5959
import androidx.compose.ui.semantics.contentDescription
6060
import androidx.compose.ui.semantics.semantics
6161
import androidx.compose.ui.semantics.testTag
62+
import androidx.compose.ui.text.font.FontWeight
6263
import androidx.compose.ui.text.style.TextAlign
6364
import androidx.compose.ui.text.style.TextOverflow.Companion.Ellipsis
6465
import org.kiwix.kiwixmobile.core.R
@@ -196,6 +197,7 @@ private fun LazyListScope.spellingCorrectionHeader() {
196197
Text(
197198
text = stringResource(R.string.do_you_mean),
198199
fontSize = SEARCH_ITEM_TEXT_SIZE,
200+
fontWeight = FontWeight.Companion.W700,
199201
color = MaterialTheme.colorScheme.onBackground,
200202
modifier = Modifier
201203
.fillMaxWidth()

core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileUtils.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,20 @@ object FileUtils {
6868
} else {
6969
context.cacheDir
7070
}
71-
return File(baseCacheDir, SPELLING_DB_CACHED_DIRECTORY).apply {
71+
72+
val spellingDBCacheDir = File(baseCacheDir, SPELLING_DB_CACHED_DIRECTORY).apply {
7273
if (!exists()) mkdirs()
7374
}
75+
76+
// Clean up any incomplete `.tmp` folders inside the spelling DB directory
77+
spellingDBCacheDir.listFiles()?.forEach { file ->
78+
if (file.isDirectory && file.name.endsWith(".tmp")) {
79+
file.deleteRecursively()
80+
Log.w(TAG_KIWIX, "Deleted incomplete SpellingsDB folder: ${file.absolutePath}")
81+
}
82+
}
83+
84+
return spellingDBCacheDir
7485
}
7586

7687
@JvmStatic

0 commit comments

Comments
 (0)