aboutsummaryrefslogtreecommitdiffstats
path: root/Low Battery Yup d
diff options
context:
space:
mode:
authorTeddy Wing2016-11-18 22:54:19 -0500
committerTeddy Wing2016-11-18 22:54:19 -0500
commit678f8ca1a961eb9125aa82b7d2277fda4db7f146 (patch)
treeaad4444f63e18aa9b8e10e05874f0612c4f93e7a /Low Battery Yup d
parent7677b59543a8d2edc9a28f77f26ebb02492e2b5c (diff)
downloadLow-Battery-Yup-678f8ca1a961eb9125aa82b7d2277fda4db7f146.tar.bz2
Use hard-coded hotkey to invoke battery dialog dismisser
* Add DDHotKey library to the project. Just copy the files in from the latest HEAD@e0481f648e0bc7e55d183622b00510b6721152d8. * Only add DDHotKeyCenter.{h,m} & DDHotKeyUtilities.{h,m} to the "Low Battery Yup.d" target as the *TextField file is only useful for a UI to choose a hotkey, and we don't have a UI in this target. * Set the DDHotKey* files to use ARC when compiling since they require it. This was done by going to Build Phases -> Compile Sources and adding this flag for both files: -fobj-arc this I figured out thanks to the following SO post: http://stackoverflow.com/questions/6448874/disable-automatic-reference-counting-for-some-files/10255815#10255815 * Link Carbon.framework because DDHotKey depends on it to register global hotkeys * Move our mouse moving & clicking code to a new method that gets used as the global hotkey action * Fix a runtime error caused by MainMenu.xib not being available (as a result of f0e8b5188e6fb984511eb01849380669e69632a6). To do this, we modify `main.m` to bypass the check for MainMenu.xib as described in this SO post: http://stackoverflow.com/questions/6945872/cocoa-app-without-a-mainmenu-xib/6946016#6946016 * Delete the `window` `IBOutlet` since we no longer have a MainMenu.xib and don't have a window in this app.
Diffstat (limited to 'Low Battery Yup d')
-rw-r--r--Low Battery Yup d/AppDelegate.h2
-rw-r--r--Low Battery Yup d/AppDelegate.m12
-rw-r--r--Low Battery Yup d/main.m6
3 files changed, 18 insertions, 2 deletions
diff --git a/Low Battery Yup d/AppDelegate.h b/Low Battery Yup d/AppDelegate.h
index ab9467b..10f6e4b 100644
--- a/Low Battery Yup d/AppDelegate.h
+++ b/Low Battery Yup d/AppDelegate.h
@@ -10,6 +10,6 @@
@interface AppDelegate : NSObject <NSApplicationDelegate>
-@property (assign) IBOutlet NSWindow *window;
+- (void)dismissLowBatteryWarning:(NSEvent *)hotKeyEvent;
@end
diff --git a/Low Battery Yup d/AppDelegate.m b/Low Battery Yup d/AppDelegate.m
index 0a7d2a3..51c1626 100644
--- a/Low Battery Yup d/AppDelegate.m
+++ b/Low Battery Yup d/AppDelegate.m
@@ -7,7 +7,9 @@
//
#import "AppDelegate.h"
+#import "DDHotKeyCenter.h"
#import "Mouse.h"
+#import <Carbon/Carbon.h>
@implementation AppDelegate
@@ -18,6 +20,16 @@
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
+ DDHotKeyCenter *hotkey_center = [DDHotKeyCenter sharedHotKeyCenter];
+ [hotkey_center registerHotKeyWithKeyCode:kVK_ANSI_0
+ modifierFlags:(NSCommandKeyMask | NSAlternateKeyMask | NSShiftKeyMask | NSControlKeyMask)
+ target:self
+ action:@selector(dismissLowBatteryWarning:)
+ object:nil];
+}
+
+- (void)dismissLowBatteryWarning:(NSEvent *)hotKeyEvent
+{
Mouse *m = [[Mouse alloc] init];
[m moveToLowBatteryOK];
[m click];
diff --git a/Low Battery Yup d/main.m b/Low Battery Yup d/main.m
index a58a570..dbd48d9 100644
--- a/Low Battery Yup d/main.m
+++ b/Low Battery Yup d/main.m
@@ -7,8 +7,12 @@
//
#import <Cocoa/Cocoa.h>
+#import "AppDelegate.h"
int main(int argc, char *argv[])
{
- return NSApplicationMain(argc, (const char **)argv);
+ AppDelegate *delegate = [[AppDelegate alloc] init];
+ [[NSApplication sharedApplication] setDelegate:delegate];
+ [NSApp run];
+ return EXIT_SUCCESS;
}