Variable import moved into its own function
This commit is contained in:
parent
33605474b8
commit
68be39056e
1 changed files with 23 additions and 36 deletions
|
@ -163,22 +163,7 @@ pub async fn start_reader(reader: EventReader) {
|
||||||
fn set_environment() -> Environment {
|
fn set_environment() -> Environment {
|
||||||
match env::var("DBUS_SESSION_BUS_ADDRESS") {
|
match env::var("DBUS_SESSION_BUS_ADDRESS") {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let command = Command::new("sh")
|
copy_variables()
|
||||||
.arg("-c")
|
|
||||||
.arg("systemctl --user show-environment")
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
let vars = std::str::from_utf8(command.stdout.as_slice())
|
|
||||||
.unwrap()
|
|
||||||
.split("\n")
|
|
||||||
.collect::<Vec<&str>>();
|
|
||||||
for var in vars {
|
|
||||||
if let Some((variable, value)) = var.split_once("=") {
|
|
||||||
if let Err(env::VarError::NotPresent) = env::var(variable) {
|
|
||||||
env::set_var(variable, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let uid = Command::new("sh").arg("-c").arg("id -u").output().unwrap();
|
let uid = Command::new("sh").arg("-c").arg("id -u").output().unwrap();
|
||||||
|
@ -186,26 +171,7 @@ fn set_environment() -> Environment {
|
||||||
if uid_number != "0" {
|
if uid_number != "0" {
|
||||||
let bus_address = format!("unix:path=/run/user/{}/bus", uid_number);
|
let bus_address = format!("unix:path=/run/user/{}/bus", uid_number);
|
||||||
env::set_var("DBUS_SESSION_BUS_ADDRESS", bus_address);
|
env::set_var("DBUS_SESSION_BUS_ADDRESS", bus_address);
|
||||||
let command = Command::new("sh")
|
copy_variables()
|
||||||
.arg("-c")
|
|
||||||
.arg("systemctl --user show-environment")
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
let vars = std::str::from_utf8(command.stdout.as_slice())
|
|
||||||
.unwrap()
|
|
||||||
.split("\n")
|
|
||||||
.collect::<Vec<&str>>();
|
|
||||||
for var in vars {
|
|
||||||
if let Some((variable, value)) = var.split_once("=") {
|
|
||||||
if let Err(env::VarError::NotPresent) = env::var(variable) {
|
|
||||||
env::set_var(variable, value);
|
|
||||||
} else if variable == "PATH" {
|
|
||||||
let current_path = env::var("PATH").unwrap();
|
|
||||||
let chained_path = format!("{}:{}", value, current_path);
|
|
||||||
env::set_var("PATH", chained_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
println!("Warning: unable to inherit user environment.\n\
|
println!("Warning: unable to inherit user environment.\n\
|
||||||
Launch Makima with 'sudo -E makima' or make sure that your systemd unit is running with the 'User=<username>' parameter.\n");
|
Launch Makima with 'sudo -E makima' or make sure that your systemd unit is running with the 'User=<username>' parameter.\n");
|
||||||
|
@ -275,6 +241,27 @@ fn set_environment() -> Environment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn copy_variables() {
|
||||||
|
let command = Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg("systemctl --user show-environment")
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
let vars = std::str::from_utf8(command.stdout.as_slice())
|
||||||
|
.unwrap()
|
||||||
|
.split("\n")
|
||||||
|
.collect::<Vec<&str>>();
|
||||||
|
for var in vars {
|
||||||
|
if let Some((variable, value)) = var.split_once("=") {
|
||||||
|
if let Err(env::VarError::NotPresent) = env::var(variable) {
|
||||||
|
env::set_var(variable, value);
|
||||||
|
} else if variable == "PATH" {
|
||||||
|
env::set_var("PATH", format!("{}:{}", value, env::var("PATH").unwrap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_event_stream(path: &Path, config: Vec<Config>) -> EventStream {
|
pub fn get_event_stream(path: &Path, config: Vec<Config>) -> EventStream {
|
||||||
let mut device: Device = Device::open(path).expect("Couldn't open device path.");
|
let mut device: Device = Device::open(path).expect("Couldn't open device path.");
|
||||||
match config
|
match config
|
||||||
|
|
Loading…
Add table
Reference in a new issue