Skip to content

Commit

Permalink
improvement: Show actual JSON when a cipher fails the decoding #224
Browse files Browse the repository at this point in the history
  • Loading branch information
AChep committed Mar 27, 2024
1 parent 1d170fd commit a1210b4
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data class BitwardenService(
data class Error(
val code: Int,
val message: String? = null,
val blob: String? = null,
val revisionDate: Instant,
) {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.artemchep.keyguard.feature.home.vault.component

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
Expand All @@ -11,6 +15,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.AccessTime
import androidx.compose.material.icons.outlined.ContentCopy
import androidx.compose.material.icons.outlined.ErrorOutline
import androidx.compose.material.icons.outlined.Sync
import androidx.compose.material3.Icon
Expand All @@ -24,7 +29,11 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.artemchep.keyguard.feature.home.vault.model.VaultViewItem
import com.artemchep.keyguard.ui.DisabledEmphasisAlpha
import com.artemchep.keyguard.ui.ExpandedIfNotEmpty
Expand Down Expand Up @@ -122,6 +131,83 @@ fun VaultViewErrorItem(
.width(8.dp),
)
}
if (item.blob != null) Row(
modifier = Modifier
.padding(vertical = 8.dp)
.height(IntrinsicSize.Min)
.background(
color = LocalContentColor.current
.combineAlpha(0.1f),
),
verticalAlignment = Alignment.CenterVertically,
) {
Spacer(
modifier = Modifier
.width(8.dp),
)
Box(
modifier = Modifier
.width(8.dp)
.background(
color = LocalContentColor.current
.combineAlpha(MediumEmphasisAlpha),
)
.fillMaxHeight(),
)
Spacer(
modifier = Modifier
.width(8.dp),
)
Column(
modifier = Modifier
.weight(1f),
) {
Text(
modifier = modifier
.padding(
vertical = 8.dp,
),
text = "BLOB",
style = MaterialTheme.typography.labelLarge,
fontSize = 12.sp,
fontWeight = FontWeight.Medium,
color = LocalContentColor.current
.combineAlpha(MediumEmphasisAlpha),
)
Text(
modifier = Modifier
.padding(),
text = item.blob,
maxLines = 3,
fontFamily = FontFamily.Monospace,
fontSize = 13.sp,
overflow = TextOverflow.Ellipsis,
)
Spacer(
modifier = Modifier
.height(8.dp),
)
}
Spacer(
modifier = Modifier
.width(8.dp),
)
val updatedOnCopy by rememberUpdatedState(item.onCopyBlob)
IconButton(
onClick = {
updatedOnCopy?.invoke()
},
) {
Icon(
imageVector = Icons.Outlined.ContentCopy,
contentDescription = null,
)
}
Spacer(
modifier = Modifier
.width(8.dp),
)
}
HorizontalDivider()
Row(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ sealed interface VaultViewItem {
override val id: String,
val name: String,
val message: String?,
val blob: String? = null,
val timestamp: String,
val onRetry: (() -> Unit)? = null,
val onCopyBlob: (() -> Unit)? = null,
) : VaultViewItem {
companion object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ private fun RememberStateFlowScope.oh(
id = "error",
name = "Couldn't sync the item",
message = cipherError.message(),
blob = cipherError.blob,
timestamp = time,
onRetry = if (cipherError.canRetry(cipher.revisionDate)) {
// lambda
Expand All @@ -830,6 +831,17 @@ private fun RememberStateFlowScope.oh(
} else {
null
},
onCopyBlob = if (cipherError.blob != null) {
// lambda
{
copy.copy(
text = cipherError.blob,
hidden = false,
)
}
} else {
null
},
)
emit(model)
}
Expand Down
Loading

0 comments on commit a1210b4

Please sign in to comment.