forked from nihalsharma/Clock-Bar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.m
More file actions
138 lines (96 loc) · 4.48 KB
/
Copy pathViewController.m
File metadata and controls
138 lines (96 loc) · 4.48 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#import "ViewController.h"
#import "AppDelegate.h"
#include <ServiceManagement/SMLoginItem.h>
static NSString *const MASCustomShortcutKey = @"customShortcut";
static void *MASObservingContext = &MASObservingContext;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"auto_login"] == nil) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"auto_login"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
BOOL state = [[NSUserDefaults standardUserDefaults] boolForKey:@"auto_login"];
[self.autoLoginState setState: !state];
BOOL hideStatusBarState = [[NSUserDefaults standardUserDefaults] boolForKey:@"hide_status_bar"];
[self.showInMenuBarState setState: hideStatusBarState];
NSLog(@"View Load");
}
-(void)viewDidAppear {
[super viewDidAppear];
[[self.view window] setTitle:@"Clock Bar"];
[[self.view window] center];
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
[[[[NSApplication sharedApplication] windows] lastObject] setTitle:@"Clock Bar"];
}
- (IBAction)quitPressed:(id)sender {
[NSApp terminate:nil]; //TODO or quit about window
}
- (IBAction)onLoginStartChanged:(id)sender {
NSLog(@"Login start changed");
NSInteger state = [self.autoLoginState state];
BOOL enableState = NO;
if(state == NSOnState) {
enableState = YES;
}
if(SMLoginItemSetEnabled((__bridge CFStringRef)@"Nihalsharma.Clock-Launcher", enableState)) {
[[NSUserDefaults standardUserDefaults] setBool:!enableState forKey:@"auto_login"];
}
}
- (IBAction)showMenuBarChanged:(id)sender {
NSInteger state = [self.showInMenuBarState state];
BOOL enableState = NO;
if(state == NSOnState) {
enableState = YES;
}
[[NSUserDefaults standardUserDefaults] setBool:enableState forKey:@"hide_status_bar"];
[[NSUserDefaults standardUserDefaults] synchronize];
AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
[appDelegate hideMenuBar:enableState];
if (enableState == YES) {
NSString *msgText = @"Long press on the Touch Bar Clock Button to show Preferences when the Menu Item is disabled.";
NSAlert* msgBox = [[NSAlert alloc] init] ;
[msgBox setMessageText:msgText];
[msgBox addButtonWithTitle: @"OK"];
[msgBox runModal];
}
}
- (IBAction)whiteButtonClicked:(id)sender {
AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
NSColor *color = [appDelegate colorWithHexColorString:@"FFFFFF"];
[[NSUserDefaults standardUserDefaults] setObject:@"FFFFFF" forKey:@"clock_color"];
[appDelegate changeColor:color];
}
- (IBAction)greenButtonClicked:(id)sender {
AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
NSColor *color = [appDelegate colorWithHexColorString:@"00FF00"];
[[NSUserDefaults standardUserDefaults] setObject:@"00FF00" forKey:@"clock_color"];
[appDelegate changeColor:color];
}
- (IBAction)pinkButtonClicked:(id)sender {
AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
NSColor *color = [appDelegate colorWithHexColorString:@"FE69F3"];
[[NSUserDefaults standardUserDefaults] setObject:@"FE69F3" forKey:@"clock_color"];
[appDelegate changeColor:color];
}
- (IBAction)redButtonClicked:(id)sender {
AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
NSColor *color = [appDelegate colorWithHexColorString:@"FF0000"];
[[NSUserDefaults standardUserDefaults] setObject:@"FF00000" forKey:@"clock_color"];
[appDelegate changeColor:color];
}
- (IBAction)yellowButtonClicked:(id)sender {
AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
NSColor *color = [appDelegate colorWithHexColorString:@"FFFF00"];
[[NSUserDefaults standardUserDefaults] setObject:@"FFFF00" forKey:@"clock_color"];
[appDelegate changeColor:color];
}
- (IBAction)blueButtonClicked:(id)sender {
AppDelegate *appDelegate = (AppDelegate *) [[NSApplication sharedApplication] delegate];
NSColor *color = [appDelegate colorWithHexColorString:@"30E6FF"];
[[NSUserDefaults standardUserDefaults] setObject:@"30E6FF" forKey:@"clock_color"];
[appDelegate changeColor:color];
}
@end