Skip to content

Commit b4847f6

Browse files
committed
First commit
0 parents  commit b4847f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3311
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.Trashes
3+
*.swp
4+
*~.nib
5+
xcuserdata

Clock Bar App/AppDelegate.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#import <Cocoa/Cocoa.h>
2+
3+
@interface AppDelegate : NSObject <NSApplicationDelegate>
4+
5+
@property (weak) IBOutlet NSMenu *statusMenu;
6+
@property (strong, nonatomic) NSStatusItem *statusBar;
7+
8+
- (IBAction)prefsMenuItemAction:(id)sender;
9+
10+
- (IBAction)quitMenuItemAction:(id)sender;
11+
12+
@property (weak) IBOutlet NSMenuItem *muteMenuItem;
13+
14+
- (void) hideMenuBar:(BOOL)enableState;
15+
- (void) changeColor:(id)sender;
16+
- (NSColor*)colorWithHexColorString:(NSString*)inColorString;
17+
18+
19+
@end
20+

Clock Bar App/AppDelegate.m

+239
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#import "AppDelegate.h"
2+
#import "TouchBar.h"
3+
#import <ServiceManagement/ServiceManagement.h>
4+
#import "TouchButton.h"
5+
#import "TouchDelegate.h"
6+
#import <Cocoa/Cocoa.h>
7+
8+
static const NSTouchBarItemIdentifier muteIdentifier = @"ns.clock";
9+
static NSString *const MASCustomShortcutKey = @"customShortcut";
10+
11+
@interface AppDelegate () <TouchDelegate>
12+
13+
@end
14+
15+
@implementation AppDelegate
16+
17+
NSButton *touchBarButton;
18+
19+
@synthesize statusBar;
20+
21+
TouchButton *button;
22+
23+
NSString *STATUS_ICON_BLACK = @"clock-64";
24+
25+
NSDateFormatter *timeformatter;
26+
NSString *format = @"hh:mm";
27+
NSMutableAttributedString *colorTitle;
28+
29+
30+
- (void) awakeFromNib {
31+
32+
BOOL hideStatusBar = NO;
33+
BOOL statusBarButtonToggle = NO;
34+
BOOL useAlternateStatusBarIcons = NO;
35+
36+
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"hide_status_bar"] != nil) {
37+
hideStatusBar = [[NSUserDefaults standardUserDefaults] boolForKey:@"hide_status_bar"];
38+
}
39+
40+
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"status_bar_button_toggle"] != nil) {
41+
statusBarButtonToggle = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_button_toggle"];
42+
}
43+
44+
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"status_bar_alternate_icons"] != nil) {
45+
useAlternateStatusBarIcons = [[NSUserDefaults standardUserDefaults] boolForKey:@"status_bar_alternate_icons"];
46+
}
47+
48+
[[NSUserDefaults standardUserDefaults] setBool:hideStatusBar forKey:@"hide_status_bar"];
49+
[[NSUserDefaults standardUserDefaults] setBool:statusBarButtonToggle forKey:@"status_bar_button_toggle"];
50+
[[NSUserDefaults standardUserDefaults] setBool:useAlternateStatusBarIcons forKey:@"status_bar_alternate_icons"];
51+
52+
if (!hideStatusBar) {
53+
[self setupStatusBarItem];
54+
}
55+
56+
}
57+
58+
- (void) setupStatusBarItem {
59+
60+
self.statusBar = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
61+
self.statusBar.menu = self.statusMenu;
62+
63+
NSImage* statusImage = [self getStatusBarImage];
64+
65+
statusImage.size = NSMakeSize(18, 18);
66+
67+
[statusImage setTemplate:YES];
68+
69+
self.statusBar.image = statusImage;
70+
self.statusBar.highlightMode = YES;
71+
self.statusBar.enabled = YES;
72+
}
73+
74+
75+
- (void) hideMenuBar: (BOOL) enableState {
76+
77+
if (!enableState) {
78+
[self setupStatusBarItem];
79+
} else {
80+
self.statusBar = nil;
81+
}
82+
}
83+
84+
85+
-(void)changeColor:(id)sender
86+
{
87+
88+
[colorTitle addAttribute:NSForegroundColorAttributeName value:sender range:NSMakeRange(0, button.title.length)];
89+
[button setAttributedTitle:colorTitle];
90+
}
91+
92+
-(void)UpdateTime:(id)sender
93+
{
94+
NSString *time = [timeformatter stringFromDate:[NSDate date]];
95+
[colorTitle.mutableString setString:time];
96+
[button setAttributedTitle:colorTitle];
97+
}
98+
99+
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
100+
[[[[NSApplication sharedApplication] windows] lastObject] close];
101+
102+
DFRSystemModalShowsCloseBoxWhenFrontMost(YES);
103+
104+
timeformatter = [[NSDateFormatter alloc] init];
105+
[timeformatter setTimeStyle: NSDateFormatterShortStyle];
106+
[timeformatter setDateFormat:format];
107+
108+
NSDate *now = [NSDate date];
109+
NSString *newDateString = [timeformatter stringFromDate:now];
110+
111+
112+
button = [TouchButton buttonWithTitle:newDateString target:nil action:nil];
113+
[button setDelegate: self];
114+
115+
NSFont *systemFont = [NSFont systemFontOfSize:14.0f];
116+
NSDictionary * fontAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:systemFont, NSFontAttributeName, nil];
117+
118+
colorTitle = [[NSMutableAttributedString alloc] initWithString:[button title] attributes:fontAttributes];
119+
120+
NSString *colorString = [[NSUserDefaults standardUserDefaults] objectForKey:@"clock_color"];
121+
NSColor *color = nil;
122+
if (colorString == nil){
123+
color = [NSColor whiteColor];
124+
} else{
125+
color = [self getColorForString:colorString];
126+
}
127+
128+
[colorTitle addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, button.title.length)];
129+
[button setAttributedTitle:colorTitle];
130+
131+
132+
NSCustomTouchBarItem *time = [[NSCustomTouchBarItem alloc] initWithIdentifier:muteIdentifier];
133+
time.view = button;
134+
[NSTouchBarItem addSystemTrayItem:time];
135+
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(UpdateTime:) userInfo:nil repeats:YES];
136+
137+
touchBarButton = button;
138+
139+
[NSTouchBarItem addSystemTrayItem:time];
140+
DFRElementSetControlStripPresenceForIdentifier(muteIdentifier, YES);
141+
142+
[self enableLoginAutostart];
143+
144+
}
145+
146+
-(NSColor*)getColorForString:(id)sender{
147+
return [self colorWithHexColorString:sender];
148+
}
149+
150+
151+
- (NSImage*) getStatusBarImage {
152+
153+
return [NSImage imageNamed:STATUS_ICON_BLACK];
154+
}
155+
156+
157+
-(void) enableLoginAutostart {
158+
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"auto_login"] == nil) {
159+
return;
160+
}
161+
162+
BOOL state = [[NSUserDefaults standardUserDefaults] boolForKey:@"auto_login"];
163+
if(!SMLoginItemSetEnabled((__bridge CFStringRef)@"Nihalsharma.Clock-Launcher", !state)) {
164+
NSLog(@"The login was not succesfull");
165+
}
166+
}
167+
168+
- (void)applicationWillTerminate:(NSNotification *)aNotification {
169+
}
170+
171+
-(double) changeState {
172+
return 0;
173+
}
174+
175+
-(double) changeStateFixed {
176+
return 0;
177+
}
178+
179+
-(NSColor *)colorState:(double)volume {
180+
181+
if(!volume) {
182+
return NSColor.redColor;
183+
} else {
184+
return NSColor.clearColor;
185+
}
186+
}
187+
188+
- (void)onPressed:(TouchButton*)sender
189+
{
190+
NSLog(@"On Press clicked");
191+
if ([format isEqual:@"hh:mm"]){
192+
format = @"HH:mm";
193+
} else {
194+
format = @"hh:mm";
195+
}
196+
[timeformatter setDateFormat:format];
197+
}
198+
199+
- (void)onLongPressed:(TouchButton*)sender
200+
{
201+
[[[[NSApplication sharedApplication] windows] lastObject] makeKeyAndOrderFront:nil];
202+
[[NSApplication sharedApplication] activateIgnoringOtherApps:true];
203+
}
204+
205+
- (IBAction)prefsMenuItemAction:(id)sender {
206+
207+
[self onLongPressed:sender];
208+
}
209+
210+
- (IBAction)quitMenuItemAction:(id)sender {
211+
[NSApp terminate:nil];
212+
}
213+
214+
- (NSColor*)colorWithHexColorString:(NSString*)inColorString
215+
{
216+
NSColor* result = nil;
217+
unsigned colorCode = 0;
218+
unsigned char redByte, greenByte, blueByte;
219+
220+
if (nil != inColorString)
221+
{
222+
NSScanner* scanner = [NSScanner scannerWithString:inColorString];
223+
(void) [scanner scanHexInt:&colorCode]; // ignore error
224+
}
225+
redByte = (unsigned char)(colorCode >> 16);
226+
greenByte = (unsigned char)(colorCode >> 8);
227+
blueByte = (unsigned char)(colorCode); // masks off high bits
228+
229+
result = [NSColor
230+
colorWithCalibratedRed:(CGFloat)redByte / 0xff
231+
green:(CGFloat)greenByte / 0xff
232+
blue:(CGFloat)blueByte / 0xff
233+
alpha:1.0];
234+
return result;
235+
}
236+
237+
238+
239+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"images" : [
3+
{
4+
"size" : "16x16",
5+
"idiom" : "mac",
6+
"filename" : "clock-16.png",
7+
"scale" : "1x"
8+
},
9+
{
10+
"size" : "16x16",
11+
"idiom" : "mac",
12+
"filename" : "clock-32.png",
13+
"scale" : "2x"
14+
},
15+
{
16+
"size" : "32x32",
17+
"idiom" : "mac",
18+
"filename" : "clock-33.png",
19+
"scale" : "1x"
20+
},
21+
{
22+
"size" : "32x32",
23+
"idiom" : "mac",
24+
"filename" : "clock-64.png",
25+
"scale" : "2x"
26+
},
27+
{
28+
"size" : "128x128",
29+
"idiom" : "mac",
30+
"filename" : "clock-128.png",
31+
"scale" : "1x"
32+
},
33+
{
34+
"size" : "128x128",
35+
"idiom" : "mac",
36+
"filename" : "clock-257.png",
37+
"scale" : "2x"
38+
},
39+
{
40+
"size" : "256x256",
41+
"idiom" : "mac",
42+
"filename" : "clock-256.png",
43+
"scale" : "1x"
44+
},
45+
{
46+
"size" : "256x256",
47+
"idiom" : "mac",
48+
"filename" : "clock-514.png",
49+
"scale" : "2x"
50+
},
51+
{
52+
"size" : "512x512",
53+
"idiom" : "mac",
54+
"filename" : "clock-512.png",
55+
"scale" : "1x"
56+
},
57+
{
58+
"size" : "512x512",
59+
"idiom" : "mac",
60+
"filename" : "clock-513.png",
61+
"scale" : "2x"
62+
}
63+
],
64+
"info" : {
65+
"version" : 1,
66+
"author" : "xcode"
67+
}
68+
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "clock-64.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "clock-65.png",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"filename" : "clock-66.png",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
}
23+
}
Loading
Loading
Loading

0 commit comments

Comments
 (0)