use crate::app::window_state::WindowState;
impl WindowState {
pub(crate) fn apply_tmux_session_profile(&mut self, session_name: &str) {
if let Some(ref profile_name) = self.config.tmux_profile {
if let Some(profile) = self.overlay_ui.profile_manager.find_by_name(profile_name) {
let profile_id = profile.id;
let profile_display = profile.name.clone();
crate::debug_info!(
"TMUX",
"Applying configured tmux_profile '{}' for session '{}'",
profile_display,
session_name
);
self.apply_profile_to_gateway_tab(profile_id, &profile_display);
return;
} else {
crate::debug_info!(
"TMUX",
"Configured tmux_profile '{}' not found",
profile_name
);
}
}
if let Some(profile) = self
.overlay_ui
.profile_manager
.find_by_tmux_session(session_name)
{
let profile_id = profile.id;
let profile_display = profile.name.clone();
crate::debug_info!(
"TMUX",
"Auto-switching to profile '{}' for tmux session '{}'",
profile_display,
session_name
);
self.apply_profile_to_gateway_tab(profile_id, &profile_display);
} else {
crate::debug_info!(
"TMUX",
"No profile matches tmux session '{}' - consider adding tmux_session_patterns to a profile",
session_name
);
}
}
pub(crate) fn apply_profile_to_gateway_tab(
&mut self,
profile_id: crate::profile::ProfileId,
profile_name: &str,
) {
let profile_settings = self.overlay_ui.profile_manager.get(&profile_id).map(|p| {
(
p.tab_name.clone(),
p.icon.clone(),
p.badge_text.clone(),
p.command.clone(),
p.command_args.clone(),
)
});
if let Some(gateway_tab_id) = self.tmux_state.tmux_gateway_tab_id
&& let Some(tab) = self.tab_manager.get_tab_mut(gateway_tab_id)
{
tab.profile.auto_applied_profile_id = Some(profile_id);
if let Some((tab_name, icon, badge_text, command, command_args)) = profile_settings {
tab.profile.profile_icon = icon;
if tab.profile.pre_profile_title.is_none() {
tab.profile.pre_profile_title = Some(tab.title.clone());
}
tab.title = tab_name.unwrap_or_else(|| profile_name.to_string());
if let Some(badge_text) = badge_text {
tab.profile.badge_override = Some(badge_text.clone());
crate::debug_info!(
"TMUX",
"Applied badge text '{}' from profile '{}'",
badge_text,
profile_name
);
}
if let Some(cmd) = command {
let mut full_cmd = cmd;
if let Some(args) = command_args {
for arg in args {
full_cmd.push(' ');
full_cmd.push_str(&arg);
}
}
full_cmd.push('\n');
let terminal_clone = std::sync::Arc::clone(&tab.terminal);
self.runtime.spawn(async move {
let term = terminal_clone.write().await;
if let Err(e) = term.write(full_cmd.as_bytes()) {
log::error!("Failed to execute tmux profile command: {}", e);
}
});
}
}
self.show_toast(format!("tmux: Profile '{}' applied", profile_name));
log::info!(
"Applied profile '{}' for tmux session (gateway tab {})",
profile_name,
gateway_tab_id
);
}
if let Some(profile) = self.overlay_ui.profile_manager.get(&profile_id) {
let profile_clone = profile.clone();
self.apply_profile_badge(&profile_clone);
}
}
}