Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ pub fn run() {
connection_appearance::delete_connection_icon,
commands::set_connection_appearance,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(|_app_handle, event| {
if let tauri::RunEvent::Exit = event {
log::info!("Application exiting, stopping all active SSH tunnels...");
crate::ssh_tunnel::stop_all_tunnels();
}
});
}
25 changes: 23 additions & 2 deletions src-tauri/src/ssh_tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ pub fn get_tunnels() -> &'static Mutex<HashMap<String, SshTunnel>> {
TUNNELS.get_or_init(|| Mutex::new(HashMap::new()))
}

fn create_ssh_command() -> Command {
let mut cmd = Command::new("ssh");
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
const CREATE_NO_WINDOW: u32 = 0x08000000;
cmd.creation_flags(CREATE_NO_WINDOW);
}
cmd
}

impl SshTunnel {
pub fn new(
ssh_host: &str,
Expand Down Expand Up @@ -201,7 +212,7 @@ impl SshTunnel {

println!("[SSH Tunnel] Executing: ssh {:?}", args);

let mut command = Command::new("ssh");
let mut command = create_ssh_command();
command
.args(&args)
.stdout(Stdio::piped())
Expand Down Expand Up @@ -535,6 +546,16 @@ impl SshTunnel {
}
}

pub fn stop_all_tunnels() {
if let Some(tunnels) = TUNNELS.get() {
if let Ok(mut guard) = tunnels.lock() {
for (_, tunnel) in guard.drain() {
tunnel.stop();
}
}
}
}

/// Test an SSH connection without creating a tunnel
pub fn test_ssh_connection(
ssh_host: &str,
Expand Down Expand Up @@ -614,7 +635,7 @@ fn test_ssh_connection_system(

println!("[SSH Test] Executing: ssh {:?}", args);

let mut command = Command::new("ssh");
let mut command = create_ssh_command();
command.args(&args);

// Keep the askpass server alive while ssh runs: prompts can arrive at any
Expand Down