From 4ecb8f7e4e6c3e4f55bb873b20e74e5c315864c9 Mon Sep 17 00:00:00 2001 From: kosay Date: Sun, 15 Dec 2024 22:15:14 +0900 Subject: [PATCH] feat(clipboard): remove clipboard from render - Removed clipboard initialization from render.rs - Removed clipboard field from WindowInit struct - Updated tabs_dialogs method to create clipboard instance - Added error handling for clipboard creation --- src/workers/render.rs | 3 --- src/workers/render/window.rs | 10 ++++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/workers/render.rs b/src/workers/render.rs index 128a3522..eae740de 100644 --- a/src/workers/render.rs +++ b/src/workers/render.rs @@ -16,7 +16,6 @@ use crossbeam::channel::{Receiver, Sender}; use ratatui::{backend::CrosstermBackend, layout::Direction, Terminal, TerminalOptions, Viewport}; use crate::{ - clipboard::Clipboard, kube::context::{Context, Namespace}, logger, message::Message, @@ -74,14 +73,12 @@ impl Render { fn render(&self) -> Result<()> { let namespace = Rc::new(RefCell::new(Namespace::new())); let context = Rc::new(RefCell::new(Context::new())); - let clipboard = Rc::new(RefCell::new(Clipboard::new(arboard::Clipboard::new()?))); let mut window = WindowInit::new( self.direction, self.tx.clone(), context.clone(), namespace.clone(), - clipboard, ) .build(); diff --git a/src/workers/render/window.rs b/src/workers/render/window.rs index c392ccbc..b55af9b6 100644 --- a/src/workers/render/window.rs +++ b/src/workers/render/window.rs @@ -61,7 +61,6 @@ pub struct WindowInit { tx: Sender, context: Rc>, namespaces: Rc>, - clipboard: Rc>, } impl WindowInit { @@ -70,14 +69,12 @@ impl WindowInit { tx: Sender, context: Rc>, namespaces: Rc>, - clipboard: Rc>, ) -> Self { Self { split_mode, tx, context, namespaces, - clipboard, } } @@ -167,7 +164,12 @@ impl WindowInit { } fn tabs_dialogs(&self) -> (Vec>, Vec>) { - let clipboard = Some(self.clipboard.clone()); + let clipboard = arboard::Clipboard::new() + .inspect_err(|err| { + logger!(error, "Failed to create clipboard. {}", err); + }) + .ok() + .map(|clipboard| Rc::new(RefCell::new(Clipboard::new(clipboard)))); let PodTab { tab: pod_tab,