Browse Source

Menubar font size and updating mechanism changes.

v1.2.4
Abhishek Banthia 8 years ago
parent
commit
9a4e9eb6e7
  1. 1
      Clocker/MenubarController.h
  2. 47
      Clocker/MenubarController.m

1
Clocker/MenubarController.h

@ -41,6 +41,7 @@
@property (nonatomic, strong, readonly) NSStatusItem *statusItem;
@property (nonatomic, strong, readonly) StatusItemView *statusItemView;
@property (nonatomic, strong) NSTimer *menubarUpdateTimer;
@property (nonatomic, assign) BOOL checkIfMenubarUpdatingWasCancelled;
- (void)setUpTimerForUpdatingMenubar;
- (void)invalidateTimerForMenubar;

47
Clocker/MenubarController.m

@ -6,6 +6,8 @@
#import "ApplicationDelegate.h"
#import "CLTimezoneDataOperations.h"
typedef void (^CompletionType)(void);
@implementation MenubarController
@synthesize statusItemView = _statusItemView;
@ -59,7 +61,7 @@
- (NSTextField *)setUpTextfieldForMenubar
{
NSTextField *textField= [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, STATUS_ITEM_VIEW_WIDTH, 18)];
NSTextField *textField= [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, STATUS_ITEM_VIEW_WIDTH, 22)];
textField.backgroundColor = [NSColor whiteColor];
textField.bordered = NO;
textField.textColor = [NSColor blackColor];
@ -75,18 +77,45 @@
- (void)setUpTimerForUpdatingMenubar
{
self.menubarUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(updateMenubar)
userInfo:nil
repeats:YES];
self.checkIfMenubarUpdatingWasCancelled = NO;
[self tryingSomethingHere];
}
- (void)invalidateTimerForMenubar
- (void)tryingSomethingHere
{
//a block calling itself without the ARC retain warning
__block CompletionType completionBlock = nil;
__block __weak CompletionType weakCompletionBlock = nil;
completionBlock = ^(void) {
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if(!self.checkIfMenubarUpdatingWasCancelled)
{
[self updateMenubar];
weakCompletionBlock = completionBlock;
weakCompletionBlock();
}
});
};
completionBlock();
}
- (void)stoppingTheMenubar
{
self.checkIfMenubarUpdatingWasCancelled = YES;
[self.statusItemView setNeedsDisplay:YES];
[self.menubarUpdateTimer invalidate];
self.menubarUpdateTimer = nil;
}
- (void)invalidateTimerForMenubar
{
[self stoppingTheMenubar];
}
- (NSImage *)convertTextfieldRepresentationToImage:(NSTextField *)textField

Loading…
Cancel
Save