-@interface NSStatusItem (HACKHACKHACKHACK)
-- (id)_initInStatusBar:(NSStatusBar*)statusBar
- withLength:(float)length
- withPriority:(int)priority;
-- (NSStatusBarButton*)_button;
+@implementation ITStatusItemMenuProxy
+
++ (BOOL)respondsToSelector:(SEL)aSelector {
+ if (![super respondsToSelector:aSelector]) {
+ return [NSMenu respondsToSelector:aSelector];
+ }
+ return YES;
+}
+
+- (id)initWithMenuProvider:(id <ITStatusItemMenuProvider>)provider statusItem:(ITStatusItem *)item {
+ menuProvider = [provider retain];
+ statusItem = [item retain];
+ cachedTime = UpTime();
+ menu = nil;
+ return self;
+}
+
+- (void)forwardInvocation:(NSInvocation *)anInvocation {
+ AbsoluteTime diff = SubAbsoluteFromAbsolute(UpTime(),cachedTime);
+
+ if (!menu || diff.lo > 1000000) {
+ [menu release];
+ menu = [[menuProvider menuForStatusItem:statusItem] retain];
+ cachedTime = UpTime();
+ }
+
+ [anInvocation setTarget:menu];
+ [anInvocation invoke];
+}
+
+- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
+ return [NSMenu instanceMethodSignatureForSelector:aSelector];
+}
+
+- (void)dealloc {
+ [menu release];
+ [statusItem release];
+ [menuProvider release];
+ [super dealloc];
+}
+