Skip to content

Commit

Permalink
Some minor tweaks to track viewing
Browse files Browse the repository at this point in the history
  • Loading branch information
whomwah committed Dec 9, 2013
1 parent 5cbf441 commit 529b1b0
Show file tree
Hide file tree
Showing 22 changed files with 198 additions and 727 deletions.
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ gem "motion-cocoapods", "~> 1.4.0"
gem "motion-sparkle", "~> 0.0.3"
gem "bubble-wrap", "~> 1.4.0"
gem "motion-stump", "~> 0.3.0"
gem "kyan_jukebox", :path => "/Users/duncan/_dev/kyan/gems/kyan_jukebox"
gem 'sugarcube', "~> 1.3.7", :require => [
'sugarcube-attributedstring',
]
#gem "kyan_jukebox", :path => "/Users/duncan/_dev/kyan/gems/kyan_jukebox"
gem "kyan_jukebox", :git => '[email protected]:kyan/kyan_jukebox.git'
15 changes: 9 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
PATH
remote: /Users/duncan/_dev/kyan/gems/kyan_jukebox
GIT
remote: [email protected]:kyan/kyan_jukebox.git
revision: 2785b19d4b662a73a7fd20a91fbb6352a973d7dd
specs:
kyan_jukebox (0.0.1)
kyan_jukebox (0.1.2)

GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.15)
activesupport (3.2.16)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
bubble-wrap (1.4.0)
Expand All @@ -30,17 +31,18 @@ GEM
colored (1.2)
escape (0.0.4)
fuzzy_match (2.0.4)
i18n (0.6.5)
i18n (0.6.9)
json (1.8.1)
json_pure (1.8.1)
motion-cocoapods (1.4.0)
cocoapods (>= 0.26.2)
motion-sparkle (0.0.3)
motion-stump (0.3.0)
multi_json (1.8.2)
nap (0.5.1)
nap (0.6.0)
open4 (1.3.0)
rake (10.1.0)
sugarcube (1.3.7)
xcodeproj (0.14.1)
activesupport (~> 3.0)
colored (~> 1.2)
Expand All @@ -56,3 +58,4 @@ DEPENDENCIES
motion-sparkle (~> 0.0.3)
motion-stump (~> 0.3.0)
rake
sugarcube (~> 1.3.7)
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Motion::Project::App.setup do |app|

app.sparkle do
release :base_url, 'https://raw.github.com/kyan/kyan_bar/master'
release :version, '1.0.4'
release :version, '1.0.5'

# Optional settings
release :feed_filename, 'releases.xml'
Expand Down
6 changes: 3 additions & 3 deletions app/app_delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ class AppDelegate

def applicationDidFinishLaunching(notification)
build_jukebox
buildStatus
build_status
handle_notifications

@reconn_interval = 0.0
connect_to_websocket_server
end

def buildStatus
def build_status
@status_bar_image = NSImage.imageNamed("k_logo_col_18x18")
@status_bar_image_alt = NSImage.imageNamed("k_logo_bw_18x18")

Expand All @@ -32,7 +32,7 @@ def build_preferences(sender)
end

def build_jukebox
@jukebox ||= KyanJukebox::Notify.new([:track])
@jukebox ||= KyanJukebox::Notify.new([:track, :playlist])
@jukebox.json_parser = BW::JSON
end

Expand Down
7 changes: 6 additions & 1 deletion app/config/constants.rb
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
WEBSOCKET_URL = 'ws://jukebox.local:8080'
WEBSOCKET_URL = 'ws://jukebox.local:8080'

TRACK_TITLE=1
TRACK_ARTIST=2
TRACK_ARTWORK_URL=3
TRACK_ALBUM=4
7 changes: 0 additions & 7 deletions app/controllers/jukebox_view_controller.rb

This file was deleted.

6 changes: 1 addition & 5 deletions app/lib/SRWebSocketDelegate.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class SRWebSocketDelegate

def self.webSocket(webSocket, didReceiveMessage:msg)
puts "Message: #{msg}"
jukebox = App.shared.delegate.jukebox
jukebox.update!(msg.dataUsingEncoding(NSUTF8StringEncoding))
jukebox.notifications.each do |message|
Expand All @@ -15,13 +14,10 @@ def self.webSocket(webSocket, didReceiveMessage:msg)
end

def self.webSocketDidOpen(webSocket)
puts "Socket connection opened!"
App.shared.delegate.reconn_interval = 0.0
end

def self.webSocket(webSocket, didFailWithError:error)
puts "Lost Connection!!"

NSTimer.scheduledTimerWithTimeInterval(App.shared.delegate.reconn_interval,
target:App.shared.delegate,
selector:'reconnect_to_websocket_server',
Expand All @@ -31,6 +27,6 @@ def self.webSocket(webSocket, didFailWithError:error)
end

def self.webSocket(webSocket, didCloseWithCode:code, reason:reason, wasClean:wasClean)
puts "Bang again!!"
# Bang!
end
end
114 changes: 96 additions & 18 deletions app/menu.rb
Original file line number Diff line number Diff line change
@@ -1,55 +1,133 @@
class AppDelegate
def setupMenu
menu = NSMenu.new
menu.initWithTitle App.name
@menu = NSMenu.new
@menu.initWithTitle App.name
@jukebox = App.shared.delegate.jukebox

# mi = NSMenuItem.new
# @jukebox_menu = JukeboxViewController.alloc.initWithNibName("Jukebox", bundle:nil)
# @jukebox_menu.setRepresentedObject(App.shared.delegate.jukebox)
# mi.view = @jukebox_menu.view
# menu.addItem mi
build_now_playing
add_seperator

# add_seperator(menu)
unless jukebox.playlist.empty?
build_upcoming_tracks
end

links.each_with_index do |data, i|
m = NSMenuItem.new
m.title = data.first
m.tag = i
m.setImage( NSImage.imageNamed(data.first.downcase) )
m.action = 'open_link:'
menu.addItem m
@menu.addItem m
end

add_seperator(menu)
build_submenu

@menu
end

private

def build_submenu
sub_menu = NSMenu.new
mi = NSMenuItem.new
mi.title = 'Preferences...'
mi.action = 'build_preferences:'
menu.addItem mi
sub_menu.addItem mi

mi = NSMenuItem.new
mi.title = 'Check for updates...'
mi.action = 'checkForUpdates:'
mi.target = SUUpdater.new
menu.addItem mi
sub_menu.addItem mi

mi = NSMenuItem.new
mi.title = 'Quit'
mi.action = 'terminate:'
menu.addItem mi
sub_menu.addItem mi

add_seperator

mi = NSMenuItem.new
mi.title = 'Settings'
mi.setSubmenu(sub_menu)
@menu.addItem mi
end

menu
def build_now_playing
@jukebox_menu = NSViewController.alloc.initWithNibName("Jukebox", bundle:nil)
@jukebox_view = @jukebox_menu.view
@jukebox_view.jukebox = @jukebox

mi = NSMenuItem.new
mi.view = @jukebox_view
@menu.addItem mi
end

def build_upcoming_tracks
@jukebox.playlist.take(3).each do |track|
m = NSMenuItem.new
m.setAttributedTitle(
track.title.attrd({
'NSFont' => NSFont.fontWithName("Lucida Grande", size:12),
'NSColor' => NSColor.blackColor
}) + "\n" +
track.artist.attrd({
'NSFont' => NSFont.fontWithName("Lucida Grande", size:10),
'NSColor' => NSColor.darkGrayColor
}) + " - " +
track.album.attrd({
'NSFont' => NSFont.fontWithName("Lucida Grande", size:10),
'NSColor' => NSColor.lightGrayColor
})
)
m.tag = track.dbid
add_menu_icon_for(m, track.artwork_url)

@menu.addItem m
end

add_seperator if @jukebox.playlist.any?
end

def add_menu_icon_for(menu, img_url)
image_url = if img_url.nil?
"http://www.appledystopia.com/wp-content/uploads/2013/03/missing-itunes-album-art-icon.png"
else
img_url
end

Dispatch::Queue.concurrent.async do
new_size = NSMakeSize(32, 32)
url = NSURL.URLWithString(image_url)
image_data = NSData.alloc.initWithContentsOfURL(url)
image = NSImage.alloc.initWithData(image_data)
image.setScalesWhenResized(true)

resized_img = NSImage.alloc.initWithSize(new_size)
originalSize = image.size

resized_img.lockFocus
image.setSize(new_size)
NSGraphicsContext.currentContext.setImageInterpolation(NSImageInterpolationHigh)
image.drawAtPoint(
NSZeroPoint,
fromRect: CGRectMake(0, 0, new_size.width, new_size.height),
operation: NSCompositeCopy,
fraction:1.0
)
resized_img.unlockFocus

menu.setImage(resized_img)
end
end

def open_link(sender)
url = NSURL.URLWithString( url_for_index(sender.tag) )
NSWorkspace.sharedWorkspace.openURL(url)
end

private

def add_seperator(menu)
menu.addItem NSMenuItem.separatorItem
def add_seperator
@menu.addItem NSMenuItem.separatorItem
end

def links
Expand Down
48 changes: 48 additions & 0 deletions app/views/jukebox_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class JukeBoxView < NSView

attr_accessor :jukebox

def viewWillDraw
update_title
update_artist
update_album
update_image

super
end

def track
jukebox.track unless jukebox.nil?
end

private

def update_title
txt = track.title.nil? ? '-' : track.title
viewWithTag(TRACK_TITLE).setStringValue(txt)
end

def update_artist
txt = track.artist.nil? ? '-' : track.artist
viewWithTag(TRACK_ARTIST).setStringValue(txt)
end

def update_album
txt = track.album.nil? ? '-' : track.album
viewWithTag(TRACK_ALBUM).setStringValue(txt)
end

def update_image
image_url = if jukebox.track.artwork_url.nil?
"http://www.appledystopia.com/wp-content/uploads/2013/03/missing-itunes-album-art-icon.png"
else
jukebox.track.artwork_url
end

Dispatch::Queue.concurrent.async do
url = NSURL.URLWithString(image_url)
image = NSImage.alloc.initWithContentsOfURL(url)
viewWithTag(TRACK_ARTWORK_URL).setImage(image)
end
end
end
6 changes: 3 additions & 3 deletions release_notes.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
KyanBar - version 1.0.4
KyanBar - version 1.0.5
-----------------------

Updates:

* Preferences have their own Window
* You can choose whether to recieve updates, and when
* Current Playing Track in dropdown
* Move Settings in dropdown
11 changes: 6 additions & 5 deletions releases.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@
en
</language>
<pubDate>
Sun, 24 Nov 2013 18:49:13 +0000
Mon, 09 Dec 2013 13:15:03 +0000
</pubDate>
<atom:link href='https://raw.github.com/kyan/kyan_bar/master/releases.xml' rel='self' type='application/rss+xml'/>
<item>
<title>
KyanBar 1.0.4
KyanBar 1.0.5
</title>
<pubDate>
Sun, 24 Nov 2013 18:49:13 +0000
Mon, 09 Dec 2013 13:15:03 +0000
</pubDate>
<guid isPermaLink='false'>
KyanBar-1.0.4
KyanBar-1.0.5
</guid>
<sparkle:releaseNotesLink>
https://raw.github.com/kyan/kyan_bar/master/release_notes.html
</sparkle:releaseNotesLink>
<enclosure url='https://github.com/kyan/kyan_bar/releases/download/1.0.4/KyanBar.zip' length='3357967' type='application/octet-stream' sparkle:version='1.0.4' sparkle:dsaSignature='MCwCFCCe+AYoyhu1RpwRjwZK0YiVHzjmAhQEAaUnsYr711VNStecu4XbX+83qQ=='/>
<enclosure url='https://github.com/kyan/kyan_bar/releases/download/1.0.5/KyanBar.zip' length='3616623' type='application/octet-stream' sparkle:version='1.0.5' sparkle:dsaSignature='MC0CFG22Q59nwcmRTJzep4PfLd9l2fUJAhUAkLHBeZA47kq2ny+bW43epMWKOU0='/>
</item>
</channel>
</rss>


Loading

0 comments on commit 529b1b0

Please sign in to comment.