From 0b75559334510592ba6064bcb66657cdda36b758 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 7 Mar 2021 13:49:24 +0100 Subject: register_hotkeys: Add error handling Fail to start if we can't register hotkeys. --- main.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main.m b/main.m index 87e64c0..c04c2c8 100644 --- a/main.m +++ b/main.m @@ -1,8 +1,12 @@ #import +#include + #import "Invert.h" #import "DDHotKeyCenter.h" +#define E_REGISTER_HOTKEY 5 + int register_hotkeys(); int main(int argc, const char * argv[]) { @@ -11,6 +15,9 @@ int main(int argc, const char * argv[]) { [NSApplication sharedApplication]; int error_code = register_hotkeys(); + if (error_code == E_REGISTER_HOTKEY) { + return EX_SOFTWARE; + } [NSApp run]; @@ -29,7 +36,9 @@ int register_hotkeys() { action:@selector(toggleInvertColors:) object:nil] ) { - NSLog(@"Error registering hotkey"); + NSLog(@"Error registering hotkey Apple+Option+Control-8"); + + return E_REGISTER_HOTKEY; } if ( @@ -39,7 +48,9 @@ int register_hotkeys() { action:@selector(toggleInvertColors:) object:nil] ) { - NSLog(@"Error registering hotkey"); + NSLog(@"Error registering hotkey F8"); + + return E_REGISTER_HOTKEY; } return 0; -- cgit v1.2.3