forked from yujitach/MenuMeters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuMetersMenuExtraBase.m
42 lines (40 loc) · 1.39 KB
/
MenuMetersMenuExtraBase.m
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
//
// NSMenuExtraBase.m
// MenuMeters
//
// Created by Yuji on 2015/08/01.
//
//
#import "MenuMetersMenuExtraBase.h"
@implementation MenuMetersMenuExtraBase
-(instancetype)initWithBundle:(NSBundle*)bundle
{
self=[super initWithBundle:bundle];
return self;
}
-(void)timerFired:(id)notused
{
statusItem.menu=self.menu;
NSImage*canvas=[[NSImage alloc] initWithSize:NSMakeSize(self.length, self.view.frame.size.height)];
[canvas lockFocus];
[self.view drawRect:NSMakeRect(0, 0, canvas.size.width, canvas.size.height)];
[canvas unlockFocus];
statusItem.button.image=canvas;
}
- (void)configDisplay:(NSString*)bundleID fromPrefs:(MenuMeterDefaults*)ourPrefs withTimerInterval:(NSTimeInterval)interval
{
if([ourPrefs loadBoolPref:bundleID defaultValue:YES]){
if(!statusItem){
statusItem=[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
}
[timer invalidate];
timer=[NSTimer timerWithTimeInterval:interval target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
[timer setTolerance:.2*interval];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}else if(![ourPrefs loadBoolPref:bundleID defaultValue:YES] && statusItem){
[timer invalidate];
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
statusItem=nil;
}
}
@end