usable backend for terminal launch

This commit is contained in:
Joseph Montanaro committed 2023-08-03 16:35:15 -07:00
1 parent 89bc74e644
commit 890f715388
5 files changed
+103 -77

No files matched your search

+43 -3
View File
@@ -1,4 +1,5 @@
use std::net::Ipv4Addr;
use std::ffi::OsString;
use std::path::PathBuf;
use auto_launch::AutoLaunchBuilder;
@@ -15,7 +16,7 @@ pub struct TermConfig {
// we call it exec because it isn't always the actual path,
// in some cases it's just the name and relies on path-searching
pub exec: PathBuf,
pub args: Vec<String>,
pub args: Vec<OsString>,
}
@@ -31,7 +32,8 @@ pub struct AppConfig {
pub start_minimized: bool,
#[serde(default = "default_start_on_login")]
pub start_on_login: bool,
pub terminal: Option<TermConfig>,
#[serde(default = "default_term_config")]
pub terminal: TermConfig,
}
@@ -43,7 +45,7 @@ impl Default for AppConfig {
rehide_ms: default_rehide_ms(),
start_minimized: default_start_minimized(),
start_on_login: default_start_on_login(),
terminal: None,
terminal: default_term_config(),
}
}
}
@@ -128,6 +130,44 @@ fn default_listen_port() -> u16 {
}
}
fn default_term_config() -> TermConfig {
#[cfg(windows)]
{
if let Ok(path) = which::which("pwsh.exe") {
return TermConfig {
name: exe.into(),
exec: "conhost.exe".into(),
args: vec![path.into_os_string()]
};
}
return TermConfig {
name: "powershell.exe".into(),
exec: "conhost.exe".into(),
args: vec!["powershell.exe".into()]
};
}
#[cfg(unix)]
{
for bin in ["gnome-terminal", "konsole"] {
if let Ok(_) = which::which(bin) {
return TermConfig {
name: bin.into(),
exec: bin.into(),
args: vec![],
}
}
}
return TermConfig {
name: "gnome-terminal".into(),
exec: "gnome-terminal".into(),
args: vec![],
};
}
}
fn default_listen_addr() -> Ipv4Addr { Ipv4Addr::LOCALHOST }
fn default_rehide_ms() -> u64 { 1000 }
// start minimized and on login only in production mode