Skip to content
This repository has been archived by the owner on May 19, 2021. It is now read-only.

Commit

Permalink
fixed user group warnings and removed deprecated Vec::remove_item
Browse files Browse the repository at this point in the history
  • Loading branch information
PonasKovas committed Jul 3, 2020
1 parent 37e64a0 commit 0b78a61
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
24 changes: 16 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ fn main() {
// Parse arguments
let args = Opt::from_args();

// Then make sure the user running this is in the group `wheel`
if !is_user_in_wheel() {
// Then make sure the user running this is in the group `wheel` and `network`
let (in_wheel, in_network) = is_user_in_wheel_and_network();
if !in_wheel {
eprintln!("Warning! You are not in group 'wheel', netctl-tray might not work or work only partially.");
}
if !in_network {
eprintln!("Warning! You are not in group 'network', netctl-tray might not work or work only partially.");
}

let mut state = State {
link_quality: 0,
ping: 0.0,
Expand Down Expand Up @@ -268,31 +273,34 @@ fn profile_notification(
Ok(())
}

fn is_user_in_wheel() -> bool {
fn is_user_in_wheel_and_network() -> (bool, bool) {
let username = match get_current_username() {
Some(s) => s,
None => {
eprintln!("Can't get current user!");
return false;
return (false, false);
}
};

let groups = match get_user_groups(&username, get_current_gid()) {
Some(g) => g,
None => {
eprintln!("Couldn't get the list of groups the user is in.");
return false;
return (false, false);
}
};

// check if in wheel
let mut in_wheel = false;
let mut in_network = false;
for group in groups {
if group.name() == OsStr::new("network") {
return true;
in_network = true;
} else if group.name() == OsStr::new("wheel") {
in_wheel = true;
}
}

false
(in_wheel, in_network)
}

fn get_status_icon(state: &mut State) -> CppBox<QIcon> {
Expand Down
4 changes: 3 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ pub fn inotify_watch(
// Remove the profile
for path in event.paths {
match path.file_name().unwrap().to_str() {
Some(p) => all_profiles.lock().unwrap().remove_item(&p),
Some(p) => {
all_profiles.lock().unwrap().retain(|x| *x != p);
}
None => {
eprintln!(
"Can't convert OsStr to str: {:?}",
Expand Down

0 comments on commit 0b78a61

Please sign in to comment.