diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-24 01:24:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-24 01:24:12 +0200 |
commit | 890d17ba68b2d1e0287d3c6b19c45ef6d6a131d6 (patch) | |
tree | 08d4830fc0a04b64487904f8831d6895f3bd4fd2 /src/main/java/at/hannibal2 | |
parent | 284f294c8c40ae61214ec6d8378415a457ebac33 (diff) | |
download | skyhanni-890d17ba68b2d1e0287d3c6b19c45ef6d6a131d6.tar.gz skyhanni-890d17ba68b2d1e0287d3c6b19c45ef6d6a131d6.tar.bz2 skyhanni-890d17ba68b2d1e0287d3c6b19c45ef6d6a131d6.zip |
Backend: rewrote getclipboard logic (#1773)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ClipboardUtils.kt | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ClipboardUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ClipboardUtils.kt index 0c55b894c..ddd072c28 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ClipboardUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ClipboardUtils.kt @@ -2,8 +2,8 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.test.command.ErrorManager -import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.awt.Toolkit @@ -26,20 +26,18 @@ object ClipboardUtils { return result } - private suspend fun getClipboard(): Clipboard? { - val deferred = CompletableDeferred<Clipboard?>() - if (canAccessClipboard()) { - deferred.complete(Toolkit.getDefaultToolkit().systemClipboard) - } else { - LorenzUtils.runDelayed(5.milliseconds) { - SkyHanniMod.coroutineScope.launch { - deferred.complete(getClipboard()) - } - } - } - return deferred.await() + private suspend fun getClipboard(retries: Int = 20): Clipboard? = if (canAccessClipboard()) { + Toolkit.getDefaultToolkit().systemClipboard + } else if (retries > 0) { + delay(11) + getClipboard(retries - 1) + } else { + ErrorManager.logErrorStateWithData("can not read clipboard", + "clipboard can not be accessed after 20 retries") + null } + fun copyToClipboard(text: String, step: Int = 0) { SkyHanniMod.coroutineScope.launch { try { |