-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.mm
46 lines (43 loc) · 1.54 KB
/
main.mm
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
46
#include <Foundation/Foundation.h>
#include <CoreFoundation/CoreFoundation.h>
#import "objc/runtime.h"
extern "C" CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);
const char helpText[] = "Usage:\n - Pause: `timercl pause`\n - Resume: `timercl resume`\n - Cancel: `timercl cancel`\n - Set: `timercl set <seconds>`\n";
int main(int argc, char **argv, char **envp) {
if (argc == 1) {
printf(helpText);
} else if (argc == 2) {
if (strcmp(argv[1], "pause") == 0) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
CFSTR("com.hackingdartmouth.timercl.pause"),
NULL,
NULL,
kCFNotificationDeliverImmediately);
} else if (strcmp(argv[1], "resume") == 0) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
CFSTR("com.hackingdartmouth.timercl.resume"),
NULL,
NULL,
kCFNotificationDeliverImmediately);
} else if (strcmp(argv[1], "cancel") == 0) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
CFSTR("com.hackingdartmouth.timercl.cancel"),
NULL,
NULL,
kCFNotificationDeliverImmediately);
} else {
printf(helpText);
}
} else if (argc == 3) {
if (strcmp(argv[1], "set") == 0) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
CFSTR("com.hackingdartmouth.timercl.set"),
NULL,
(__bridge CFDictionaryRef) @{ @"delay" : [NSString stringWithUTF8String:argv[2]] },
kCFNotificationDeliverImmediately);
} else {
printf(helpText);
}
}
return 0;
}