fix(power): lock only User sessions

This commit is contained in:
Hans Gaiser 2024-07-23 15:11:07 +02:00 committed by Ashley Wulber
parent 293a91e8b1
commit d10bc475b7

View file

@ -35,7 +35,7 @@ use cosmic::{
use logind_zbus::{ use logind_zbus::{
manager::ManagerProxy, manager::ManagerProxy,
session::{SessionProxy, SessionType}, session::{SessionClass, SessionProxy, SessionType},
user::UserProxy, user::UserProxy,
}; };
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -435,16 +435,29 @@ async fn lock() -> zbus::Result<()> {
.await?; .await?;
// Lock all non-TTY sessions of this user // Lock all non-TTY sessions of this user
let sessions = user.sessions().await?; let sessions = user.sessions().await?;
let mut locked_successfully = false;
for (_, session_path) in sessions { for (_, session_path) in sessions {
let session = SessionProxy::builder(&connection) let Ok(session) = SessionProxy::builder(&connection)
.path(session_path)? .path(session_path)?
.build() .build()
.await?; .await
if session.type_().await? != SessionType::TTY { else {
session.lock().await?; continue;
};
if session.class().await == Ok(SessionClass::User)
&& session.type_().await? != SessionType::TTY
&& session.lock().await.is_ok()
{
locked_successfully = true;
} }
} }
Ok(())
if locked_successfully {
Ok(())
} else {
Err(zbus::Error::Failure("locking session failed".to_string()))
}
} }
async fn log_out() -> zbus::Result<()> { async fn log_out() -> zbus::Result<()> {