withLongRunningApi (#3675)

This commit is contained in:
Stanislav Dmitrenko 2024-01-15 21:29:11 +07:00 committed by GitHub
parent bfb274b037
commit 46fe0fc671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 11 additions and 11 deletions

View File

@ -36,7 +36,7 @@ actual fun SaveContentItemAction(cItem: ChatItem, saveFileLauncher: FileChooserL
writePermissionState.launchPermissionRequest()
}
}
is MsgContent.MCFile, is MsgContent.MCVoice, is MsgContent.MCVideo -> withBGApi { saveFileLauncher.launch(cItem.file?.fileName ?: "") }
is MsgContent.MCFile, is MsgContent.MCVoice, is MsgContent.MCVideo -> withLongRunningApi { saveFileLauncher.launch(cItem.file?.fileName ?: "") }
else -> {}
}
showMenu.value = false

View File

@ -101,7 +101,7 @@ fun CIFileView(
filePath = getLoadedFilePath(file)
}
if (filePath != null) {
withBGApi {
withLongRunningApi {
saveFileLauncher.launch(file.fileName)
}
} else {

View File

@ -34,7 +34,7 @@ fun ChatArchiveView(m: ChatModel, title: String, archiveName: String, archiveTim
ChatArchiveLayout(
title,
archiveTime,
saveArchive = { withBGApi { saveArchiveLauncher.launch(archivePath.substringAfterLast(File.separator)) }},
saveArchive = { withLongRunningApi { saveArchiveLauncher.launch(archivePath.substringAfterLast(File.separator)) }},
deleteArchiveAlert = { deleteArchiveAlert(m, archivePath) }
)
}

View File

@ -240,7 +240,7 @@ fun DatabaseLayout(
SettingsActionItem(
painterResource(MR.images.ic_download),
stringResource(MR.strings.import_database),
{ withBGApi { importArchiveLauncher.launch("application/zip") } },
{ withLongRunningApi { importArchiveLauncher.launch("application/zip") } },
textColor = Color.Red,
iconColor = Color.Red,
disabled = operationsDisabled
@ -500,7 +500,7 @@ private fun exportArchive(
saveArchiveLauncher: FileChooserLauncher
) {
progressIndicator.value = true
withBGApi {
withLongRunningApi {
try {
val archiveFile = exportChatArchive(m, chatArchiveName, chatArchiveTime, chatArchiveFile)
chatArchiveFile.value = archiveFile

View File

@ -39,7 +39,7 @@ fun withBGApi(action: suspend CoroutineScope.() -> Unit): Job =
CoroutineScope(singleThreadDispatcher).launch(block = { wrapWithLogging(action, it) })
}
fun withLongRunningApi(slow: Long = 120_000, deadlock: Long = 240_000, action: suspend CoroutineScope.() -> Unit): Job =
fun withLongRunningApi(slow: Long = Long.MAX_VALUE, deadlock: Long = Long.MAX_VALUE, action: suspend CoroutineScope.() -> Unit): Job =
Exception().let {
CoroutineScope(Dispatchers.Default).launch(block = { wrapWithLogging(action, it, slow = slow, deadlock = deadlock) })
}

View File

@ -131,7 +131,7 @@ object AppearanceScope {
SectionItemView({
val overrides = ThemeManager.currentThemeOverridesForExport(isInDarkTheme)
theme.value = yaml.encodeToString<ThemeOverrides>(overrides)
withBGApi { exportThemeLauncher.launch("simplex.theme")}
withLongRunningApi { exportThemeLauncher.launch("simplex.theme")}
}) {
Text(generalGetString(MR.strings.export_theme), color = colors.primary)
}
@ -144,7 +144,7 @@ object AppearanceScope {
}
}
// Can not limit to YAML mime type since it's unsupported by Android
SectionItemView({ withBGApi { importThemeLauncher.launch("*/*") } }) {
SectionItemView({ withLongRunningApi { importThemeLauncher.launch("*/*") } }) {
Text(generalGetString(MR.strings.import_theme), color = colors.primary)
}
}

View File

@ -22,7 +22,7 @@ actual fun ClipboardManager.shareText(text: String) {
}
actual fun shareFile(text: String, fileSource: CryptoFile) {
withBGApi {
withLongRunningApi {
FileChooserLauncher(false) { to: URI? ->
if (to != null) {
val absolutePath = if (fileSource.isAbsolutePath) fileSource.filePath else getAppFilePath(fileSource.filePath)

View File

@ -35,7 +35,7 @@ actual fun SaveContentItemAction(cItem: ChatItem, saveFileLauncher: FileChooserL
ItemAction(stringResource(MR.strings.save_verb), painterResource(if (cItem.file?.fileSource?.cryptoArgs == null) MR.images.ic_download else MR.images.ic_lock_open_right), onClick = {
val saveIfExists = {
when (cItem.content.msgContent) {
is MsgContent.MCImage, is MsgContent.MCFile, is MsgContent.MCVoice, is MsgContent.MCVideo -> withBGApi { saveFileLauncher.launch(cItem.file?.fileName ?: "") }
is MsgContent.MCImage, is MsgContent.MCFile, is MsgContent.MCVoice, is MsgContent.MCVideo -> withLongRunningApi { saveFileLauncher.launch(cItem.file?.fileName ?: "") }
else -> {}
}
showMenu.value = false

View File

@ -45,7 +45,7 @@ actual fun GetImageBottomSheet(
}
val pickImageLauncher = rememberFileChooserLauncher(true, null, processPickedImage)
ActionButton(null, stringResource(MR.strings.from_gallery_button), icon = painterResource(MR.images.ic_image)) {
withBGApi { pickImageLauncher.launch("image/*") }
withLongRunningApi { pickImageLauncher.launch("image/*") }
}
}
}