feat(mac-utils): add methods to show/hide macOS dock icon
This commit is contained in:
parent
40ea11ef94
commit
ddf8a35aeb
|
@ -34,6 +34,7 @@ fn cc_config() {
|
|||
println!("cargo:rustc-link-lib=dylib=c++");
|
||||
println!("cargo:rustc-link-lib=static=espansomacutils");
|
||||
println!("cargo:rustc-link-lib=framework=Cocoa");
|
||||
println!("cargo:rustc-link-lib=framework=Carbon");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -27,4 +27,6 @@ extern "C" {
|
|||
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;
|
||||
pub fn mac_utils_transition_to_foreground_app();
|
||||
pub fn mac_utils_transition_to_background_app();
|
||||
}
|
||||
|
|
|
@ -115,6 +115,20 @@ pub fn prompt_accessibility() -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn convert_to_foreground_app() {
|
||||
unsafe {
|
||||
ffi::mac_utils_transition_to_foreground_app();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn convert_to_background_app() {
|
||||
unsafe {
|
||||
ffi::mac_utils_transition_to_background_app();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(target_os = "macos")]
|
||||
mod tests {
|
||||
|
|
|
@ -34,4 +34,10 @@ 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();
|
||||
|
||||
// When called, convert the current process to a foreground app (showing the dock icon).
|
||||
extern "C" void mac_utils_transition_to_foreground_app();
|
||||
|
||||
// When called, convert the current process to a background app (hide the dock icon).
|
||||
extern "C" void mac_utils_transition_to_background_app();
|
||||
|
||||
#endif //ESPANSO_MAC_UTILS_H
|
|
@ -21,6 +21,7 @@
|
|||
#include <libproc.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Carbon/Carbon.h>
|
||||
|
||||
// Taken (with a few modifications) from the MagicKeys project: https://github.com/zsszatmari/MagicKeys
|
||||
int32_t mac_utils_get_secure_input_process(int64_t *pid) {
|
||||
|
@ -76,3 +77,13 @@ int32_t mac_utils_prompt_accessibility() {
|
|||
NSDictionary* opts = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES};
|
||||
return AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)opts);
|
||||
}
|
||||
|
||||
void mac_utils_transition_to_foreground_app() {
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
}
|
||||
|
||||
void mac_utils_transition_to_background_app() {
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
|
||||
}
|
Loading…
Reference in New Issue
Block a user