mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-29 15:29:14 +00:00
fix(gui): set HOME for macOS launchd service (#2509)
Co-authored-by: hezz <hezz@example.com>
This commit is contained in:
@@ -1356,12 +1356,24 @@ mod service {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn service_environment() -> Option<Vec<(String, String)>> {
|
||||
// System LaunchDaemons run as root but launchd does not provide HOME.
|
||||
Some(vec![("HOME".to_string(), "/var/root".to_string())])
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
fn service_environment() -> Option<Vec<(String, String)>> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn install(opts: ServiceOptions) -> anyhow::Result<()> {
|
||||
let service = easytier::service_manager::Service::new(env!("CARGO_PKG_NAME").to_string())?;
|
||||
let options = easytier::service_manager::ServiceInstallOptions {
|
||||
program: super::get_exe_path().into(),
|
||||
args: opts.to_args_vec(),
|
||||
work_directory: std::env::current_dir()?,
|
||||
environment: service_environment(),
|
||||
disable_autostart: false,
|
||||
description: Some("EasyTier Gui Service".to_string()),
|
||||
display_name: Some("EasyTier Gui Service".to_string()),
|
||||
@@ -1397,6 +1409,21 @@ mod service {
|
||||
let service = easytier::service_manager::Service::new(env!("CARGO_PKG_NAME").to_string())?;
|
||||
service.status()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn service_environment_matches_platform() {
|
||||
#[cfg(target_os = "macos")]
|
||||
assert_eq!(
|
||||
super::service_environment(),
|
||||
Some(vec![("HOME".to_string(), "/var/root".to_string())])
|
||||
);
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
assert_eq!(super::service_environment(), None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
|
||||
@@ -3227,6 +3227,7 @@ async fn main() -> Result<(), Error> {
|
||||
program: bin_path,
|
||||
args: bin_args,
|
||||
work_directory: work_dir,
|
||||
environment: None,
|
||||
disable_autostart: install_args.disable_autostart.unwrap_or(false),
|
||||
description: Some(install_args.description),
|
||||
display_name: install_args.display_name,
|
||||
|
||||
@@ -11,6 +11,7 @@ pub struct ServiceInstallOptions {
|
||||
pub program: PathBuf,
|
||||
pub args: Vec<OsString>,
|
||||
pub work_directory: PathBuf,
|
||||
pub environment: Option<Vec<(String, String)>>,
|
||||
pub disable_autostart: bool,
|
||||
pub description: Option<String>,
|
||||
pub display_name: Option<String>,
|
||||
@@ -92,7 +93,7 @@ impl Service {
|
||||
autostart: !options.disable_autostart,
|
||||
username: None,
|
||||
working_directory: Some(options.work_directory.clone()),
|
||||
environment: None,
|
||||
environment: options.environment.clone(),
|
||||
disable_restart_on_failure: options.disable_restart_on_failure,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user