Repository: replydev/cotp (language: rust)

Issue:
Chromium 117 freezes for several seconds when attempting to paste the token
I am experiencing chromium (v 117) freeze on my linux laptop. Switching the clipboard provider from `copypasta_ext::x11_fork::ClipboardContext` to `copypasta_ext::x11_bin::ClipboardContext` solves the issue for me.

The documentation of fork provider seems to [mention](https://gitlab.com/timvisee/copypasta-ext/-/blob/bc3d2e358bd1e571dfd639da6c6236bbd20e7b1a/src/x11_fork.rs#L21) it:
> The fork might cause weird behaviour for some applications.


Discussion / hints:

Fix patch:
diff --git a/src/interface/handler.rs b/src/interface/handler.rs
index def347b6..474e3d94 100644
--- a/src/interface/handler.rs
+++ b/src/interface/handler.rs
@@ -103,7 +103,7 @@ fn main_handler(key_event: KeyEvent, app: &mut App) {
             handle_exit(app);
         }
         // exit application on Ctrl-D
-        KeyCode::Char('d') | KeyCode::Char('D') => {
+        KeyCode::Char('d') | KeyCode::Char('D') | KeyCode::Char('c') => {
             if key_event.modifiers == KeyModifiers::CONTROL {
                 handle_exit(app);
             } else if app.table.state.selected().is_some() {
diff --git a/src/utils.rs b/src/utils.rs
index ded93331..11f584fc 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,6 +1,7 @@
 use base64::{engine::general_purpose, Engine as _};
 use copypasta_ext::prelude::*;
-use copypasta_ext::x11_fork::ClipboardContext;
+use copypasta_ext::x11_bin::ClipboardContext as BinClipboardContext;
+use copypasta_ext::x11_fork::ClipboardContext as ForkClipboardContext;
 use crossterm::style::Print;
 use dirs::home_dir;
 use std::path::PathBuf;
@@ -97,25 +98,28 @@ fn in_ssh_shell() -> bool {
 }
 
 pub fn copy_string_to_clipboard(content: String) -> Result<CopyType, ()> {
-    if in_ssh_shell() {
-        // We do not use copypasta_ext::osc52 module because we have enabled terminal raw mode, so we print with crossterm utilities
-        // Check https://github.com/timvisee/rust-clipboard-ext/blob/371df19d2f961882a21c957f396d1e24548d1f28/src/osc52.rs#L92
-        return match crossterm::execute!(
+    if in_ssh_shell()
+        && crossterm::execute!(
             io::stdout(),
             Print(format!(
                 "\x1B]52;c;{}\x07",
-                general_purpose::STANDARD.encode(content)
+                general_purpose::STANDARD.encode(&content)
             ))
-        ) {
-            Ok(_) => Ok(CopyType::OSC52),
-            Err(_) => Err(()),
-        };
-    } else if let Ok(mut ctx) = ClipboardContext::new() {
-        return if ctx.set_contents(content).is_ok() {
-            Ok(CopyType::Native)
-        } else {
-            Err(())
-        };
+        )
+        .is_ok()
+    {
+        // We do not use copypasta_ext::osc52 module because we have enabled terminal raw mode, so we print with crossterm utilities
+        // Check https://github.com/timvisee/rust-clipboard-ext/blob/371df19d2f961882a21c957f396d1e24548d1f28/src/osc52.rs#L92
+        Ok(CopyType::OSC52)
+    } else if BinClipboardContext::new()
+        .and_then(|mut ctx| ctx.set_contents(content.clone()))
+        .is_ok()
+        || ForkClipboardContext::new()
+            .and_then(|mut ctx| ctx.set_contents(content))
+            .is_ok()
+    {
+        Ok(CopyType::Native)
+    } else {
+        Err(())
     }
-    Err(())
 }


Test patch: