Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
d19346e732
|
@ -87,6 +87,16 @@ void send_string(const char * string) {
|
||||||
|
|
||||||
// Send the event
|
// Send the event
|
||||||
|
|
||||||
|
// Check if the shift key is down, and if so, release it
|
||||||
|
// To see why: https://github.com/federico-terzi/espanso/issues/279
|
||||||
|
if (CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, 0x38)) {
|
||||||
|
CGEventRef e2 = CGEventCreateKeyboardEvent(NULL, 0x38, false);
|
||||||
|
CGEventPost(kCGHIDEventTap, e2);
|
||||||
|
CFRelease(e2);
|
||||||
|
|
||||||
|
usleep(2000);
|
||||||
|
}
|
||||||
|
|
||||||
// Because of a bug ( or undocumented limit ) of the CGEventKeyboardSetUnicodeString method
|
// Because of a bug ( or undocumented limit ) of the CGEventKeyboardSetUnicodeString method
|
||||||
// the string gets truncated after 20 characters, so we need to send multiple events.
|
// the string gets truncated after 20 characters, so we need to send multiple events.
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>Label</key>
|
<key>Label</key>
|
||||||
<string>com.federicoterzi.espanso</string>
|
<string>com.federicoterzi.espanso</string>
|
||||||
|
<key>EnvironmentVariables</key>
|
||||||
|
<dict>
|
||||||
|
<key>PATH</key>
|
||||||
|
<string>{{{PATH}}}</string>
|
||||||
|
</dict>
|
||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>{{{espanso_path}}}</string>
|
<string>{{{espanso_path}}}</string>
|
||||||
|
|
|
@ -61,6 +61,12 @@ pub fn register(_config_set: ConfigSet) {
|
||||||
espanso_path.to_str().unwrap_or_default(),
|
espanso_path.to_str().unwrap_or_default(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Copy the user PATH variable and inject it in the Plist file so that
|
||||||
|
// it gets loaded by Launchd.
|
||||||
|
// To see why this is necessary: https://github.com/federico-terzi/espanso/issues/233
|
||||||
|
let user_path = std::env::var("PATH").unwrap_or("".to_owned());
|
||||||
|
let plist_content = plist_content.replace("{{{PATH}}}", &user_path);
|
||||||
|
|
||||||
std::fs::write(plist_file.clone(), plist_content).expect("Unable to write plist file");
|
std::fs::write(plist_file.clone(), plist_content).expect("Unable to write plist file");
|
||||||
|
|
||||||
println!("Entry created correctly!")
|
println!("Entry created correctly!")
|
||||||
|
|
|
@ -91,12 +91,6 @@ impl MacSystemManager {
|
||||||
/// 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.
|
||||||
pub fn get_secure_input_application() -> Option<(String, String)> {
|
pub fn get_secure_input_application() -> Option<(String, String)> {
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref APP_REGEX: Regex = Regex::new("/([^/]+).app/").unwrap();
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let pid = MacSystemManager::get_secure_input_pid();
|
let pid = MacSystemManager::get_secure_input_pid();
|
||||||
|
|
||||||
|
@ -112,26 +106,59 @@ impl MacSystemManager {
|
||||||
if let Ok(path) = string {
|
if let Ok(path) = string {
|
||||||
if !path.trim().is_empty() {
|
if !path.trim().is_empty() {
|
||||||
let process = path.trim().to_string();
|
let process = path.trim().to_string();
|
||||||
let caps = APP_REGEX.captures(&process);
|
let app_name = if let Some(name) = Self::get_app_name_from_path(&process) {
|
||||||
let app_name = if let Some(caps) = caps {
|
name
|
||||||
caps.get(1).map_or("", |m| m.as_str()).to_owned()
|
|
||||||
} else {
|
} else {
|
||||||
process.to_owned()
|
process.to_owned()
|
||||||
};
|
};
|
||||||
|
|
||||||
Some((app_name, process))
|
return Some((app_name, process));
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_app_name_from_path(path: &str) -> Option<String> {
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref APP_REGEX: Regex = Regex::new("/([^/]+).(app|bundle)/").unwrap();
|
||||||
|
};
|
||||||
|
|
||||||
|
let caps = APP_REGEX.captures(&path);
|
||||||
|
if let Some(caps) = caps {
|
||||||
|
Some(caps.get(1).map_or("", |m| m.as_str()).to_owned())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_app_name_from_path() {
|
||||||
|
let app_name = MacSystemManager::get_app_name_from_path("/Applications/iTerm.app/Contents/MacOS/iTerm2");
|
||||||
|
assert_eq!(app_name.unwrap(), "iTerm")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_app_name_from_path_no_app_name() {
|
||||||
|
let app_name = MacSystemManager::get_app_name_from_path("/another/directory");
|
||||||
|
assert!(app_name.is_none())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_get_app_name_from_path_security_bundle() {
|
||||||
|
let app_name = MacSystemManager::get_app_name_from_path("/System/Library/Frameworks/Security.framework/Versions/A/MachServices/SecurityAgent.bundle/Contents/MacOS/SecurityAgent");
|
||||||
|
assert_eq!(app_name.unwrap(), "SecurityAgent")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user