fix: allow logon screen password, on lock screen (#11566)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-04-25 10:37:09 +08:00
committed by GitHub
parent 279fb72a4f
commit 198967ea35
7 changed files with 248 additions and 9 deletions

View File

@@ -491,6 +491,38 @@ pub fn is_prelogin() -> bool {
get_active_userid() == "0"
}
// https://stackoverflow.com/questions/11505255/osx-check-if-the-screen-is-locked
// No "CGSSessionScreenIsLocked" can be found when macOS is not locked.
//
// `ioreg -n Root -d1` returns `"CGSSessionScreenIsLocked"=Yes`
// `ioreg -n Root -d1 -a` returns
// ```
// ...
// <key>CGSSessionScreenIsLocked</key>
// <true/>
// ...
// ```
pub fn is_locked() -> bool {
match std::process::Command::new("ioreg")
.arg("-n")
.arg("Root")
.arg("-d1")
.output()
{
Ok(output) => {
let output_str = String::from_utf8_lossy(&output.stdout);
// Although `"CGSSessionScreenIsLocked"=Yes` was printed on my macOS,
// I also check `"CGSSessionScreenIsLocked"=true` for better compability.
output_str.contains("\"CGSSessionScreenIsLocked\"=Yes")
|| output_str.contains("\"CGSSessionScreenIsLocked\"=true")
}
Err(e) => {
log::error!("Failed to query ioreg for the lock state: {}", e);
false
}
}
}
pub fn is_root() -> bool {
crate::username() == "root"
}