fix(mac-utils): fix compilation on non-macOS systems

This commit is contained in:
Federico Terzi 2021-06-09 22:05:28 +02:00
parent 09095a1e8d
commit f266c3c23c
2 changed files with 8 additions and 0 deletions

View File

@ -17,8 +17,10 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
#[cfg(target_os = "macos")]
use std::os::raw::c_char; use std::os::raw::c_char;
#[cfg(target_os = "macos")]
#[link(name = "espansomacutils", kind = "static")] #[link(name = "espansomacutils", kind = "static")]
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;

View File

@ -17,15 +17,18 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
#[cfg(target_os = "macos")]
use std::{ffi::CStr, os::raw::c_char}; use std::{ffi::CStr, os::raw::c_char};
#[macro_use] #[macro_use]
#[cfg(target_os = "macos")]
extern crate lazy_static; extern crate lazy_static;
mod ffi; mod ffi;
/// Check whether an application is currently holding the Secure Input. /// Check whether an application is currently holding the Secure Input.
/// Return None if no application has claimed SecureInput, its PID otherwise. /// Return None if no application has claimed SecureInput, its PID otherwise.
#[cfg(target_os = "macos")]
pub fn get_secure_input_pid() -> Option<i64> { pub fn get_secure_input_pid() -> Option<i64> {
unsafe { unsafe {
let mut pid: i64 = -1; let mut pid: i64 = -1;
@ -41,6 +44,7 @@ pub fn get_secure_input_pid() -> Option<i64> {
/// Check whether an application is currently holding the Secure Input. /// Check whether an application is currently holding the Secure Input.
/// Return None if no application has claimed SecureInput, Some((AppName, AppPath)) otherwise. /// Return None if no application has claimed SecureInput, Some((AppName, AppPath)) otherwise.
#[cfg(target_os = "macos")]
pub fn get_secure_input_application() -> Option<(String, String)> { pub fn get_secure_input_application() -> Option<(String, String)> {
unsafe { unsafe {
let pid = get_secure_input_pid(); let pid = get_secure_input_pid();
@ -73,6 +77,7 @@ pub fn get_secure_input_application() -> Option<(String, String)> {
} }
} }
#[cfg(target_os = "macos")]
fn get_app_name_from_path(path: &str) -> Option<String> { fn get_app_name_from_path(path: &str) -> Option<String> {
use regex::Regex; use regex::Regex;
@ -89,6 +94,7 @@ fn get_app_name_from_path(path: &str) -> Option<String> {
} }
#[cfg(test)] #[cfg(test)]
#[cfg(target_os = "macos")]
mod tests { mod tests {
use super::*; use super::*;