Permalink
Browse files

Make playURL a property… and a URL.

  • Loading branch information...
1 parent 6ad2c9c commit 40fb3655eb37b800fd1a53cfa2dda7b7f5aca447 Danny Greg committed Jan 17, 2013
@@ -17,12 +17,11 @@ extern NSString *const PLANowPlayingUpdated;
@property (nonatomic, strong) NSArray *queuedTracks;
@property (nonatomic, strong) PLATrack *currentlyPlayingTrack;
@property (nonatomic, strong) NSString *streamUrl;
+@property (nonatomic, copy) NSURL *playURL;
+ (PLAController *)sharedController;
- (void)logInWithBlock:(void(^)(BOOL succeeded))block;
-- (void)setPlayUrl:(NSString *)url;
-- (NSString *)playUrl;
- (void)setAuthToken:(NSString *)token;
- (NSString *)authToken;
- (void)updateNowPlaying:(NSDictionary *)nowPlayingDict;
@@ -54,13 +54,15 @@ - (void)logInWithBlock:(void(^)(BOOL succeeded))block{
#pragma mark - Settings
-- (void)setPlayUrl:(NSString *)url{
- [[NSUserDefaults standardUserDefaults] setObject:url forKey:@"playUrl"];
+- (void)setPlayURL:(NSURL *)url{
+ [[NSUserDefaults standardUserDefaults] setObject:url.absoluteString forKey:@"playUrl"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-- (NSString *)playUrl{
- return [[NSUserDefaults standardUserDefaults] objectForKey:@"playUrl"];
+- (NSString *)playURL{
+ NSString *storedString = [[NSUserDefaults standardUserDefaults] objectForKey:@"playUrl"];
+ if (storedString == nil) return nil;
+ return [NSURL URLWithString:storedString];
}
- (void)setAuthToken:(NSString *)token{
@@ -17,13 +17,13 @@ + (PLAPlayClient *)sharedClient {
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
- _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:[[PLAController sharedController] playUrl]]];
+ _sharedClient = [[self alloc] initWithBaseURL:[[PLAController sharedController] playURL]];
});
// This isn't pretty, but baseURL is readonly. So we can't actually
// keep it a singleton and adjust the url based on user input at runtime.
- if (![[[_sharedClient baseURL] absoluteString] isEqualToString:[[PLAController sharedController] playUrl]]) {
- _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:[[PLAController sharedController] playUrl]]];
+ if (![[[_sharedClient baseURL] absoluteString] isEqualToString:[[[PLAController sharedController] playURL] absoluteString]]) {
+ _sharedClient = [[self alloc] initWithBaseURL:[[PLAController sharedController] playURL]];
}
[_sharedClient setDefaultHeader:@"Authorization" value:[[PLAController sharedController] authToken]];
View
@@ -105,19 +105,19 @@ - (id)copyWithZone:(NSZone *)zone
- (NSURL *)albumArtURL
{
- NSString *urlString = [NSString stringWithFormat:@"%@/images/art/%@.png", [[PLAController sharedController] playUrl], self.trackId];
+ NSString *urlString = [NSString stringWithFormat:@"%@/images/art/%@.png", [[PLAController sharedController] playURL], self.trackId];
return [NSURL URLWithString:urlString];
}
- (NSURL *)downloadURL
{
- NSString *urlString = [NSString stringWithFormat:@"%@/song/%@/download", [[PLAController sharedController] playUrl], self.trackId];
+ NSString *urlString = [NSString stringWithFormat:@"%@/song/%@/download", [[PLAController sharedController] playURL], self.trackId];
return [NSURL URLWithString:urlString];
}
- (NSURL *)albumDownloadURL
{
- NSString *urlString = [NSString stringWithFormat:@"%@/artist/%@/album/%@/download", [[PLAController sharedController] playUrl], [self.artist stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [self.album stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
+ NSString *urlString = [NSString stringWithFormat:@"%@/artist/%@/album/%@/download", [[PLAController sharedController] playURL], [self.artist stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [self.album stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
return [NSURL URLWithString:urlString];
}
@@ -21,8 +21,8 @@ - (void)awakeFromNib
{
[self.window setLevel:NSFloatingWindowLevel];
- NSString *playURL = [[PLAController sharedController] playUrl]; //A URL which isn't NSURL… quit trolling maddox
- [_playUrlTextField setStringValue:(playURL ?: @"")];
+ NSURL *playURL = [[PLAController sharedController] playURL]; //A URL which isn't NSURL… quit trolling maddox
+ [_playUrlTextField setStringValue:(playURL.absoluteString ?: @"")];
NSString *token = [[PLAController sharedController] authToken];
[_authTokenTextField setStringValue:(token ?: @"")];
@@ -46,11 +46,11 @@ - (IBAction)getToken:(id)sender
{
if ([self.playUrlTextField.stringValue rangeOfString:@"http://"].location != 0 && [self.playUrlTextField.stringValue rangeOfString:@"https://"].location != 0) {
NSString *urlString = [NSString stringWithFormat:@"http://%@", self.playUrlTextField.stringValue];
- [[PLAController sharedController] setPlayUrl:urlString];
+ [[PLAController sharedController] setPlayURL:[NSURL URLWithString:urlString]];
self.playUrlTextField.stringValue = urlString; //bindings don't have a chance to update here
}
- NSURL *playURL = [NSURL URLWithString:[[PLAController sharedController] playUrl]];
+ NSURL *playURL = [[PLAController sharedController] playURL];
if (playURL == nil) {
NSBeep();
return;
@@ -155,7 +155,7 @@ - (void)flipWindowToQueue
}
- (IBAction)goToPlay:(id)sender{
- [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[[PLAController sharedController] playUrl]]];
+ [[NSWorkspace sharedWorkspace] openURL:[[PLAController sharedController] playURL]];
}
#pragma mark - Play Methods

0 comments on commit 40fb365

Please sign in to comment.