From a405372f6acea51daab2eae138bcebfe7464de7a Mon Sep 17 00:00:00 2001 From: kr328 Date: Mon, 16 May 2022 20:00:48 +0800 Subject: [PATCH] Fix: operate clipboard on main thread --- .../kr328/clash/AccessControlActivity.kt | 19 +++++++------------ .../github/kr328/clash/design/LogcatDesign.kt | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/kr328/clash/AccessControlActivity.kt b/app/src/main/java/com/github/kr328/clash/AccessControlActivity.kt index 546dfed4..b3575341 100644 --- a/app/src/main/java/com/github/kr328/clash/AccessControlActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/AccessControlActivity.kt @@ -76,11 +76,8 @@ class AccessControlActivity : BaseActivity() { val data = clipboard?.primaryClip if (data != null && data.itemCount > 0) { - val all = withContext(Dispatchers.IO) { - val packages = data.getItemAt(0).text.split("\n").toSet() - - design.apps.map(AppInfo::packageName).intersect(packages) - } + val packages = data.getItemAt(0).text.split("\n").toSet() + val all = design.apps.map(AppInfo::packageName).intersect(packages) selected.clear() selected.addAll(all) @@ -91,14 +88,12 @@ class AccessControlActivity : BaseActivity() { AccessControlDesign.Request.Export -> { val clipboard = getSystemService() - withContext(Dispatchers.IO) { - val data = ClipData.newPlainText( - "packages", - selected.joinToString("\n") - ) + val data = ClipData.newPlainText( + "packages", + selected.joinToString("\n") + ) - clipboard?.setPrimaryClip(data) - } + clipboard?.setPrimaryClip(data) } } } diff --git a/design/src/main/java/com/github/kr328/clash/design/LogcatDesign.kt b/design/src/main/java/com/github/kr328/clash/design/LogcatDesign.kt index b66963c1..fe06bbf9 100644 --- a/design/src/main/java/com/github/kr328/clash/design/LogcatDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/LogcatDesign.kt @@ -26,7 +26,7 @@ class LogcatDesign( private val binding = DesignLogcatBinding .inflate(context.layoutInflater, context.root, false) private val adapter = LogMessageAdapter(context) { - launch(Dispatchers.IO) { + launch { val data = ClipData.newPlainText("log_message", it.message) context.getSystemService()?.setPrimaryClip(data)