From 93ce220b6256be96a1c54babf7286488c0afe04c Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 5 Nov 2021 21:11:14 +0100 Subject: [PATCH] fix(core): block the wizard if app has been translocated on macOS. Fix #844 --- espanso/src/cli/launcher/mod.rs | 2 +- espanso/src/cli/util.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/espanso/src/cli/launcher/mod.rs b/espanso/src/cli/launcher/mod.rs index aa77a19..4f40f1e 100644 --- a/espanso/src/cli/launcher/mod.rs +++ b/espanso/src/cli/launcher/mod.rs @@ -72,7 +72,7 @@ fn launcher_main(args: CliModuleArgs) -> i32 { let is_welcome_page_enabled = !preferences.has_completed_wizard(); - let is_move_bundle_page_enabled = false; // TODO + let is_move_bundle_page_enabled = crate::cli::util::is_subject_to_app_translocation_on_macos(); let is_legacy_version_page_enabled = util::is_legacy_version_running(&paths.runtime); let runtime_dir_clone = paths.runtime.clone(); diff --git a/espanso/src/cli/util.rs b/espanso/src/cli/util.rs index 401ce2c..335009a 100644 --- a/espanso/src/cli/util.rs +++ b/espanso/src/cli/util.rs @@ -69,3 +69,17 @@ pub fn prevent_running_as_root_on_macos() { pub fn prevent_running_as_root_on_macos() { // Do nothing on other platforms } + +// This is needed to make sure the app is NOT subject to "App Translocation" on +// macOS, which would make Espanso misbehave on some circumstances. +// For more information, see: https://github.com/federico-terzi/espanso/issues/844 +pub fn is_subject_to_app_translocation_on_macos() -> bool { + if !cfg!(target_os = "macos") { + return false; + } + + let exec_path = std::env::current_exe().expect("unable to extract executable path"); + let exec_path = exec_path.to_string_lossy(); + + exec_path.contains("/private/") +}