From ce3dd004441a04fc6a43c2cac6b8b4f11d0de1ad Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 9 Mar 2022 10:33:29 -0700 Subject: [PATCH] fix panic when spawning invalid command via reused gui instance refs: #1696 --- wezterm-gui/src/termwindow/clipboard.rs | 8 ++++++-- wezterm-gui/src/termwindow/mod.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/wezterm-gui/src/termwindow/clipboard.rs b/wezterm-gui/src/termwindow/clipboard.rs index 92791b3b1..caa5e7eef 100644 --- a/wezterm-gui/src/termwindow/clipboard.rs +++ b/wezterm-gui/src/termwindow/clipboard.rs @@ -34,7 +34,7 @@ impl wezterm_term::Clipboard for ClipboardHelper { } impl TermWindow { - pub fn setup_clipboard(window: &Window, mux_window_id: MuxWindowId) { + pub fn setup_clipboard(window: &Window, mux_window_id: MuxWindowId) -> anyhow::Result<()> { let clipboard: Arc = Arc::new(ClipboardHelper { window: window.clone(), }); @@ -42,7 +42,9 @@ impl TermWindow { Arc::new(crate::download::Downloader::new()); let mux = Mux::get().unwrap(); - let mut mux_window = mux.get_window_mut(mux_window_id).unwrap(); + let mut mux_window = mux + .get_window_mut(mux_window_id) + .ok_or_else(|| anyhow::anyhow!("mux doesn't know about window yet!?"))?; mux_window.set_clipboard(&clipboard); for tab in mux_window.iter() { @@ -51,6 +53,8 @@ impl TermWindow { pos.pane.set_download_handler(&downloader); } } + + Ok(()) } pub fn copy_to_clipboard(&self, clipboard: ClipboardCopyDestination, text: String) { diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 0d7b37284..8c546837a 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -778,7 +778,7 @@ impl TermWindow { tw.borrow_mut().window.replace(window.clone()); Self::apply_icon(&window)?; - Self::setup_clipboard(&window, mux_window_id); + Self::setup_clipboard(&window, mux_window_id)?; let config_subscription = config::subscribe_to_config_reload({ let window = window.clone();