fix(plugins): do not allow attaching to the same session (#3674)

This commit is contained in:
Aram Drevekenin 2024-10-14 14:48:49 +02:00 committed by GitHub
parent 90433932bc
commit cc04ec6ba4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -983,52 +983,58 @@ pub fn start_server(mut os_input: Box<dyn ServerOsApi>, socket_path: PathBuf) {
); );
}, },
ServerInstruction::SwitchSession(mut connect_to_session, client_id) => { ServerInstruction::SwitchSession(mut connect_to_session, client_id) => {
let layout_dir = session_data let current_session_name = envs::get_session_name();
.read() if connect_to_session.name == current_session_name.ok() {
.unwrap() log::error!("Cannot attach to same session");
.as_ref() } else {
.unwrap() let layout_dir = session_data
.session_configuration .read()
.get_client_configuration(&client_id) .unwrap()
.options .as_ref()
.layout_dir .unwrap()
.or_else(|| default_layout_dir()); .session_configuration
if let Some(layout_dir) = layout_dir { .get_client_configuration(&client_id)
connect_to_session.apply_layout_dir(&layout_dir); .options
} .layout_dir
if let Some(min_size) = session_state.read().unwrap().min_client_terminal_size() { .or_else(|| default_layout_dir());
if let Some(layout_dir) = layout_dir {
connect_to_session.apply_layout_dir(&layout_dir);
}
if let Some(min_size) = session_state.read().unwrap().min_client_terminal_size()
{
session_data
.write()
.unwrap()
.as_ref()
.unwrap()
.senders
.send_to_screen(ScreenInstruction::TerminalResize(min_size))
.unwrap();
}
session_data session_data
.write() .write()
.unwrap() .unwrap()
.as_ref() .as_ref()
.unwrap() .unwrap()
.senders .senders
.send_to_screen(ScreenInstruction::TerminalResize(min_size)) .send_to_screen(ScreenInstruction::RemoveClient(client_id))
.unwrap(); .unwrap();
session_data
.write()
.unwrap()
.as_ref()
.unwrap()
.senders
.send_to_plugin(PluginInstruction::RemoveClient(client_id))
.unwrap();
send_to_client!(
client_id,
os_input,
ServerToClientMsg::SwitchSession(connect_to_session),
session_state
);
remove_client!(client_id, os_input, session_state);
} }
session_data
.write()
.unwrap()
.as_ref()
.unwrap()
.senders
.send_to_screen(ScreenInstruction::RemoveClient(client_id))
.unwrap();
session_data
.write()
.unwrap()
.as_ref()
.unwrap()
.senders
.send_to_plugin(PluginInstruction::RemoveClient(client_id))
.unwrap();
send_to_client!(
client_id,
os_input,
ServerToClientMsg::SwitchSession(connect_to_session),
session_state
);
remove_client!(client_id, os_input, session_state);
}, },
ServerInstruction::AssociatePipeWithClient { pipe_id, client_id } => { ServerInstruction::AssociatePipeWithClient { pipe_id, client_id } => {
session_state session_state