aboutsummaryrefslogtreecommitdiffstats
path: root/Low Battery Yup d/AppDelegate.m
blob: c47df1819c1af8406dfd9d00845d6b0b94041235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
//  AppDelegate.m
//  Low Battery Yup.d
//
//  Created by TW on 11/16/16.
//  Copyright (c) 2016 TW. All rights reserved.
//

#import "AppDelegate.h"
#import "DDHotKeyCenter.h"
#import <Carbon/Carbon.h>
#import "Constants.h"

@implementation AppDelegate

- (void)dealloc
{
	[_mouse release];
	[super dealloc];
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
	_mouse = [[Mouse alloc] init];

	[[NSUserDefaults standardUserDefaults] addSuiteNamed:@"com.teddywing.Low-Battery-Yup"];
	NSDictionary *shortcut = [[NSUserDefaults standardUserDefaults] objectForKey:kPreferenceGlobalShortcut];

	if (shortcut) {
		DDHotKeyCenter *hotkey_center = [DDHotKeyCenter sharedHotKeyCenter];
		[hotkey_center registerHotKeyWithKeyCode:[[shortcut objectForKey:@"keyCode"] unsignedIntegerValue]
			modifierFlags:[[shortcut objectForKey:@"modifierFlags"] unsignedIntegerValue]
			target:self
			action:@selector(dismissLowBatteryWarning:)
			object:nil];
	}
}

- (void)dismissLowBatteryWarning:(NSEvent *)hotKeyEvent
{
	[_mouse moveToLowBatteryOK];
	[_mouse click];
}

@end