macos_accessibility_client/
lib.rs#![allow(non_snake_case)]
pub mod raw {
use core_foundation_sys::dictionary::CFDictionaryRef;
use core_foundation_sys::base::Boolean;
use core_foundation::string::CFStringRef;
extern {
pub static kAXTrustedCheckOptionPrompt: CFStringRef;
pub fn AXIsProcessTrusted() -> Boolean;
pub fn AXIsProcessTrustedWithOptions(theDict: CFDictionaryRef) -> Boolean;
}
}
pub mod accessibility {
use core_foundation::string::CFString;
use core_foundation::dictionary::CFDictionary;
use core_foundation::boolean::CFBoolean;
use core_foundation::base::TCFType;
use crate::raw::{AXIsProcessTrusted, kAXTrustedCheckOptionPrompt, AXIsProcessTrustedWithOptions};
pub fn application_is_trusted() -> bool {
unsafe {
return AXIsProcessTrusted() != 0;
}
}
pub fn application_is_trusted_with_prompt() -> bool {
unsafe {
let option_prompt = CFString::wrap_under_get_rule(kAXTrustedCheckOptionPrompt);
let dict: CFDictionary<CFString, CFBoolean> = CFDictionary::from_CFType_pairs(&[
(option_prompt, CFBoolean::true_value()),
]);
return AXIsProcessTrustedWithOptions(dict.as_concrete_TypeRef()) != 0
}
}
}
#[cfg(test)]
mod tests {
use crate::accessibility::{application_is_trusted, application_is_trusted_with_prompt};
#[test]
fn test_application_is_trusted() {
assert_eq!(false, application_is_trusted());
}
#[test]
fn test_application_is_trusted_with_prompt() {
assert_eq!(false, application_is_trusted_with_prompt());
}
}