feat(mac-utils): add methods to start and stop headless eventloops
This commit is contained in:
parent
12ba0b8755
commit
806ac8112e
|
@ -29,4 +29,6 @@ extern "C" {
|
||||||
pub fn mac_utils_prompt_accessibility() -> i32;
|
pub fn mac_utils_prompt_accessibility() -> i32;
|
||||||
pub fn mac_utils_transition_to_foreground_app();
|
pub fn mac_utils_transition_to_foreground_app();
|
||||||
pub fn mac_utils_transition_to_background_app();
|
pub fn mac_utils_transition_to_background_app();
|
||||||
|
pub fn mac_utils_start_headless_eventloop();
|
||||||
|
pub fn mac_utils_exit_headless_eventloop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,20 @@ pub fn convert_to_background_app() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn start_headless_eventloop() {
|
||||||
|
unsafe {
|
||||||
|
ffi::mac_utils_start_headless_eventloop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn exit_headless_eventloop() {
|
||||||
|
unsafe {
|
||||||
|
ffi::mac_utils_exit_headless_eventloop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -40,4 +40,8 @@ extern "C" void mac_utils_transition_to_foreground_app();
|
||||||
// When called, convert the current process to a background app (hide the dock icon).
|
// When called, convert the current process to a background app (hide the dock icon).
|
||||||
extern "C" void mac_utils_transition_to_background_app();
|
extern "C" void mac_utils_transition_to_background_app();
|
||||||
|
|
||||||
|
// Start and stop a "headless" eventloop to receive NSApplication events.
|
||||||
|
extern "C" void mac_utils_start_headless_eventloop();
|
||||||
|
extern "C" void mac_utils_exit_headless_eventloop();
|
||||||
|
|
||||||
#endif //ESPANSO_MAC_UTILS_H
|
#endif //ESPANSO_MAC_UTILS_H
|
|
@ -88,4 +88,16 @@ void mac_utils_transition_to_foreground_app() {
|
||||||
void mac_utils_transition_to_background_app() {
|
void mac_utils_transition_to_background_app() {
|
||||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||||
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
|
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mac_utils_start_headless_eventloop() {
|
||||||
|
NSApplication * application = [NSApplication sharedApplication];
|
||||||
|
[NSApp run];
|
||||||
|
}
|
||||||
|
|
||||||
|
void mac_utils_exit_headless_eventloop() {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^(void) {
|
||||||
|
[NSApp stop:nil];
|
||||||
|
[NSApp abortModal];
|
||||||
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user