Skip to content

Commit e1f8354

Browse files
committed
reorganize appdelegate
1 parent aaf9230 commit e1f8354

1 file changed

Lines changed: 34 additions & 38 deletions

File tree

SimonRemote/ApplicationDelegate.m

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ @implementation ApplicationDelegate {
1616
@synthesize messenger = _messenger;
1717
@synthesize numberActiveControllers = _numberActiveControllers;
1818

19-
NSString *letters = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
19+
NSString *letters = @"ABCDEFGHIJKLMNPQRSTUVWXYZ";
2020

2121
#pragma mark - Notifications
2222

@@ -42,19 +42,6 @@ - (void) receiveWakeNote: (NSNotification*) note
4242
NSLog(@"receiveWakeNote: %@", [note name]);
4343
}
4444

45-
- (void) fileNotifications
46-
{
47-
//These notifications are filed on NSWorkspace's notification center, not the default
48-
// notification center. You will not receive sleep/wake notifications if you file
49-
//with the default notification center.
50-
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
51-
selector: @selector(receiveSleepNote:)
52-
name: NSWorkspaceWillSleepNotification object: NULL];
53-
54-
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
55-
selector: @selector(receiveWakeNote:)
56-
name: NSWorkspaceDidWakeNotification object: NULL];
57-
}
5845

5946
-(void)reachabilityChanged:(NSNotification*)note
6047
{
@@ -150,51 +137,60 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification
150137
[updater checkForUpdatesInBackground];
151138
}
152139

153-
154-
- (void)applicationDidFinishLaunching:(NSNotification *)notification
140+
- (void)setupNotificationsAndTimers
155141
{
156-
// Install icon into the menu bar
157-
self.menubarController = [[MenubarController alloc] init];
158-
channel = [self getChannel];
159-
_messenger = [[SRMessenger alloc] initWithURL:WS_SERVER_URL andChannel:channel];
142+
// Reachability
160143

161-
162-
// Allocate a reachability object
163144
reach = [Reachability reachabilityWithHostname:@"www.google.com"];
164-
165-
// Tell the reachability that we DON'T want to be reachable on 3G/EDGE/CDMA
166145
reach.reachableOnWWAN = NO;
167-
168-
// Here we set up a NSNotification observer. The Reachability that caused the notification
169-
// is passed in the object parameter
170146
[[NSNotificationCenter defaultCenter] addObserver:self
171147
selector:@selector(reachabilityChanged:)
172148
name:kReachabilityChangedNotification
173149
object:nil];
174150

175151
[reach startNotifier];
176-
[self fileNotifications];
152+
153+
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
154+
selector: @selector(receiveSleepNote:)
155+
name: NSWorkspaceWillSleepNotification object: NULL];
156+
157+
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
158+
selector: @selector(receiveWakeNote:)
159+
name: NSWorkspaceDidWakeNotification object: NULL];
177160

178-
NSDistributedNotificationCenter *dnc = [NSDistributedNotificationCenter defaultCenter];
161+
// Player state changes
179162

180-
[dnc addObserver:self
181-
selector:@selector(pushNewInfo:)
182-
name:@"com.apple.iTunes.playerInfo"
183-
object:nil];
163+
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
164+
selector:@selector(pushNewInfo:)
165+
name:@"com.apple.iTunes.playerInfo"
166+
object:nil];
184167

185-
[dnc addObserver:self
186-
selector:@selector(pushNewInfo:)
187-
name:@"com.spotify.client.PlaybackStateChanged"
188-
object:nil];
189-
168+
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
169+
selector:@selector(pushNewInfo:)
170+
name:@"com.spotify.client.PlaybackStateChanged"
171+
object:nil];
190172

191173
// set up reconnect timer
174+
192175
tickTimer = [NSTimer scheduledTimerWithTimeInterval: 30.0
193176
target: self
194177
selector:@selector(timerTick:)
195178
userInfo: nil repeats:YES];
196179
}
197180

181+
182+
- (void)applicationDidFinishLaunching:(NSNotification *)notification
183+
{
184+
// Install icon into the menu bar
185+
self.menubarController = [[MenubarController alloc] init];
186+
channel = [self getChannel];
187+
_messenger = [[SRMessenger alloc] initWithURL:WS_SERVER_URL andChannel:channel];
188+
189+
190+
191+
[self setupNotificationsAndTimers];
192+
}
193+
198194
- (void)timerTick:(NSTimer *)timer
199195
{
200196
//I'm removing reachable check for local testing

0 commit comments

Comments
 (0)