From 48262cd9138d68db9b88f299e1a56c44056e914e Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 5 Nov 2021 21:22:35 +0100 Subject: [PATCH] fix(core): block env-path register and service register on macOS if App Translocation is active. Fix #845 --- espanso/src/cli/service/macos.rs | 13 +++++++++++-- espanso/src/path/macos.rs | 10 +++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/espanso/src/cli/service/macos.rs b/espanso/src/cli/service/macos.rs index cbf1b8c..5529c15 100644 --- a/espanso/src/cli/service/macos.rs +++ b/espanso/src/cli/service/macos.rs @@ -17,13 +17,14 @@ * along with espanso. If not, see . */ -use anyhow::Result; -use log::{info, warn}; +use anyhow::{bail, Result}; +use log::{error, info, warn}; use std::process::Command; use std::{fs::create_dir_all, process::ExitStatus}; use thiserror::Error; use crate::cli::util::prevent_running_as_root_on_macos; +use crate::error_eprintln; #[cfg(target_os = "macos")] 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<()> { 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 library_dir = home_dir.join("Library"); let agents_dir = library_dir.join("LaunchAgents"); diff --git a/espanso/src/path/macos.rs b/espanso/src/path/macos.rs index 54674a7..cd0f7c2 100644 --- a/espanso/src/path/macos.rs +++ b/espanso/src/path/macos.rs @@ -21,7 +21,7 @@ use std::path::{Path, PathBuf}; use std::{fs::create_dir_all, io::ErrorKind}; use thiserror::Error; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use log::{error, warn}; 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<()> { + 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 exec_path = std::env::current_exe()?;