Skip to content

Commit

Permalink
Add shuffle and repeat menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
steve228uk committed Jul 5, 2018
1 parent 9dae511 commit e701b9b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Binary file not shown.
13 changes: 13 additions & 0 deletions YT Music/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(NSMenuItem(title: "Next", action: #selector(nextTrack), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Previous", action: #selector(previousTrack), keyEquivalent: ""))
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Shuffle", action: #selector(shuffleTracks), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Repeat", action: #selector(repeatTracks), keyEquivalent: ""))
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Like", action: #selector(likeTrack), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Dislike", action: #selector(dislikeTrack), keyEquivalent: ""))
return menu
Expand Down Expand Up @@ -78,5 +81,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
.performSelector(onMainThread: #selector(ViewController.dislikeTrack), with: nil, waitUntilDone: true)
}

@objc func repeatTracks(_ sender: Any?) {
mainWindowController?.window?.contentViewController?
.performSelector(onMainThread: #selector(ViewController.repeatTracks), with: nil, waitUntilDone: true)
}

@objc func shuffleTracks(_ sender: Any?) {
mainWindowController?.window?.contentViewController?
.performSelector(onMainThread: #selector(ViewController.shuffleTracks), with: nil, waitUntilDone: true)
}

}

11 changes: 11 additions & 0 deletions YT Music/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@
<action selector="previousTrack:" target="Ady-hI-5gd" id="heq-zF-PP6"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="0Ku-CO-331"/>
<menuItem title="Shuffle" keyEquivalent="s" id="ZZg-XZ-mDf">
<connections>
<action selector="shuffleTracks:" target="Ady-hI-5gd" id="zrI-kM-qzO"/>
</connections>
</menuItem>
<menuItem title="Repeat" keyEquivalent="r" id="cJf-AS-lZ7">
<connections>
<action selector="repeatTracks:" target="Ady-hI-5gd" id="81t-sq-vlN"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="Y4d-Hi-54I"/>
<menuItem title="Like" keyEquivalent="l" id="GYC-cp-9M7">
<connections>
Expand Down
8 changes: 8 additions & 0 deletions YT Music/Controllers/ViewController + MediaKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ extension ViewController: MediaKeyTapDelegate {
clickElement(className: "dislike")
}

@objc func shuffleTracks() {
clickElement(className: "shuffle")
}

@objc func repeatTracks() {
clickElement(className: "repeat")
}

func clickElement(className: String) {
let js = "var elements = document.getElementsByClassName('\(className)'); if(elements.length > 0) { elements[0].click(); }";
webView.evaluateJavaScript(js) { (_, error) in
Expand Down

0 comments on commit e701b9b

Please sign in to comment.