Skip to content

Commit

Permalink
Make JTState a more proper singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
bgreenlee committed Apr 29, 2013
1 parent 2802c42 commit e26044b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
6 changes: 3 additions & 3 deletions JobTracker/JTPageLoadOperation.m
Expand Up @@ -30,9 +30,9 @@ - (void)main {
NSLog(@"Error loading document: %@", error);
}

[[[JTState alloc] init] performSelectorOnMainThread:@selector(pageLoaded:)
withObject:document
waitUntilDone:YES];
[[JTState sharedInstance] performSelectorOnMainThread:@selector(pageLoaded:)
withObject:document
waitUntilDone:YES];
}

@end
5 changes: 3 additions & 2 deletions JobTracker/JTState.h
@@ -1,5 +1,5 @@
//
// JTParser.h
// JTState.h
// JobTracker
//
// Created by Brad Greenlee on 11/6/12.
Expand All @@ -21,7 +21,8 @@
@property(nonatomic, retain) NSArray *usernames;
@property(nonatomic, retain) id delegate;

- (id)initWithURL:(NSURL *)url withUsernames:(NSString *)usernames;
+ (id)sharedInstance;
- (void)setUsernameString:(NSString *)usernames;
- (void)pageLoaded:(NSXMLDocument *)document;
- (void)refresh;
- (void)parse:(NSXMLDocument *)document;
Expand Down
23 changes: 14 additions & 9 deletions JobTracker/JTState.m
@@ -1,5 +1,5 @@
//
// JTParser.m
// JTState.m
// JobTracker
//
// Created by Brad Greenlee on 11/6/12.
Expand All @@ -14,28 +14,33 @@ @implementation JTState

@synthesize clusterSummary, jobs, url, usernames, delegate;

- (id)init {
if (shared) {
return shared;
+ (id)sharedInstance {
return shared;
}

+ (void)initialize {
static BOOL initialized = NO;
if (!initialized) {
initialized = YES;
shared = [[JTState alloc] init];
}
}

- (id)init {
if ((self = [super init])) {
clusterSummary = [[NSMutableDictionary alloc] init];
jobs = [[NSMutableDictionary alloc] init];
queue = [[NSOperationQueue alloc] init];
}
shared = self;
return self;
}

- (id)initWithURL:(NSURL *)_url withUsernames:(NSString *)_usernames{
self = [self init];
url = _url;
- (void)setUsernameString:(NSString *)_usernames{
if (_usernames == nil || [_usernames isEqualToString:@""]) {
usernames = nil;
} else {
usernames = [_usernames componentsSeparatedByString:@","];
}
return self;
}

- (void)pageLoaded:(NSXMLDocument *)document {
Expand Down
10 changes: 6 additions & 4 deletions JobTracker/JTStatusMenu.m
Expand Up @@ -34,8 +34,9 @@ - (void)awakeFromNib {

[self loadPreferences];
if ([self isConfigured]) {
jtState = [[JTState alloc] initWithURL:[NSURL URLWithString:[jobTrackerURL stringByAppendingString:@"/jobtracker.jsp"]]
withUsernames:usernames];
jtState = [JTState sharedInstance];
jtState.url = [NSURL URLWithString:[jobTrackerURL stringByAppendingString:@"/jobtracker.jsp"]];
[jtState setUsernameString:usernames];
jtState.delegate = self;
[self refresh:nil];
[self startTimer];
Expand Down Expand Up @@ -212,8 +213,9 @@ - (IBAction)openInBrowser:(id)sender {
- (void)preferencesUpdated {
[self loadPreferences];
if ([self isConfigured]) {
jtState = [[JTState alloc] initWithURL:[NSURL URLWithString:[jobTrackerURL stringByAppendingString:@"/jobtracker.jsp"]]
withUsernames:usernames];
jtState = [JTState sharedInstance];
jtState.url = [NSURL URLWithString:[jobTrackerURL stringByAppendingString:@"/jobtracker.jsp"]];
[jtState setUsernameString:usernames];
jtState.delegate = self;
[self refresh:nil];
[self startTimer];
Expand Down
2 changes: 1 addition & 1 deletion JobTracker/JobTracker-Info.plist
Expand Up @@ -21,7 +21,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.3</string>
<string>1.0.4</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
3 changes: 2 additions & 1 deletion JobTrackerTests/JTStateTests.m
Expand Up @@ -18,7 +18,8 @@ - (void)setUp {
NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:fileUrl
options:NSXMLDocumentTidyHTML
error:nil];
jtState = [[JTState alloc] initWithURL:fileUrl withUsernames:nil];
jtState = [JTState sharedInstance];
jtState.url = fileUrl;
[jtState pageLoaded:document];
}

Expand Down

0 comments on commit e26044b

Please sign in to comment.