Verified Commit aed9e2d9 authored by Spotlight Deveaux's avatar Spotlight Deveaux 🦊

Beginning support at using broadcast

parent aa74a622
......@@ -253,6 +253,9 @@
com.apple.HardenedRuntime = {
enabled = 1;
};
com.apple.Sandbox = {
enabled = 0;
};
};
};
42024DF420145BFA00AEBA10 = {
......@@ -524,7 +527,6 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = iTunesRPC/iTunesRPC.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
......@@ -554,7 +556,6 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = iTunesRPC/iTunesRPC.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
......
......@@ -7,11 +7,11 @@
//
import Cocoa
import ScriptingBridge
import SwordRPC
import Foundation
@available(OSX 10.12.2, *)
class ViewController: NSViewController {
// This is the iTunesRPC app ID.
// You're welcome to change as you want.
......@@ -21,76 +21,63 @@ class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
mediaController.beginWatching()
let distributed = DistributedNotificationCenter.default
distributed.addObserver(self,
selector: #selector(infoDidChange),
name: NSNotification.Name(rawValue: "com.apple.iTunes.playerInfo"),
object: nil)
// Callback for when RPC connects.
rpc.onConnect { (_) in
print("Connected to Discord.")
// Now, we'll wait for notifications.
self.setupNotifications()
self.updatePlayingEmbed()
}
rpc.connect()
}
@objc func infoDidChange(notification : Notification) {
mediaController.updateInfo()
updatePlayingEmbed()
}
@objc func playingDidChange(notification : Notification) {
mediaController.updatePlayStatus()
if mediaController.isPlaying {
// Update as if we're playing.
updatePlayingEmbed()
} else {
var presence = RichPresence()
let details = "Paused."
presence.details = details
var presence = RichPresence()
presence.assets.largeImage = "itunes_logo"
let info = notification.userInfo! as NSDictionary
print(info)
let playingState = info["Player State"]! as! String
if playingState == "Paused" {
presence.assets.smallImage = "pause"
presence.details = "Paused."
presence.state = "Holding your spot in the beat."
rpc.setPresence(presence)
}
}
func updatePlayingEmbed() {
// Do a slight double check to see if are worth changing.
// No need to go again and again.
if currentTitle == mediaController.title as String {
return
} else if playingState == "Stopped" {
presence.assets.smallImage = "stop"
presence.details = "iTunes is stopped."
presence.state = "Nothing is happening."
} else {
presence.assets.smallImage = "play"
// We're now "stealing" display lines directly from iTunes.
presence.details = info["Display Line 0"]! as! String
presence.state = info["Display Line 1"]! as! String
presence.party.id = "\(info["PersistentID"] as! NSNumber)"
presence.secrets.join = (info["Store URL"] as! String).toBase64()
}
var presence = RichPresence()
presence.details = mediaController.title as String
presence.state = "\(mediaController.album as String) - \(mediaController.artist as String)"
rpc.setPresence(presence)
}
}
// xo https://stackoverflow.com/a/35360697
extension String {
func setupNotifications() {
NotificationCenter.default.addObserver(self,
selector: #selector(infoDidChange),
name: NSNotification.Name.mrPlaybackQueueContentItemsChanged,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(infoDidChange),
name: NSNotification.Name.mrNowPlayingPlaybackQueueChanged,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(playingDidChange),
name: NSNotification.Name.mrMediaRemoteNowPlayingApplicationIsPlayingDidChange,
object: nil)
func fromBase64() -> String? {
guard let data = Data(base64Encoded: self) else {
return nil
}
return String(data: data, encoding: .utf8)
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
func toBase64() -> String {
return Data(self.utf8).base64EncodedString()
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.automation.apple-events</key>
<true/>
</dict>
<dict/>
</plist>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment