-
Notifications
You must be signed in to change notification settings - Fork 6
lockscreen: bridge homed users into AccountsService with visibility filtering #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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)] | ||
|
|
@@ -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. | ||
|
|
@@ -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 { | ||
|
|
@@ -208,6 +213,10 @@ | |
| } | ||
| } | ||
| }, | ||
| _ = homed_tick.next() => { | ||
| cache_homed_users(&accounts_proxy, &conn).await; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| }, | ||
| } | ||
| } | ||
| })); | ||
|
|
@@ -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); | ||
|
Comment on lines
+253
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The reconciliation loop only calls 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" | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
| } | ||
There was a problem hiding this comment.
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 ... 👀)?