Updated notification system
parent
1f3939c363
commit
2a0ef29ebe
|
@ -494,7 +494,7 @@ increase/decrease as long as the user holds the left/right, plus/minus button */
|
|||
[userDefaultsValuesDict setObject:[NSNumber numberWithInteger:kCogStatusStopped] forKey:@"lastPlaybackStatus"];
|
||||
[userDefaultsValuesDict setObject:[NSNumber numberWithInteger:-1] forKey:@"lastTrackPlaying"];
|
||||
[userDefaultsValuesDict setObject:[NSNumber numberWithDouble:0] forKey:@"lastTrackPosition"];
|
||||
|
||||
|
||||
//Register and sync defaults
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
|
|
@ -9,11 +9,18 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
#import <Growl/GrowlApplicationBridge.h>
|
||||
|
||||
#import "PlaybackController.h"
|
||||
|
||||
@class AudioScrobbler;
|
||||
@interface PlaybackEventController : NSObject <GrowlApplicationBridgeDelegate> {
|
||||
@interface PlaybackEventController : NSObject <NSUserNotificationCenterDelegate, GrowlApplicationBridgeDelegate> {
|
||||
NSOperationQueue *queue;
|
||||
|
||||
AudioScrobbler *scrobbler;
|
||||
|
||||
IBOutlet PlaybackController *playbackController;
|
||||
|
||||
IBOutlet NSWindow *mainWindow;
|
||||
IBOutlet NSWindow *miniWindow;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
// Created by Vincent Spader on 3/5/09.
|
||||
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
// New Notification Center code shamelessly based off this:
|
||||
// https://github.com/kbhomes/radiant-player-mac/tree/master/radiant-player-mac/Notifications
|
||||
|
||||
#import "PlaybackEventController.h"
|
||||
|
||||
#import "AudioScrobbler.h"
|
||||
#import "PlaybackController.h"
|
||||
#import "PlaylistEntry.h"
|
||||
|
||||
@implementation PlaybackEventController
|
||||
|
@ -19,6 +20,10 @@
|
|||
NSDictionary *defaultsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[NSNumber numberWithBool:YES], @"enableAudioScrobbler",
|
||||
[NSNumber numberWithBool:NO], @"automaticallyLaunchLastFM",
|
||||
[NSNumber numberWithBool:YES], @"notifications.enable",
|
||||
[NSNumber numberWithBool:NO], @"notifications.use-growl",
|
||||
[NSNumber numberWithBool:YES], @"notifications.itunes-style",
|
||||
[NSNumber numberWithBool:YES], @"notifications.show-album-art",
|
||||
nil];
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary];
|
||||
|
@ -35,6 +40,7 @@
|
|||
[queue setMaxConcurrentOperationCount:1];
|
||||
|
||||
scrobbler = [[AudioScrobbler alloc] init];
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
|
||||
[GrowlApplicationBridge setGrowlDelegate:self];
|
||||
}
|
||||
|
||||
|
@ -50,20 +56,55 @@
|
|||
|
||||
- (void)performPlaybackDidBeginActions:(PlaylistEntry *)pe
|
||||
{
|
||||
if (NO == [pe error]) {
|
||||
if([[NSUserDefaults standardUserDefaults] boolForKey:@"enableAudioScrobbler"]) {
|
||||
[scrobbler start:pe];
|
||||
if ([AudioScrobbler isRunning]) return;
|
||||
}
|
||||
|
||||
// Note: We don't want to send a growl notification on resume.
|
||||
[GrowlApplicationBridge notifyWithTitle:[pe title]
|
||||
description:[pe artist]
|
||||
notificationName:@"Stream Changed"
|
||||
iconData:[pe albumArtInternal]
|
||||
priority:0
|
||||
isSticky:NO
|
||||
clickContext:nil];
|
||||
if (NO == [pe error]) {
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
if ([defaults boolForKey:@"notifications.enable"]) {
|
||||
if([defaults boolForKey:@"enableAudioScrobbler"]) {
|
||||
[scrobbler start:pe];
|
||||
if ([AudioScrobbler isRunning]) return;
|
||||
}
|
||||
|
||||
if ([defaults boolForKey:@"notifications.use-growl"]) {
|
||||
// Note: We don't want to send a growl notification on resume.
|
||||
[GrowlApplicationBridge notifyWithTitle:[pe title]
|
||||
description:[pe artist]
|
||||
notificationName:@"Stream Changed"
|
||||
iconData:[pe albumArtInternal]
|
||||
priority:0
|
||||
isSticky:NO
|
||||
clickContext:nil];
|
||||
}
|
||||
else {
|
||||
NSUserNotification *notif = [[NSUserNotification alloc] init];
|
||||
notif.title = [pe title];
|
||||
|
||||
if ([defaults boolForKey:@"notifications.itunes-style"]) {
|
||||
notif.subtitle = [NSString stringWithFormat:@"%@ - %@", [pe artist], [pe album]];
|
||||
[notif setValue:@YES forKey:@"_showsButtons"];
|
||||
}
|
||||
else {
|
||||
notif.informativeText = [NSString stringWithFormat:@"%@ - %@", [pe artist], [pe album]];
|
||||
}
|
||||
|
||||
if ([notif respondsToSelector:@selector(setContentImage:)]) {
|
||||
if ([defaults boolForKey:@"notifications.show-album-art"] && [pe albumArtInternal]) {
|
||||
NSImage *image = [pe albumArt];
|
||||
|
||||
if ([defaults boolForKey:@"notifications.itunes-style"]) {
|
||||
[notif setValue:image forKey:@"_identityImage"];
|
||||
}
|
||||
else {
|
||||
notif.contentImage = image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notif.actionButtonTitle = @"Skip";
|
||||
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] scheduleNotification:notif];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,4 +197,26 @@
|
|||
nil];
|
||||
}
|
||||
|
||||
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
|
||||
{
|
||||
switch (notification.activationType)
|
||||
{
|
||||
case NSUserNotificationActivationTypeActionButtonClicked:
|
||||
[playbackController next:self];
|
||||
break;
|
||||
|
||||
case NSUserNotificationActivationTypeContentsClicked:
|
||||
{
|
||||
NSWindow *window = [[NSUserDefaults standardUserDefaults] boolForKey:@"miniMode"] ? miniWindow : mainWindow;
|
||||
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
[window makeKeyAndOrderFront:self];
|
||||
};
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -1459,7 +1459,9 @@ Gw
|
|||
</customObject>
|
||||
<customObject id="2405" customClass="PlaybackEventController">
|
||||
<connections>
|
||||
<outlet property="playlistLoader" destination="1319" id="2407"/>
|
||||
<outlet property="mainWindow" destination="21" id="xhc-8E-Ogp"/>
|
||||
<outlet property="miniWindow" destination="2234" id="iPi-Vv-Mjn"/>
|
||||
<outlet property="playbackController" destination="705" id="A0d-y8-cA6"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="226" userLabel="AppController" customClass="AppController">
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5053" systemVersion="13D21" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
|
||||
<dependencies>
|
||||
<deployment version="1050" defaultVersion="1060" identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5053"/>
|
||||
<deployment version="1050" identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6254"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="GeneralPreferencesPlugin">
|
||||
|
@ -19,7 +19,7 @@
|
|||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customObject id="6" userLabel="HotKeyPane" customClass="HotKeyPane">
|
||||
<connections>
|
||||
<outlet property="nextHotKeyControl" destination="28" id="36"/>
|
||||
|
@ -415,21 +415,55 @@
|
|||
</subviews>
|
||||
</customView>
|
||||
<customView id="U4w-jw-ca5" userLabel="GrowlView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="500" height="54"/>
|
||||
<rect key="frame" x="0.0" y="-5" width="500" height="114"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<button id="njn-Xl-9k9">
|
||||
<rect key="frame" x="18" y="18" width="329" height="18"/>
|
||||
<rect key="frame" x="18" y="78" width="158" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<buttonCell key="cell" type="check" title="Enable notifications if Growl isn't installed" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="hqT-nY-NoU">
|
||||
<buttonCell key="cell" type="check" title="Enable notifications" bezelStyle="regularSquare" imagePosition="left" alignment="left" inset="2" id="hqT-nY-NoU">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="52" name="value" keyPath="values.enableGrowlMist" id="bFi-IF-5sw"/>
|
||||
<binding destination="52" name="value" keyPath="values.notifications.enable" id="toQ-Hx-kYp"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button id="AIz-WH-Wqk">
|
||||
<rect key="frame" x="18" y="38" width="131" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Use iTunes style" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="cOb-hQ-7K8">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="52" name="value" keyPath="values.notifications.itunes-style" id="jmN-ov-rRF"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button id="LLn-jv-hmj">
|
||||
<rect key="frame" x="18" y="18" width="131" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Show album art" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="RGf-4D-3NW">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="52" name="value" keyPath="values.notifications.show-album-art" id="nrZ-bM-zQX"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button id="iyk-MU-PT8">
|
||||
<rect key="frame" x="18" y="58" width="150" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Use Growl" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="GbM-Kf-xzx">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="52" name="value" keyPath="values.notifications.use-growl" id="ihr-Z4-e0x"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<point key="canvasLocation" x="348" y="132"/>
|
||||
</customView>
|
||||
<customView id="CgN-sy-RmM" userLabel="AppearanceView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="500" height="54"/>
|
||||
|
@ -503,7 +537,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="3Gx-cs-3B0" id="5q7-83-7V6">
|
||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
<font key="font" metaFont="menu"/>
|
||||
<menu key="menu" title="OtherViews" id="HKM-FW-dhH">
|
||||
<items>
|
||||
<menuItem title="Item 1" state="on" id="3Gx-cs-3B0"/>
|
||||
|
@ -514,8 +548,8 @@
|
|||
</popUpButtonCell>
|
||||
<connections>
|
||||
<binding destination="JB6-r9-XpG" name="content" keyPath="arrangedObjects" id="Je5-Yu-hIz"/>
|
||||
<binding destination="JB6-r9-XpG" name="contentObjects" keyPath="arrangedObjects.preference" previousBinding="Je5-Yu-hIz" id="yYR-TY-pXw"/>
|
||||
<binding destination="JB6-r9-XpG" name="contentValues" keyPath="arrangedObjects.name" previousBinding="yYR-TY-pXw" id="KxI-52-0UK"/>
|
||||
<binding destination="JB6-r9-XpG" name="contentObjects" keyPath="arrangedObjects.preference" previousBinding="Je5-Yu-hIz" id="yYR-TY-pXw"/>
|
||||
<binding destination="52" name="selectedObject" keyPath="values.resampling" previousBinding="KxI-52-0UK" id="wsy-tb-NFy"/>
|
||||
</connections>
|
||||
</popUpButton>
|
||||
|
|
Loading…
Reference in New Issue