Skip to content

Commit

Permalink
feat(clipboard): remove clipboard from render
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
sarub0b0 committed Dec 15, 2024
1 parent ff3f1f2 commit 4ecb8f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/workers/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down
10 changes: 6 additions & 4 deletions src/workers/render/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ pub struct WindowInit {
tx: Sender<Message>,
context: Rc<RefCell<Context>>,
namespaces: Rc<RefCell<Namespace>>,
clipboard: Rc<RefCell<Clipboard>>,
}

impl WindowInit {
Expand All @@ -70,14 +69,12 @@ impl WindowInit {
tx: Sender<Message>,
context: Rc<RefCell<Context>>,
namespaces: Rc<RefCell<Namespace>>,
clipboard: Rc<RefCell<Clipboard>>,
) -> Self {
Self {
split_mode,
tx,
context,
namespaces,
clipboard,
}
}

Expand Down Expand Up @@ -167,7 +164,12 @@ impl WindowInit {
}

fn tabs_dialogs(&self) -> (Vec<Tab<'static>>, Vec<Dialog<'static>>) {
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,
Expand Down

0 comments on commit 4ecb8f7

Please sign in to comment.