feat(ui): complete ABox app experience redesign #10

Merged
KremeCN merged 40 commits from feat/ui-ux-redesign into main 2026-08-27 23:25:08 +08:00
2 changed files with 24 additions and 1 deletions
Showing only changes of commit 686176b148 - Show all commits
@@ -38,9 +38,16 @@ class DataStoreUiPreferencesRepository internal constructor(
transform: (UiPreferences) -> UiPreferences,
): UiPreferencesWriteResult = try {
dataStore.edit { storedPreferences ->
storedPreferences.putAll(transform(preferencesFrom(storedPreferences)))
val updatedPreferences = try {
transform(preferencesFrom(storedPreferences))
} catch (cause: Throwable) {
throw TransformFailure(cause)
}
storedPreferences.putAll(updatedPreferences)
}
UiPreferencesWriteResult.Success
} catch (failure: TransformFailure) {
throw failure.cause
} catch (cause: CancellationException) {
throw cause
} catch (_: IOException) {
@@ -71,6 +78,10 @@ class DataStoreUiPreferencesRepository internal constructor(
private inline fun <reified T : Enum<T>> String.enumOrDefault(default: T): T =
enumValues<T>().firstOrNull { it.name == this } ?: default
private class TransformFailure(
override val cause: Throwable,
) : RuntimeException(cause)
private companion object {
val RENDERER = stringPreferencesKey("renderer")
val THEME_MODE = stringPreferencesKey("theme_mode")
@@ -99,6 +99,18 @@ class DataStoreUiPreferencesRepositoryTest {
assertEquals(failure, actual)
}
@Test
fun updateRethrowsTransformIOException() = runTest {
val repository = DataStoreUiPreferencesRepository(InMemoryPreferencesDataStore())
val failure = IOException("invalid transform")
val actual = runCatching {
repository.update { throw failure }
}.exceptionOrNull()
assertEquals(failure, actual)
}
@Test
fun updateRethrowsCancellationException() = runTest {
val cancellation = CancellationException("cancelled")