Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Last.FM integration #20

Merged
merged 10 commits into from
May 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions Spotify Notifications/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@
@property (assign) IBOutlet NSWindow *window;
@property (strong, nonatomic) NSStatusItem *statusBar;
@property (strong, nonatomic) IBOutlet NSMenu *statusMenu;
@property (strong, nonatomic) IBOutlet NSMenuItem *openPrefences;
@property (strong, nonatomic) IBOutlet NSMenuItem *openPreferences;
@property (strong, nonatomic) IBOutlet NSMenuItem *openLastFMMenu;
@property (strong, nonatomic) IBOutlet NSMenuItem *openLastFMArtist;
@property (strong, nonatomic) IBOutlet NSMenuItem *openLastFMAlbum;
@property (strong, nonatomic) IBOutlet NSMenuItem *openLastFMTrack;
@property (strong, nonatomic) IBOutlet NSPopUpButton *showNotificationsToggle;
@property (strong, nonatomic) IBOutlet NSPopUpButton *showPlayPauseNotifToggle;
@property (strong, nonatomic) IBOutlet NSPopUpButton *soundToggle;
@property (strong, nonatomic) IBOutlet NSPopUpButton *iconToggle;
@property (strong, nonatomic) IBOutlet NSPopUpButton *startupToggle;
@property (strong, nonatomic) IBOutlet NSPopUpButton *showTracksToggle;
@property (strong, nonatomic) IBOutlet NSPopUpButton *albumArtToggle;
@property (weak, nonatomic) IBOutlet MASShortcutView *shortcutView;

- (IBAction)showHome:(id)sender;
- (IBAction)showAuthor:(id)sender;
- (IBAction)showSource:(id)sender;
- (IBAction)showContributors:(id)sender;

- (IBAction)toggleIcons:(id)sender;
- (IBAction)showLastFM:(id)sender;
- (IBAction)showPreferences:(id)sender;

- (IBAction)toggleNotifications:(id)sender;
- (IBAction)togglePlayPauseNotif:(id)sender;
- (IBAction)toggleSound:(id)sender;
- (IBAction)toggleIcons:(id)sender;
- (IBAction)toggleStartup:(id)sender;
- (IBAction)toggleShowTracks:(id)sender;
- (IBAction)toggleAlbumArt:(id)sender;

@end
101 changes: 66 additions & 35 deletions Spotify Notifications/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@

@implementation AppDelegate

@synthesize window;
@synthesize statusBar;
@synthesize statusMenu;
@synthesize openPrefences;
@synthesize openPreferences;
@synthesize openLastFMMenu;
@synthesize openLastFMArtist;
@synthesize openLastFMAlbum;
@synthesize openLastFMTrack;

@synthesize showNotificationsToggle;
@synthesize showPlayPauseNotifToggle;
@synthesize soundToggle;
@synthesize window;
@synthesize iconToggle;
@synthesize startupToggle;
@synthesize showTracksToggle;
@synthesize shortcutView;
@synthesize albumArtToggle;
@synthesize shortcutView;

BOOL UserNotificationContentImagePropertyAvailable;

Expand Down Expand Up @@ -87,10 +93,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self setIcon];
[self setupGlobalShortcutForNotifications];

[showNotificationsToggle selectItemAtIndex:[self getProperty:@"notifications"]];
[showPlayPauseNotifToggle selectItemAtIndex:[self getProperty:@"playpausenotifs"]];
[soundToggle selectItemAtIndex:[self getProperty:@"notificationSound"]];
[iconToggle selectItemAtIndex:[self getProperty:@"iconSelection"]];
[startupToggle selectItemAtIndex:[self getProperty:@"startupSelection"]];
[showTracksToggle selectItemAtIndex:[self getProperty:@"showTracks"]];
[albumArtToggle selectItemAtIndex:[self getProperty:@"includeAlbumArt"]];

if (!(UserNotificationContentImagePropertyAvailable)) {
Expand Down Expand Up @@ -153,7 +160,7 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:

// This makes it so you can open the preferences by re-opening the app
// This way you can get to the preferences even when the status item is hidden
[self showPrefences:nil];
[self showPreferences:nil];

}

Expand All @@ -163,29 +170,43 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:

- (IBAction)showSource:(id)sender {

[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"http://github.com/citruspi/Spotify-Notifications"]];

}

- (IBAction)showHome:(id)sender {

[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"http://mihirsingh.com/Spotify-Notifications"]];
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"https://github.com/citruspi/Spotify-Notifications"]];

}

- (IBAction)showAuthor:(id)sender {
- (IBAction)showContributors:(id)sender {

[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"http://mihirsingh.com"]];
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"https://github.com/citruspi/Spotify-Notifications/graphs/contributors"]];

}

- (IBAction)showPrefences:(id)sender {
- (IBAction)showPreferences:(id)sender {

[NSApp activateIgnoringOtherApps:YES];
[window makeKeyAndOrderFront:nil];

}

- (IBAction)showLastFM:(id)sender {

//Artist - we always need at least this
NSString* urlText = [NSString stringWithFormat:@"http://last.fm/music/%@", track.artist];

if ([sender tag] == 1) {
//Album
urlText = [urlText stringByAppendingString:[NSString stringWithFormat:@"/%@", track.album]];
}
else if ([sender tag] == 2) {
//Track
urlText = [urlText stringByAppendingString:[NSString stringWithFormat:@"/%@/%@", track.album, track.title]];
}

urlText = [urlText stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: urlText]];

}

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
shouldPresentNotification:(NSUserNotification *)notification {

Expand All @@ -210,7 +231,11 @@ - (void)eventOccured:(NSNotification *)notification {
track.title = [information objectForKey: @"Name"];
track.trackID = [information objectForKey:@"Track ID"];

if (![previousTrack isEqualToString:track.trackID] || [self getProperty:@"showTracks"] == 0) {
if (![openLastFMMenu isEnabled] && [track.artist isNotEqualTo:NULL]) {
[openLastFMMenu setEnabled:YES];
}

if ( [self getProperty:@"notifications"] == 0 && (![previousTrack isEqualToString:track.trackID] || [self getProperty:@"playpausenotifs"] == 0) ) {

previousTrack = track.trackID;
track.albumArt = nil;
Expand Down Expand Up @@ -241,34 +266,22 @@ - (void)eventOccured:(NSNotification *)notification {

}

- (IBAction)toggleSound:(id)sender {
- (IBAction)toggleNotifications:(id)sender {

[self saveProperty:@"notificationSound" value:(int)[soundToggle indexOfSelectedItem]];
[self saveProperty:@"notifications" value:(int)[showNotificationsToggle indexOfSelectedItem]];

}

- (IBAction)toggleShowTracks:(id)sender {
- (IBAction)togglePlayPauseNotif:(id)sender {

[self saveProperty:@"showTracks" value:(int)[showTracksToggle indexOfSelectedItem]];
[self saveProperty:@"playpausenotifs" value:(int)[showPlayPauseNotifToggle indexOfSelectedItem]];

}

- (IBAction)toggleStartup:(id)sender {

[self saveProperty:@"startupSelection" value:(int)[startupToggle indexOfSelectedItem]];
- (IBAction)toggleSound:(id)sender {

if ([self getProperty:@"startupSelection"] == 0) {

[GBLaunchAtLogin addAppAsLoginItem];

}
[self saveProperty:@"notificationSound" value:(int)[soundToggle indexOfSelectedItem]];

if ([self getProperty:@"startupSelection"] == 1) {

[GBLaunchAtLogin removeAppFromLoginItems];

}

}

- (void)setIcon {
Expand Down Expand Up @@ -308,6 +321,24 @@ - (IBAction)toggleIcons:(id)sender {

}

- (IBAction)toggleStartup:(id)sender {

[self saveProperty:@"startupSelection" value:(int)[startupToggle indexOfSelectedItem]];

if ([self getProperty:@"startupSelection"] == 0) {

[GBLaunchAtLogin addAppAsLoginItem];

}

if ([self getProperty:@"startupSelection"] == 1) {

[GBLaunchAtLogin removeAppFromLoginItems];

}

}

- (IBAction)toggleAlbumArt:(id)sender {

[self saveProperty:@"includeAlbumArt" value:(int)[albumArtToggle indexOfSelectedItem]];
Expand Down