From b899c81d19dfc2a27820197396e25f8ae4709b07 Mon Sep 17 00:00:00 2001 From: g4c Date: Mon, 30 Aug 2021 16:12:59 +0800 Subject: [PATCH] create gui when attach to exist session --- mux/src/tmux.rs | 23 +++++++++++++---------- mux/src/tmux_commands.rs | 6 ++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/mux/src/tmux.rs b/mux/src/tmux.rs index ed1768bea..d25aea3bb 100644 --- a/mux/src/tmux.rs +++ b/mux/src/tmux.rs @@ -98,16 +98,7 @@ impl TmuxDomainState { } } Event::WindowAdd { window: _ } => { - if self.gui_window.borrow().is_none() { - if let Some(mux) = Mux::get() { - let window_builder = mux.new_empty_window(); - log::info!("Tmux create window id {}", window_builder.window_id); - { - let mut window_id = self.gui_window.borrow_mut(); - *window_id = Some(window_builder); // keep the builder so it won't be purged - } - } - } + self.create_gui_window(); } Event::SessionChanged { session, name: _ } => { *self.tmux_session.borrow_mut() = Some(*session); @@ -147,6 +138,18 @@ impl TmuxDomainState { *self.state.borrow_mut() = State::WaitingForResponse; } } + + pub fn create_gui_window(&self) { + if self.gui_window.borrow().is_none() { + let mux = Mux::get().expect("should be call at main thread"); + let window_builder = mux.new_empty_window(); + log::info!("Tmux create window id {}", window_builder.window_id); + { + let mut window_id = self.gui_window.borrow_mut(); + *window_id = Some(window_builder); // keep the builder so it won't be purged + } + }; + } } impl TmuxDomain { diff --git a/mux/src/tmux_commands.rs b/mux/src/tmux_commands.rs index 5305eb067..ae184d451 100644 --- a/mux/src/tmux_commands.rs +++ b/mux/src/tmux_commands.rs @@ -146,11 +146,12 @@ impl TmuxDomainState { let tab = Rc::new(Tab::new(&size)); tab.assign_pane(&local_pane); + self.create_gui_window(); let mut gui_window = self.gui_window.borrow_mut(); let gui_window_id = match gui_window.as_mut() { - Some(x) => &mut *x, + Some(x) => x, None => { - anyhow::bail!("None tmux GUI window created") + anyhow::bail!("No tmux gui created"); } }; @@ -159,6 +160,7 @@ impl TmuxDomainState { gui_window_id.notify(); self.add_attached_pane(&pane, &tab.tab_id())?; + log::info!("new pane attached"); } Ok(()) }