feat(mac-utils): implement accessibility methods
This commit is contained in:
parent
355196ea90
commit
9f905fbd36
|
@ -25,4 +25,6 @@ use std::os::raw::c_char;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn mac_utils_get_secure_input_process(pid: *mut i64) -> i32;
|
pub fn mac_utils_get_secure_input_process(pid: *mut i64) -> i32;
|
||||||
pub fn mac_utils_get_path_from_pid(pid: i64, buffer: *mut c_char, size: i32) -> i32;
|
pub fn mac_utils_get_path_from_pid(pid: i64, buffer: *mut c_char, size: i32) -> i32;
|
||||||
|
pub fn mac_utils_check_accessibility() -> i32;
|
||||||
|
pub fn mac_utils_prompt_accessibility() -> i32;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,28 @@ fn get_app_name_from_path(path: &str) -> Option<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn check_accessibility() -> bool {
|
||||||
|
unsafe {
|
||||||
|
if ffi::mac_utils_check_accessibility() > 0 {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn prompt_accessibility() -> bool {
|
||||||
|
unsafe {
|
||||||
|
if ffi::mac_utils_prompt_accessibility() > 0 {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -28,4 +28,10 @@ extern "C" int32_t mac_utils_get_secure_input_process(int64_t *pid);
|
||||||
// Find the executable path corresponding to the given PID, return 0 if no process was found.
|
// Find the executable path corresponding to the given PID, return 0 if no process was found.
|
||||||
extern "C" int32_t mac_utils_get_path_from_pid(int64_t pid, char *buff, int buff_size);
|
extern "C" int32_t mac_utils_get_path_from_pid(int64_t pid, char *buff, int buff_size);
|
||||||
|
|
||||||
|
// Return 1 if the accessibility permissions have been granted, 0 otherwise
|
||||||
|
extern "C" int32_t mac_utils_check_accessibility();
|
||||||
|
|
||||||
|
// Return 1 if the accessibility permissions have been granted, 0 otherwise
|
||||||
|
extern "C" int32_t mac_utils_prompt_accessibility();
|
||||||
|
|
||||||
#endif //ESPANSO_MAC_UTILS_H
|
#endif //ESPANSO_MAC_UTILS_H
|
|
@ -65,4 +65,14 @@ int32_t mac_utils_get_path_from_pid(int64_t pid, char *buff, int buff_size) {
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t mac_utils_check_accessibility() {
|
||||||
|
NSDictionary* opts = @{(__bridge id)kAXTrustedCheckOptionPrompt: @NO};
|
||||||
|
return AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t mac_utils_prompt_accessibility() {
|
||||||
|
NSDictionary* opts = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES};
|
||||||
|
return AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)opts);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user