diff --git a/espanso/src/cli/launcher/accessibility.rs b/espanso/src/cli/launcher/accessibility.rs new file mode 100644 index 0000000..faaad80 --- /dev/null +++ b/espanso/src/cli/launcher/accessibility.rs @@ -0,0 +1,38 @@ +/* + * This file is part of espanso. + * + * Copyright (C) 2019-2021 Federico Terzi + * + * espanso is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * espanso is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with espanso. If not, see . + */ + +#[cfg(not(target_os = "macos"))] +pub fn is_accessibility_enabled() -> bool { + true +} + +#[cfg(not(target_os = "macos"))] +pub fn prompt_enable_accessibility() -> bool { + true +} + +#[cfg(target_os = "macos")] +pub fn is_accessibility_enabled() -> bool { + espanso_mac_utils::check_accessibility() +} + +#[cfg(target_os = "macos")] +pub fn prompt_enable_accessibility() -> bool { + espanso_mac_utils::prompt_accessibility() +} \ No newline at end of file diff --git a/espanso/src/cli/launcher/mod.rs b/espanso/src/cli/launcher/mod.rs index bd71640..c303327 100644 --- a/espanso/src/cli/launcher/mod.rs +++ b/espanso/src/cli/launcher/mod.rs @@ -22,6 +22,7 @@ use crate::preferences::Preferences; use super::{CliModule, CliModuleArgs}; +mod accessibility; mod util; // TODO: test also with modulo feature disabled @@ -84,7 +85,7 @@ fn launcher_main(args: CliModuleArgs) -> i32 { }; // TODO: consider also Windows case? let add_to_path_handler = Box::new(move || match util::add_espanso_to_path() { - Ok(_) => true, + Ok(_) => true, Err(error) => { eprintln!("Add to path returned error: {}", error); false @@ -92,11 +93,16 @@ fn launcher_main(args: CliModuleArgs) -> i32 { }); let is_accessibility_page_enabled = if cfg!(target_os = "macos") { - // TODO: add actual check - true + !accessibility::is_accessibility_enabled() } else { false }; + let is_accessibility_enabled_handler = Box::new(move || { + accessibility::is_accessibility_enabled() + }); + let enable_accessibility_handler = Box::new(move || { + accessibility::prompt_enable_accessibility(); + }); let preferences_clone = preferences.clone(); let on_completed_handler = Box::new(move || { @@ -129,18 +135,21 @@ fn launcher_main(args: CliModuleArgs) -> i32 { welcome_image_path: icon_paths .logo_no_background .map(|path| path.to_string_lossy().to_string()), - accessibility_image_1_path: None, // TODO - accessibility_image_2_path: None, // TODO + accessibility_image_1_path: icon_paths + .accessibility_image_1 + .map(|path| path.to_string_lossy().to_string()), + accessibility_image_2_path: icon_paths + .accessibility_image_2 + .map(|path| path.to_string_lossy().to_string()), handlers: WizardHandlers { is_legacy_version_running: Some(is_legacy_version_running_handler), backup_and_migrate: Some(backup_and_migrate_handler), add_to_path: Some(add_to_path_handler), - enable_accessibility: None, // TODO - is_accessibility_enabled: None, // TODO + enable_accessibility: Some(enable_accessibility_handler), + is_accessibility_enabled: Some(is_accessibility_enabled_handler), on_completed: Some(on_completed_handler), }, }); - } // TODO: initialize config directory if not present diff --git a/espanso/src/icon.rs b/espanso/src/icon.rs index 7afdb13..8ae39e5 100644 --- a/espanso/src/icon.rs +++ b/espanso/src/icon.rs @@ -38,6 +38,10 @@ const MAC_BINARY: &[u8] = include_bytes!("res/macos/icon.png"); const MAC_DISABLED_BINARY: &[u8] = include_bytes!("res/macos/icondisabled.png"); #[cfg(target_os = "macos")] const MAC_SYSTEM_DISABLED_BINARY: &[u8] = include_bytes!("res/macos/iconsystemdisabled.png"); +#[cfg(target_os = "macos")] +const MAC_ACCESSIBILITY_1_BINARY: &[u8] = include_bytes!("res/accessibility_1.png"); +#[cfg(target_os = "macos")] +const MAC_ACCESSIBILITY_2_BINARY: &[u8] = include_bytes!("res/accessibility_2.png"); #[derive(Debug, Default)] pub struct IconPaths { @@ -47,7 +51,10 @@ pub struct IconPaths { pub tray_icon_normal: Option, pub tray_icon_disabled: Option, - pub tray_icon_system_disabled: Option, // TODO: secure input + pub tray_icon_system_disabled: Option, + + pub accessibility_image_1: Option, + pub accessibility_image_2: Option, pub logo: Option, pub logo_no_background: Option, @@ -76,6 +83,8 @@ pub fn load_icon_paths(runtime_dir: &Path) -> Result { tray_icon_system_disabled: Some(extract_icon(MAC_SYSTEM_DISABLED_BINARY, &runtime_dir.join("systemdisabled.png"))?), logo: Some(extract_icon(ICON_BINARY, &runtime_dir.join("icon.png"))?), logo_no_background: Some(extract_icon(LOGO_NO_BACKGROUND_BINARY, &runtime_dir.join("icon_no_background.png"))?), + accessibility_image_1: Some(extract_icon(MAC_ACCESSIBILITY_1_BINARY, &runtime_dir.join("accessibility_1.png"))?), + accessibility_image_2: Some(extract_icon(MAC_ACCESSIBILITY_2_BINARY, &runtime_dir.join("accessibility_2.png"))?), ..Default::default() }) }