Skip to content

Commit

Permalink
Don't suppress coroutine cancellation in clipboard utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
gujjwal00 committed Feb 25, 2024
1 parent 2ac85c0 commit e1a6152
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/gaurav/avnc/util/Clipboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.content.ClipboardManager
import android.content.Context
import android.util.Log
import androidx.core.content.ContextCompat
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

Expand All @@ -35,6 +36,8 @@ suspend fun setClipboardText(context: Context, text: String): Boolean {
success = true
}
}
} catch (e: CancellationException) {
throw e
} catch (t: Throwable) {
Log.e("ClipboardUtil", "Could not copy text to clipboard.", t)
}
Expand All @@ -53,6 +56,8 @@ suspend fun getClipboardText(context: Context): String? {
result = it.primaryClip?.getItemAt(0)?.text?.toString()
}
}
} catch (e: CancellationException) {
throw e
} catch (t: Throwable) {
Log.e("ClipboardUtil", "Could not retrieve text from clipboard.", t)
}
Expand Down

0 comments on commit e1a6152

Please sign in to comment.