mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-12-18 11:20:24 +00:00
fix: accept mimetype text/html when looking for clipboard text
This commit is contained in:
parent
f35ca00b16
commit
bd139e1cec
1 changed files with 10 additions and 12 deletions
|
@ -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 {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
} catch (ex: NullPointerException) {
|
|
||||||
// if we have don't find a text in the clipboard
|
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue