parent
							
								
									28c7cf1f09
								
							
						
					
					
						commit
						99f4cb96c4
					
				|  | @ -2,22 +2,8 @@ | |||
| 
 | ||||
| @implementation AppDelegate | ||||
| 
 | ||||
| // 10.9+ only, see this url for compatibility: | ||||
| // http://stackoverflow.com/questions/17693408/enable-access-for-assistive-devices-programmatically-on-10-9 | ||||
| BOOL checkAccessibility() | ||||
| { | ||||
|     NSDictionary* opts = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES}; | ||||
|     return AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)opts); | ||||
| } | ||||
| 
 | ||||
| - (void)applicationDidFinishLaunching:(NSNotification *)aNotification | ||||
| { | ||||
|     if (checkAccessibility()) { | ||||
|         NSLog(@"Accessibility Enabled"); | ||||
|     }else { | ||||
|         NSLog(@"Accessibility Disabled"); | ||||
|     } | ||||
| 
 | ||||
|     // Setup status icon | ||||
|     myStatusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; | ||||
| 
 | ||||
|  | @ -31,7 +17,6 @@ BOOL checkAccessibility() | |||
|     [myStatusItem.button setTarget:self]; | ||||
| 
 | ||||
|     // Setup key listener | ||||
|     NSLog(@"registering keydown mask"); | ||||
|     [NSEvent addGlobalMonitorForEventsMatchingMask:(NSEventMaskKeyDown | NSEventMaskFlagsChanged) | ||||
|             handler:^(NSEvent *event){ | ||||
|         if (event.type == NSEventTypeKeyDown | ||||
|  |  | |||
|  | @ -79,6 +79,12 @@ extern "C" void register_context_menu_click_callback(ContextMenuClickCallback ca | |||
| 
 | ||||
| // SYSTEM
 | ||||
| 
 | ||||
| /*
 | ||||
|  * Check if espanso is authorized to control accessibility features, needed to detect key presses. | ||||
|  * @return | ||||
|  */ | ||||
| int32_t check_accessibility(); | ||||
| 
 | ||||
| /*
 | ||||
|  * Return the active NSRunningApplication path | ||||
|  */ | ||||
|  |  | |||
|  | @ -227,4 +227,11 @@ int32_t show_context_menu(MenuItem * items, int32_t count) { | |||
| 
 | ||||
|         [delegate_ptr->myStatusItem popUpStatusItemMenu:espansoMenu]; | ||||
|     }); | ||||
| } | ||||
| } | ||||
| 
 | ||||
| // 10.9+ only, see this url for compatibility: | ||||
| // http://stackoverflow.com/questions/17693408/enable-access-for-assistive-devices-programmatically-on-10-9 | ||||
| int32_t check_accessibility() { | ||||
|     NSDictionary* opts = @{(__bridge id)kAXTrustedCheckOptionPrompt: @YES}; | ||||
|     return AXIsProcessTrustedWithOptions((__bridge CFDictionaryRef)opts); | ||||
| } | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ extern { | |||
|     pub fn eventloop(); | ||||
| 
 | ||||
|     // System
 | ||||
|     pub fn check_accessibility() -> i32; | ||||
|     pub fn get_active_app_bundle(buffer: *mut c_char, size: i32) -> i32; | ||||
|     pub fn get_active_app_identifier(buffer: *mut c_char, size: i32) -> i32; | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ use std::ffi::CString; | |||
| use std::fs; | ||||
| use log::{info, error}; | ||||
| use std::path::PathBuf; | ||||
| use std::process::exit; | ||||
| 
 | ||||
| const STATUS_ICON_BINARY : &'static [u8] = include_bytes!("../res/mac/icon.png"); | ||||
| 
 | ||||
|  | @ -17,6 +18,18 @@ pub struct MacContext { | |||
| 
 | ||||
| impl MacContext { | ||||
|     pub fn new(send_channel: Sender<Event>) -> Box<MacContext> { | ||||
|         // Check accessibility
 | ||||
|         unsafe { | ||||
|             let res = check_accessibility(); | ||||
| 
 | ||||
|             if res == 0 { | ||||
|                 error!("Accessibility must be enabled to make espanso work on MacOS."); | ||||
|                 error!("Please allow espanso in the Security & Privacy panel, then restart espanso."); | ||||
|                 error!("For more information: "); // TODO: add documentation link
 | ||||
|                 exit(1); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         let context = Box::new(MacContext { | ||||
|            send_channel | ||||
|         }); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user