From 578f30b7c9d7d83090946bb4eb5a569879c304ef Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Sat, 15 Oct 2022 19:06:12 +0200 Subject: [PATCH] Replaced custom clipboard method by the built-in --- .../com/jetpackduba/gitnuro/extensions/SystemUtils.kt | 11 ----------- .../com/jetpackduba/gitnuro/ui/CommitChanges.kt | 5 ++++- .../jetpackduba/gitnuro/viewmodels/TabViewModel.kt | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/extensions/SystemUtils.kt b/src/main/kotlin/com/jetpackduba/gitnuro/extensions/SystemUtils.kt index 3a4d2d6..66e70a4 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/extensions/SystemUtils.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/extensions/SystemUtils.kt @@ -65,17 +65,6 @@ private fun openFileJdk(filePath: String) { } } -fun copyInBrowser(textToCopy: String) { - try { - val selection = StringSelection(textToCopy) - val clipboard: Clipboard = Toolkit.getDefaultToolkit().systemClipboard - clipboard.setContents(selection, selection) - } catch (ex: Exception) { - printLog(TAG, "Failed to copy text") - ex.printStackTrace() - } -} - enum class OS { LINUX, WINDOWS, diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt index 734a98a..fdc2039 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/CommitChanges.kt @@ -8,6 +8,8 @@ import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalClipboardManager +import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -138,6 +140,7 @@ fun Author( ) { var copied by remember(id) { mutableStateOf(false) } val scope = rememberCoroutineScope() + val clipboard = LocalClipboardManager.current Row( modifier = Modifier @@ -173,7 +176,7 @@ fun Author( style = MaterialTheme.typography.body2, modifier = Modifier.handMouseClickable { scope.launch { - copyInBrowser(id.name) + clipboard.setText(AnnotatedString(id.name)) copied = true delay(2000) // 2s copied = false diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt index dbe918f..3df7476 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt @@ -33,7 +33,7 @@ private const val TAG = "TabViewModel" /** * Contains all the information related to a tab and its subcomponents (smaller composables like the log, branches, * commit changes, etc.). It holds a reference to every view model because this class lives as long as the tab is open (survives - * across full com.jetpackduba.gitnuro.app recompositions), therefore, tab's content can be recreated with these view models. + * across full app recompositions), therefore, tab's content can be recreated with these view models. */ class TabViewModel @Inject constructor( val logViewModel: LogViewModel,