android, desktop: more relaxed way of showing alerts for encryption/decryption errors (#4085)

This commit is contained in:
Stanislav Dmitrenko
2024-04-25 03:39:59 +07:00
committed by GitHub
parent 2b7f3099a6
commit 9e2a3fe848
8 changed files with 12 additions and 12 deletions
@@ -156,13 +156,13 @@ actual object AudioPlayer: AudioPlayerInterface {
}
}.onFailure {
Log.e(TAG, it.stackTraceToString())
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.message)
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.stackTraceToString())
return null
}
runCatching { player.prepare() }.onFailure {
// Can happen when audio file is broken
Log.e(TAG, it.stackTraceToString())
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.message)
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.stackTraceToString())
return null
}
}
@@ -88,7 +88,7 @@ actual class VideoPlayer actual constructor(
player.setMediaSource(source, seek ?: 0L)
}.onFailure {
Log.e(TAG, it.stackTraceToString())
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.message)
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.stackTraceToString())
brokenVideo.value = true
return false
}
@@ -97,7 +97,7 @@ actual class VideoPlayer actual constructor(
runCatching { player.prepare() }.onFailure {
// Can happen when video file is broken
Log.e(TAG, it.stackTraceToString())
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.message)
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.stackTraceToString())
brokenVideo.value = true
return false
}
@@ -192,7 +192,6 @@ actual suspend fun getLoadedImage(file: CIFile?): Pair<ImageBitmap, ByteArray>?
readCryptoFile(getAppFilePath(file.fileSource.filePath), file.fileSource.cryptoArgs)
} catch (e: Exception) {
Log.e(TAG, "Unable to read crypto file: " + e.stackTraceToString())
AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.error), text = e.stackTraceToString())
return null
}
} else {
@@ -2701,6 +2701,7 @@ data class CryptoFile(
} catch (e: Exception) {
Log.e(TAG, "Unable to decrypt crypto file: " + e.stackTraceToString())
AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.error), text = e.stackTraceToString())
return null
}
return tmpFile.toURI()
}
@@ -146,7 +146,7 @@ fun ImageFullScreenView(imageProvider: () -> ImageGalleryProvider, close: () ->
onDispose { playersToRelease.add(decrypted) }
}
} else if (media.fileSource != null) {
VideoViewEncrypted(uriDecrypted, media.fileSource, preview)
VideoViewEncrypted(uriDecrypted, media.fileSource, preview, close)
}
}
}
@@ -163,10 +163,13 @@ fun ImageFullScreenView(imageProvider: () -> ImageGalleryProvider, close: () ->
expect fun FullScreenImageView(modifier: Modifier, data: ByteArray, imageBitmap: ImageBitmap)
@Composable
private fun VideoViewEncrypted(uriUnencrypted: MutableState<URI?>, fileSource: CryptoFile, defaultPreview: ImageBitmap) {
private fun VideoViewEncrypted(uriUnencrypted: MutableState<URI?>, fileSource: CryptoFile, defaultPreview: ImageBitmap, close: () -> Unit) {
LaunchedEffect(Unit) {
withBGApi {
uriUnencrypted.value = fileSource.decryptedGetOrCreate()
if (uriUnencrypted.value == null) {
close()
}
}
}
Box(contentAlignment = Alignment.Center) {
@@ -60,7 +60,7 @@ actual object AudioPlayer: AudioPlayerInterface {
}.onFailure {
Log.e(TAG, it.stackTraceToString())
fileSource.deleteTmpFile()
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.message)
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.stackTraceToString())
return null
}
}
@@ -70,7 +70,7 @@ actual class VideoPlayer actual constructor(
}
}.onFailure {
Log.e(TAG, it.stackTraceToString())
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.message)
AlertManager.shared.showAlertMsg(generalGetString(MR.strings.unknown_error), it.stackTraceToString())
brokenVideo.value = true
return false
}
@@ -12,11 +12,9 @@ import chat.simplex.common.model.CIFile
import chat.simplex.common.model.readCryptoFile
import chat.simplex.common.platform.*
import chat.simplex.common.simplexWindowState
import chat.simplex.res.MR
import kotlinx.coroutines.delay
import java.io.ByteArrayInputStream
import java.io.File
import java.io.*
import java.net.URI
import javax.imageio.ImageIO
import kotlin.io.encoding.Base64
@@ -143,7 +141,6 @@ actual suspend fun getLoadedImage(file: CIFile?): Pair<ImageBitmap, ByteArray>?
if (bitmap != null) bitmap to data else null
} catch (e: Exception) {
Log.e(TAG, "Unable to read crypto file: " + e.stackTraceToString())
AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.error), text = e.stackTraceToString())
null
}
} else {