Skip to content

Commit 798e6e3

Browse files
author
crr
committed
Merge branch 'development'
2 parents 36a4228 + ef63e93 commit 798e6e3

File tree

7 files changed

+27
-36
lines changed

7 files changed

+27
-36
lines changed

Notify.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@
579579
);
580580
runOnlyForDeploymentPostprocessing = 0;
581581
shellPath = /bin/bash;
582-
shellScript = "#!/bin/bash\nimage=\"icon_128x128.png\"\ndir=\"$TEMP_FILES_DIR/disk\"\ndist=\"$PROJECT_DIR/dist\"\ncp \"$PROJECT_DIR/$PROJECT_NAME/Assets.xcassets/AppIcon.appiconset/$image\" \"$dir/\"\n\n#unmount the temp image file, then convert it to final image file\nsync\nsync\nhdiutil detach /Volumes/$PRODUCT_NAME\nrm -f \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\"\nhdiutil convert \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.temp.dmg\" -format UDZO -imagekey zlib-level=9 -o \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\"\nrm -f \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.temp.dmg\"\n\n#Change the icon of the image file\nsips -i \"$dir/$image\"\nDeRez -only icns \"$dir/$image\" > \"$dir/tmpicns.rsrc\"\nRez -append \"$dir/tmpicns.rsrc\" -o \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\"\nSetFile -a C \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\"\n\nrm -rf \"$dir\"\n\nmkdir \"$dist\"\nmv \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\" \"$dist/$PRODUCT_NAME.dmg\"";
582+
shellScript = "#!/bin/bash\nimage=\"icon_128x128.png\"\ndir=\"$TEMP_FILES_DIR/disk\"\ndist=\"$PROJECT_DIR/dist\"\ncp \"$PROJECT_DIR/$PROJECT_NAME/Assets.xcassets/AppIcon.appiconset/$image\" \"$dir/\"\n\n#unmount the temp image file, then convert it to final image file\nsync\nsync\nhdiutil detach /Volumes/$PRODUCT_NAME\nrm -f \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\"\nhdiutil convert \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.temp.dmg\" -format UDZO -imagekey zlib-level=9 -o \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\"\nrm -f \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.temp.dmg\"\n\n#Change the icon of the image file\nsips -i \"$dir/$image\"\nDeRez -only icns \"$dir/$image\" > \"$dir/tmpicns.rsrc\"\nRez -append \"$dir/tmpicns.rsrc\" -o \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\"\nSetFile -a C \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\"\n\nrm -rf \"$dir\"\n\n[ -d $dist ] || mkdir $dist\nmv \"$BUILT_PRODUCTS_DIR/$PRODUCT_NAME.dmg\" \"$dist/$PRODUCT_NAME.dmg\"";
583583
};
584584
/* End PBXShellScriptBuildPhase section */
585585

Notify/AppDelegate.swift

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
2929
button.image = NSImage(named: "statusIcon")
3030
button.image?.template = true // sets the icon to inverted color for dark mode
3131
button.action = Selector("quitClicked:")
32-
3332
statusItem.menu = statusMenu
3433
}
3534

36-
// Set up Spotify listeners
37-
NSUserNotificationCenter.defaultUserNotificationCenter().delegate = spotifyHelper
3835
// Set observer to when Spotify state changes
39-
NSDistributedNotificationCenter.defaultCenter().addObserver(spotifyHelper.self,
40-
selector: "spotifyStateChanged:",
41-
name: Client.Spotify.rawValue + "." + PlaybackChanged.Spotify.rawValue,
42-
object: nil,
43-
suspensionBehavior: NSNotificationSuspensionBehavior.DeliverImmediately)
44-
NSDistributedNotificationCenter.defaultCenter().addObserver(self,
45-
selector: "togglePlayPauseText:",
46-
name: Client.Spotify.rawValue + "." + PlaybackChanged.Spotify.rawValue,
47-
object: nil,
48-
suspensionBehavior: NSNotificationSuspensionBehavior.DeliverImmediately)
49-
50-
// Set up iTunes listeners
51-
NSUserNotificationCenter.defaultUserNotificationCenter().delegate = itunesHelper
52-
// Set observer to when Spotify state changes
53-
NSDistributedNotificationCenter.defaultCenter().addObserver(itunesHelper.self,
54-
selector: "iTunesStateChanged:",
55-
name: Client.iTunes.rawValue + "." + PlaybackChanged.iTunes.rawValue,
56-
object: nil,
57-
suspensionBehavior: NSNotificationSuspensionBehavior.DeliverImmediately)
58-
NSDistributedNotificationCenter.defaultCenter().addObserver(self,
59-
selector: "togglePlayPauseText:",
60-
name: Client.iTunes.rawValue + "." + PlaybackChanged.iTunes.rawValue,
61-
object: nil,
62-
suspensionBehavior: NSNotificationSuspensionBehavior.DeliverImmediately)
36+
SystemHelper.addObserver(spotifyHelper, selector: "spotifyStateChanged:", client: .Spotify, event: .Spotify)
37+
SystemHelper.addObserver(self, selector: "togglePlayPauseText:", client: .Spotify, event: .Spotify)
6338

39+
// Set observer to when iTunes state changes
40+
SystemHelper.addObserver(itunesHelper, selector: "iTunesStateChanged:", client: .iTunes, event: .iTunes)
41+
SystemHelper.addObserver(self, selector: "togglePlayPauseText:", client: .iTunes, event: .iTunes)
6442
}
6543

6644
func applicationWillTerminate(aNotification: NSNotification) {

Notify/Handlers/SpotifyNotificationHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Cocoa
1313
import Alamofire
1414
import SwiftyJSON
1515

16-
class SpotifyNotificationHandler: NSObject, NSUserNotificationCenterDelegate, NotificationHandler {
16+
class SpotifyNotificationHandler: NSObject, NotificationHandler {
1717
var track = Song()
1818
let client: Client = .Spotify
1919

Notify/ITunesNotificationHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Cocoa
1111
import Alamofire
1212
import SwiftyJSON
1313

14-
class ITunesNotificationHandler: NSObject, NSUserNotificationCenterDelegate, NotificationHandler {
14+
class ITunesNotificationHandler: NSObject, NotificationHandler {
1515
var track = Song()
1616
let client: Client = .iTunes
1717

Notify/Info.plist

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929
<key>LSUIElement</key>
3030
<true/>
3131
<key>NSHumanReadableCopyright</key>
32-
<string>Copyright © 2015 Chris Rees. All rights reserved.</string>
32+
<string>Copyright © 2015 David Aghassi, Chris Rees. All rights reserved.</string>
3333
<key>NSMainNibFile</key>
3434
<string>MainMenu</string>
3535
<key>NSPrincipalClass</key>
3636
<string>NSApplication</string>
37-
<key>NSAppTransportSecurity</key>
38-
<dict>
39-
<key>NSAllowsArbitraryLoads</key><true/>
40-
</dict>
37+
<key>NSAppTransportSecurity</key>
38+
<dict>
39+
<key>NSAllowsArbitraryLoads</key>
40+
<true/>
41+
</dict>
4142
</dict>
4243
</plist>

Notify/NotificationHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010
import Cocoa
1111

12-
protocol NotificationHandler {
12+
protocol NotificationHandler: NSUserNotificationCenterDelegate {
1313
// The current track being played
1414
var track: Song { get }
1515
var client: Client { get }

Notify/System Helpers/SystemHelper.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ class SystemHelper {
2626

2727
return (playerState == "Playing")
2828
}
29+
30+
/*
31+
Add an observer to an event for an application
32+
*/
33+
static func addObserver(helper: AnyObject, selector: Selector, client: Client, event: PlaybackChanged) {
34+
// Set observer to when the application state changes
35+
NSDistributedNotificationCenter.defaultCenter().addObserver(helper.self,
36+
selector: selector,
37+
name: client.rawValue + "." + event.rawValue,
38+
object: nil,
39+
suspensionBehavior: NSNotificationSuspensionBehavior.DeliverImmediately)
40+
}
2941
}

0 commit comments

Comments
 (0)