X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/46b610a25dea1e26f1348dac4024d72514130bb3..d33e9b61891ddd4d4e70422f3f20c693d0ee030c:/MainController.m diff --git a/MainController.m b/MainController.m index 548ca25..4994a7d 100755 --- a/MainController.m +++ b/MainController.m @@ -198,6 +198,12 @@ static MainController *sharedController; [statusItem setImage:[NSImage imageNamed:@"MenuNormal"]]; [statusItem setAlternateImage:[NSImage imageNamed:@"MenuInverted"]]; + if ([df boolForKey:@"audioscrobblerEnabled"]) { + if ([PreferencesController getKeychainItemPasswordForUser:[df stringForKey:@"audioscrobblerUser"]] != nil) { + [[AudioscrobblerController sharedController] attemptHandshake:NO]; + } + } + [networkController startRemoteServerSearch]; [NSApp deactivate]; [self performSelector:@selector(rawr) withObject:nil afterDelay:1.0]; @@ -469,8 +475,8 @@ static MainController *sharedController; if (_audioscrobblerTimer) { [_audioscrobblerTimer invalidate]; } - if (length > 0) { - _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:((length < 240) ? length / 2 : 120) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO]; + if (length > 30) { + _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:((length < 240) ? length / 2 : 120) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:YES]; } } else { _audioscrobblerTimer = nil; @@ -595,8 +601,8 @@ static MainController *sharedController; if (_audioscrobblerTimer) { [_audioscrobblerTimer invalidate]; } - if (length > 0) { - _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:((length < 240) ? length / 2 : 120) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:NO]; + if (length > 30) { + _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:((length < 240) ? length / 2 : 120) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:YES]; } } else { _audioscrobblerTimer = nil; @@ -614,20 +620,29 @@ static MainController *sharedController; - (void)submitAudioscrobblerTrack:(NSTimer *)timer { + int interval = [timer timeInterval]; + [timer invalidate]; + _audioscrobblerTimer = nil; + ITDebugLog(@"Audioscrobbler: Attempting to submit current track"); if ([df boolForKey:@"audioscrobblerEnabled"]) { NS_DURING - NSString *title = [[self currentRemote] currentSongTitle], *artist = [[self currentRemote] currentSongArtist]; - if (title && artist) { - [[AudioscrobblerController sharedController] submitTrack:title - artist:artist - album:[[self currentRemote] currentSongAlbum] - length:[[self currentRemote] currentSongDuration]]; + int elapsed = [[self currentRemote] currentSongPlayed]; + if ((abs(elapsed - interval) < 5) && ([[self currentRemote] playerPlayingState] == ITMTRemotePlayerPlaying)) { + NSString *title = [[self currentRemote] currentSongTitle], *artist = [[self currentRemote] currentSongArtist]; + if (title && artist) { + ITDebugLog(@"Audioscrobbler: Submitting current track"); + [[AudioscrobblerController sharedController] submitTrack:title + artist:artist + album:[[self currentRemote] currentSongAlbum] + length:[[self currentRemote] currentSongDuration]]; + } + } else if (interval - elapsed > 0) { + ITDebugLog(@"Audioscrobbler: Creating a new timer that will run in %i seconds", interval - elapsed); + _audioscrobblerTimer = [NSTimer scheduledTimerWithTimeInterval:(interval - elapsed) target:self selector:@selector(submitAudioscrobblerTrack:) userInfo:nil repeats:YES]; } NS_HANDLER [self networkError:localException]; NS_ENDHANDLER - [timer invalidate]; - _audioscrobblerTimer = nil; } } @@ -950,7 +965,7 @@ static MainController *sharedController; [hotKey setName:@"TrackInfo"]; [hotKey setKeyCombo:[ITKeyCombo keyComboWithPlistRepresentation:[df objectForKey:@"TrackInfo"]]]; [hotKey setTarget:self]; - [hotKey setAction:@selector(showCurrentTrackInfo)]; + [hotKey setAction:@selector(showCurrentTrackInfoHotKey)]; [[ITHotKeyCenter sharedCenter] registerHotKey:[hotKey autorelease]]; } @@ -1060,6 +1075,18 @@ static MainController *sharedController; ITDebugLog(@"Finished setting up hot keys."); } +- (void)showCurrentTrackInfoHotKey +{ + //If we're already visible and the setting says so, vanish instead of displaying again. + if ([df boolForKey:@"ToggleTrackInfoWithHotKey"] && [statusWindowController currentStatusWindowType] == StatusWindowTrackInfoType && [[StatusWindow sharedWindow] visibilityState] == ITWindowVisibleState) { + ITDebugLog(@"Track window is already visible, hiding track window."); + [self invalidateStatusWindowUpdateTimer]; + [[StatusWindow sharedWindow] vanish:nil]; + return; + } + [self showCurrentTrackInfo]; +} + - (void)showCurrentTrackInfo { ITMTRemotePlayerSource source = 0; @@ -1073,14 +1100,6 @@ static MainController *sharedController; int rating = -1; int playCount = -1; - //If we're already visible and the setting says so, vanish instead of displaying again. - if ([df boolForKey:@"ToggleTrackInfoWithHotKey"] && [statusWindowController currentStatusWindowType] == StatusWindowTrackInfoType && [[StatusWindow sharedWindow] visibilityState] == ITWindowVisibleState) { - ITDebugLog(@"Track window is already visible, hiding track window."); - [self invalidateStatusWindowUpdateTimer]; - [[StatusWindow sharedWindow] vanish:nil]; - return; - } - ITDebugLog(@"Showing track info status window."); NS_DURING