-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatusController.m
112 lines (93 loc) · 2.37 KB
/
StatusController.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
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
//
// StatusController.m
// StatusItemCrash
//
// Created by Michael Harper on 10/1/09.
// Copyright 2009 Standalone Code LLC. All rights reserved.
//
#import "StatusController.h"
@implementation StatusController
@synthesize statusMenu;
@synthesize status;
@synthesize statusMenuItem;
@synthesize cycleThread;
@synthesize menuOpen;
@synthesize menuGuarded;
@synthesize menuGuardedItem;
-(void) awakeFromNib
{
[self createStatusMenu];
}
-(void) createStatusMenu
{
NSStatusBar *bar = [NSStatusBar systemStatusBar];
statusMenuItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[statusMenuItem retain];
[statusMenuItem setHighlightMode:YES];
[statusMenuItem setMenu:statusMenu];
[statusMenuItem setTitle:@"Crash"];
menuOpen = NO;
self.menuGuarded = YES;
}
-(void) cycleStatus:(id) ignore
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Loop until thread is cancelled, setting the status item and sleeping.
NSString *completeTitle = @"12345678901234567890";
NSInteger titleLength = 2;
while (![[NSThread currentThread] isCancelled])
{
if ((!menuOpen) || (menuOpen && !menuGuarded))
{
[self performSelectorOnMainThread:@selector(setStatusTitle:) withObject:[completeTitle substringToIndex:titleLength]
waitUntilDone:YES];
titleLength = (titleLength + 2) % 20;
NSLog(@"Set Status");
}
NSLog(@"Sleeping");
[NSThread sleepForTimeInterval:2.0];
}
NSLog(@"Cancelled.");
[pool release];
}
-(IBAction) cycleAction:(id) sender;
{
cycleThread = [[NSThread alloc] initWithTarget:self selector:@selector(cycleStatus:) object:nil];
[cycleThread start];
}
-(IBAction) stopCycleAction:(id) sender;
{
if (cycleThread != nil)
{
[cycleThread cancel];
[cycleThread release];
cycleThread = nil;
}
}
-(IBAction) toggleGuardAction:(id) sender
{
self.menuGuarded = !self.menuGuarded;
}
-(void) setMenuGuarded:(BOOL) mg
{
[menuGuardedItem setTitle:(mg ? @"Disable Menu Guard" : @"Enable Menu Guard")];
menuGuarded = mg;
NSLog(@"Menu Guard is %@", (mg ? @"ON" : @"OFF"));
}
-(IBAction) quitAction:(id) sender;
{
[[NSApplication sharedApplication] terminate:self];
}
-(void) setStatusTitle:(NSString *) statusTitle;
{
[status setTitle:statusTitle];
}
-(void) menuWillOpen:(NSMenu *) menu
{
menuOpen = YES;
}
-(void) menuDidClose:(NSMenu *) menu
{
menuOpen = NO;
}
@end