Commit 29c7dc9b authored by Spotlight Deveaux's avatar Spotlight Deveaux 🦊

Revert mediaremote changes, use Music identifier

parent 41fc2664
This diff is collapsed.
......@@ -2,6 +2,6 @@
<Workspace
version = "1.0">
<FileRef
location = "self:iTunesRPC.xcodeproj">
location = "self:">
</FileRef>
</Workspace>
{
"object": {
"pins": [
{
"package": "Socket",
"repositoryURL": "https://github.com/IBM-Swift/BlueSocket.git",
"state": {
"branch": null,
"revision": "c46a3d41f5b2401d18bcb46d0101cdc5cd13e307",
"version": "1.0.52"
}
},
{
"package": "SwordRPC",
"repositoryURL": "https://owo.codes/projects-in-disarray/platform-bots/SwordRPC",
"state": {
"branch": null,
"revision": "890c3a90ab75c292c5be342bbc09935cd1b1c48b",
"version": "0.2.3"
}
}
]
},
"version": 1
}
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "1140"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......@@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "42024DE320145BF900AEBA10"
BuildableName = "iTunesRPC.app"
BlueprintName = "iTunesRPC"
ReferencedContainer = "container:iTunesRPC.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
......@@ -49,17 +58,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "42024DE320145BF900AEBA10"
BuildableName = "iTunesRPC.app"
BlueprintName = "iTunesRPC"
ReferencedContainer = "container:iTunesRPC.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
......@@ -81,8 +79,6 @@
ReferencedContainer = "container:iTunesRPC.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
......
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:iTunesRPC.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>
<?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>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G19009" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="16095" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16095"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
......@@ -600,7 +600,7 @@
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections>
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
<action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
</connections>
</menuItem>
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">
......@@ -665,11 +665,14 @@
<objects>
<customObject id="Oky-zY-oP4" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<connections>
<outlet property="delegate" destination="B8D-0N-5wS" id="1Jz-T9-Em4"/>
</connections>
</window>
<connections>
<segue destination="XfG-lQ-9wD" kind="relationship" relationship="window.shadowedContentViewController" id="cq2-FE-JQM"/>
......@@ -686,18 +689,20 @@
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vE1-Uh-CW4">
<rect key="frame" x="118" y="139" width="4" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vE1-Uh-CW4">
<rect key="frame" x="118" y="140" width="4" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" id="xNg-Kc-IE8">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="whX-hn-moM">
<rect key="frame" x="168" y="78" width="188" height="140"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="whX-hn-moM">
<rect key="frame" x="18" y="20" width="444" height="230"/>
<constraints>
<constraint firstAttribute="height" constant="230" id="UZ2-hC-gv4"/>
<constraint firstAttribute="width" constant="440" id="V1l-Nj-W5M"/>
</constraints>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" id="rVg-3t-n8B">
<font key="font" metaFont="system"/>
<string key="title">hello, my apologies but this app requires a window for discord to notice us. you're welcome to close it, we just have to have had a window
......@@ -708,6 +713,13 @@ also should've probably closed itself</string>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="whX-hn-moM" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" constant="20" id="5Po-N8-hNw"/>
<constraint firstItem="whX-hn-moM" firstAttribute="centerY" secondItem="vE1-Uh-CW4" secondAttribute="centerY" constant="12.5" id="FiL-wa-Z5z"/>
<constraint firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="whX-hn-moM" secondAttribute="trailing" constant="20" symbolic="YES" id="O8X-eI-MFk"/>
<constraint firstItem="whX-hn-moM" firstAttribute="leading" secondItem="vE1-Uh-CW4" secondAttribute="trailing" constant="-100" id="gxE-Bd-09g"/>
<constraint firstItem="whX-hn-moM" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" constant="20" id="q02-Qd-ULm"/>
</constraints>
</view>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
......
......@@ -19,13 +19,17 @@
<key>CFBundleShortVersionString</key>
<string>2.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.music</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
<true/>
<key>NSAppleEventsUsageDescription</key>
<string>iTunesRPC needs to talk to Music in order to operate.</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 Spotlight IsHere. All rights reserved.</string>
<string>Copyright © 2020 Spotlight Deveaux. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>NSPrincipalClass</key>
......
......@@ -18,7 +18,7 @@ class ViewController: NSViewController {
let rpc = SwordRPC(appId: "402370117901484042")
var currentTitle = ""
let mediaController = MediaRemoteController()
override func viewDidLoad() {
super.viewDidLoad()
let distributed = DistributedNotificationCenter.default
......@@ -26,57 +26,97 @@ class ViewController: NSViewController {
selector: #selector(infoDidChange),
name: NSNotification.Name(rawValue: "com.apple.iTunes.playerInfo"),
object: nil)
// Callback for when RPC connects.
rpc.onConnect { (_) in
var presence = RichPresence()
presence.details = "Loading."
presence.state = "Getting details from Music..."
self.rpc.setPresence(presence)
print("Connected to Discord.")
self.updateEmbed()
}
// This probably could be a race condition.
// Let's hope it connects in under 15 seconds.
Timer.scheduledTimer(withTimeInterval: 15.0, repeats: true) { (_) in
self.updateEmbed()
}
rpc.connect()
}
@objc func infoDidChange(notification : Notification) {
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."
} else if playingState == "Stopped" {
presence.assets.smallImage = "stop"
presence.details = "iTunes is stopped."
presence.state = "Nothing is happening."
let itunes: AnyObject = SBApplication(bundleIdentifier: "com.apple.Music")!
let track = itunes.currentTrack
if (track != nil) {
// Something's doing something, player can't be nil.. right?
let playerState = itunes.playerState!
// Something's marked as playing, time to see..
switch (playerState) {
case .iTunesEPlSPlaying:
let sureTrack = track!
presence.details = "\(sureTrack.name!)"
presence.state = "\(sureTrack.album!) - \(sureTrack.artist!)"
presence.assets.largeImage = "itunes_logo"
// The following needs to be in milliseconds.
let trackDuration = Double(round(sureTrack.duration!))
let trackPosition = Double(round(itunes.playerPosition!))
let currentTimestamp = Date()
let trackSecondsRemaining = trackDuration - trackPosition
let startTimestamp = currentTimestamp - trackPosition
let endTimestamp = currentTimestamp + trackSecondsRemaining
// Go back (position amount)
presence.timestamps.start = Date(timeIntervalSince1970: startTimestamp.timeIntervalSince1970 * 1000)
// Add time remaining
presence.timestamps.end = Date(timeIntervalSince1970: endTimestamp.timeIntervalSince1970 * 1000)
break
case .iTunesEPlSPaused:
presence.details = "Paused."
presence.state = "Holding your spot in the beat."
break
case .iTunesEPlSStopped:
presence.details = "Music is stopped."
presence.state = "Nothing's happening."
break
default:
presence.details = "Music is most likely closed."
presence.state = "If so, please quit this app. If not, please file a bug."
}
} 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()
}
rpc.setPresence(presence)
}
}
// xo https://stackoverflow.com/a/35360697
extension String {
func fromBase64() -> String? {
guard let data = Data(base64Encoded: self) else {
return nil
}
return String(data: data, encoding: .utf8)
}
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/>
<dict>
<key>com.apple.security.automation.apple-events</key>
<true/>
</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