fix: accept mimetype text/html when looking for clipboard text
Some checks failed
/ build-native-libraries-arm64-v8a (push) Has been cancelled
/ build-apk-arm64-v8a (push) Has been cancelled

This commit is contained in:
- 2024-12-15 14:49:39 +01:00 committed by anoncontributorxmr
parent f35ca00b16
commit bd139e1cec
No known key found for this signature in database
GPG key ID: 318D49FCE95DEA5A

View file

@ -254,19 +254,17 @@ object Helper {
} }
fun getClipBoardText(context: Context): String? { fun getClipBoardText(context: Context): String? {
val clipboardManager = val clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager val primaryClip = clipboardManager.primaryClip
try { return primaryClip?.let {
if (clipboardManager.hasPrimaryClip() val description = it.description
&& clipboardManager.primaryClipDescription?.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN) == true // some apps for some reason store clipboard text as html
) { if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN) || description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
val item = clipboardManager.primaryClip?.getItemAt(0) // getItemAt may throw IndexOutOfBoundsException and there is no safe version of it
return item?.text.toString() kotlin.runCatching { it.getItemAt(0) }.getOrNull()?.text?.toString()
} } else {
} catch (ex: NullPointerException) { null
// if we have don't find a text in the clipboard }
return null }
}
return null
} }
} }