fix(core): block env-path register and service register on macOS if App Translocation is active. Fix #845

This commit is contained in:
Federico Terzi 2021-11-05 21:22:35 +01:00
parent 93ce220b62
commit 48262cd913
2 changed files with 20 additions and 3 deletions

View File

@ -17,13 +17,14 @@
* along with espanso. If not, see <https://www.gnu.org/licenses/>. * along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/ */
use anyhow::Result; use anyhow::{bail, Result};
use log::{info, warn}; use log::{error, info, warn};
use std::process::Command; use std::process::Command;
use std::{fs::create_dir_all, process::ExitStatus}; use std::{fs::create_dir_all, process::ExitStatus};
use thiserror::Error; use thiserror::Error;
use crate::cli::util::prevent_running_as_root_on_macos; use crate::cli::util::prevent_running_as_root_on_macos;
use crate::error_eprintln;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
const SERVICE_PLIST_CONTENT: &str = include_str!("../../res/macos/com.federicoterzi.espanso.plist"); const SERVICE_PLIST_CONTENT: &str = include_str!("../../res/macos/com.federicoterzi.espanso.plist");
@ -33,6 +34,14 @@ const SERVICE_PLIST_FILE_NAME: &str = "com.federicoterzi.espanso.plist";
pub fn register() -> Result<()> { pub fn register() -> Result<()> {
prevent_running_as_root_on_macos(); prevent_running_as_root_on_macos();
if crate::cli::util::is_subject_to_app_translocation_on_macos() {
error_eprintln!("Unable to register Espanso as service, please move the Espanso.app bundle inside the /Applications directory to proceed.");
error_eprintln!(
"For more information, please see: https://github.com/federico-terzi/espanso/issues/844"
);
bail!("macOS activated app-translocation on Espanso");
}
let home_dir = dirs::home_dir().expect("could not get user home directory"); let home_dir = dirs::home_dir().expect("could not get user home directory");
let library_dir = home_dir.join("Library"); let library_dir = home_dir.join("Library");
let agents_dir = library_dir.join("LaunchAgents"); let agents_dir = library_dir.join("LaunchAgents");

View File

@ -21,7 +21,7 @@ use std::path::{Path, PathBuf};
use std::{fs::create_dir_all, io::ErrorKind}; use std::{fs::create_dir_all, io::ErrorKind};
use thiserror::Error; use thiserror::Error;
use anyhow::{Context, Result}; use anyhow::{bail, Context, Result};
use log::{error, warn}; use log::{error, warn};
pub fn is_espanso_in_path() -> bool { pub fn is_espanso_in_path() -> bool {
@ -29,6 +29,14 @@ pub fn is_espanso_in_path() -> bool {
} }
pub fn add_espanso_to_path(prompt_when_necessary: bool) -> Result<()> { pub fn add_espanso_to_path(prompt_when_necessary: bool) -> Result<()> {
if crate::cli::util::is_subject_to_app_translocation_on_macos() {
error_eprintln!("Unable to register Espanso to PATH, please move the Espanso.app bundle inside the /Applications directory to proceed.");
error_eprintln!(
"For more information, please see: https://github.com/federico-terzi/espanso/issues/844"
);
bail!("macOS activated app-translocation on Espanso");
}
let target_link_dir = PathBuf::from("/usr/local/bin"); let target_link_dir = PathBuf::from("/usr/local/bin");
let exec_path = std::env::current_exe()?; let exec_path = std::env::current_exe()?;