mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 09:09:17 +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)]
|
||||
|
||||
Reference in New Issue
Block a user