Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,31 @@ pub mod user {
fn xsession(&self) -> zbus::Result<String>;
}
}

pub mod home1_manager {
//! # D-Bus interface proxy for: `org.freedesktop.home1.Manager`
use zbus::proxy;

#[proxy(
interface = "org.freedesktop.home1.Manager",
default_service = "org.freedesktop.home1",
default_path = "/org/freedesktop/home1"
)]
pub trait Manager {
/// ListHomes method
fn list_homes(
&self,
) -> zbus::Result<
Vec<(
String,
u32,
String,
u32,
String,
String,
String,
zbus::zvariant::OwnedObjectPath,
)>,
Comment on lines +273 to +282
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is decidedly ugly - can we encode as a struct? or is there a way to name tuple elements (stupid question but ... 👀)?

>;
}
}
77 changes: 71 additions & 6 deletions src/user_session_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

mod imp {
use crate::dbus::accounts::AccountsProxy;
use crate::dbus::home1_manager::ManagerProxy;
use crate::dbus::user::UserProxy;
use crate::session_object::SessionObject;
use crate::shell::Shell;
use crate::user::User;
Expand All @@ -65,6 +67,8 @@
use libhandy::ActionRow;
use std::cell::{Cell, OnceCell};
use std::sync::OnceLock;
use std::time::Duration;
use zbus::zvariant::OwnedObjectPath;

#[derive(CompositeTemplate, Default, Properties)]
#[properties(wrapper_type = super::UserSessionPage)]
Expand Down Expand Up @@ -170,9 +174,9 @@
glib::spawn_future_local(clone!(@weak self as this, @strong last_user => async move {
let accounts_proxy = AccountsProxy::new(&conn).await.unwrap();

for path in accounts_proxy.list_cached_users().await.unwrap() {
users.append(&User::new(conn.clone(), path.into()));
}
sync_cached_accounts_users(&conn, &accounts_proxy, &users).await;
cache_homed_users(&accounts_proxy, &conn).await;
sync_cached_accounts_users(&conn, &accounts_proxy, &users).await;

// The initial user list has been populated. Select the first item in the list to
// ensure something is selected.
Expand All @@ -188,14 +192,15 @@

this.obj().set_ready(true);

let mut added_stream = accounts_proxy.receive_user_added().await.unwrap();
let mut deleted_stream = accounts_proxy.receive_user_deleted().await.unwrap();
let mut added_stream = accounts_proxy.receive_user_added().await.unwrap().fuse();
let mut deleted_stream = accounts_proxy.receive_user_deleted().await.unwrap().fuse();
let mut homed_tick = glib::interval_stream(Duration::from_secs(2)).fuse();

loop {
select! {
added = added_stream.next() => if let Some(added) = added {
if let Some(path) = added.args().ok().map(|v| v.user) {
users.append(&User::new(conn.clone(), path));
append_user_if_visible(&conn, &users, path.into()).await;
}
},
deleted = deleted_stream.next() => if let Some(deleted) = deleted {
Expand All @@ -208,6 +213,10 @@
}
}
},
_ = homed_tick.next() => {
cache_homed_users(&accounts_proxy, &conn).await;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nar. polling here gives me the ick.

oi can't we, like, ObjectManager our way to success here to get a stream of Home thingies coming and going? idk.

sync_cached_accounts_users(&conn, &accounts_proxy, &users).await;
},
}
}
}));
Expand All @@ -222,4 +231,60 @@
impl WidgetImpl for UserSessionPage {}
impl ContainerImpl for UserSessionPage {}
impl BoxImpl for UserSessionPage {}

async fn sync_cached_accounts_users(
conn: &zbus::Connection,
accounts_proxy: &AccountsProxy<'_>,
users: &ListStore,
) {
if let Ok(paths) = accounts_proxy.list_cached_users().await {
for path in paths {
append_user_if_visible(conn, users, path).await;
}
}
}

async fn cache_homed_users(accounts_proxy: &AccountsProxy<'_>, conn: &zbus::Connection) {
let Ok(homed_proxy) = ManagerProxy::new(conn).await else {
return;
};

if let Ok(homes) = homed_proxy.list_homes().await {
for (username, _, _, _, _, _, _, _) in homes {
if let Err(err) = accounts_proxy.cache_user(&username).await {
glib::warn!("failed to cache homed user {}: {}", username, err);

Check failure on line 255 in src/user_session_page.rs

View workflow job for this annotation

GitHub Actions / build

cannot find value `G_LOG_DOMAIN` in this scope
Comment on lines +253 to +255

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Uncache homed users that disappear from home1

The reconciliation loop only calls CacheUser for names currently returned by ListHomes, but it never calls UncacheUser for homed accounts that were present on a previous tick and are now gone. In a running greeter session, deleting or disabling a homed account can therefore leave a stale cached account visible in the chooser, even though it is no longer managed by home1 and may no longer be loggable. Track previous home1 usernames and uncache entries that disappear.

Useful? React with 👍 / 👎.

}
}
}
}

async fn append_user_if_visible(
conn: &zbus::Connection,
users: &ListStore,
path: OwnedObjectPath,
) {
if !user_path_is_visible(conn, &path).await {
return;
}

for user in users.iter::<User>().flatten() {
if user.path() == path.as_str() {
return;
}
}

users.append(&User::new(conn.clone(), path.into()));
}

async fn user_path_is_visible(conn: &zbus::Connection, path: &OwnedObjectPath) -> bool {
let Ok(user_proxy) = UserProxy::builder(conn).path(path).unwrap().build().await else {
return false;
};

let local_account = user_proxy.local_account().await.unwrap_or(true);
let system_account = user_proxy.system_account().await.unwrap_or(false);
let username = user_proxy.user_name().await.unwrap_or_default();

local_account && !system_account && username != "greetd"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding here is naughty. We need to consult a POSIX thing (idk I assume so you do the thinking around here not me) and get our own uid/username and filter that out.

}
}
Loading
Loading