Skip to content

Commit

Permalink
Merge pull request #151 from mjtko/proposal/fluidapp-notifications
Browse files Browse the repository at this point in the history
Fluid notifications (to support Fluid, http://fluidapp.com)
  • Loading branch information
gabceb committed Mar 1, 2013
2 parents 3b39026 + e128e9f commit c48996b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/backbone/kandan.js.coffee.erb
Expand Up @@ -58,6 +58,7 @@ window.Kandan =
$(window).focus(->
Kandan.Helpers.Utils.browserTabFocused = true
Kandan.Helpers.Utils.resetUnreadActivities()
Kandan.Plugins.Notifications?.resetUnreadActivities()
$(document).attr('title', 'Kandan')
)

Expand Down
57 changes: 53 additions & 4 deletions app/assets/javascripts/backbone/plugins/notifications.js.coffee
Expand Up @@ -5,21 +5,27 @@ class Kandan.Plugins.Notifications
@pluginNamespace: "Kandan.Plugins.Notifications"

@popup_notifications_template: _.template '<div class="notification popup-notifications"></div>'
@enable_popup_notifications_template = _.template '<a class="btn enable-popup-notifications" href="#"><i class="icon-check-empty"></i> Notifications</a>'
@disable_popup_notifications_template = _.template '<a class="btn disable-popup-notifications" href="#"><i class="icon-check"></i> Notifications</a>'
@enable_popup_notifications_template = _.template '<a class="btn enable-popup-notifications" href="#"><i class="icon-check-empty"></i> Desktop notifications</a>'
@disable_popup_notifications_template = _.template '<a class="btn disable-popup-notifications" href="#"><i class="icon-check"></i> Desktop notifications</a>'

@sound_notifications_template: _.template '<div class="notification sound-notifications"></div>'
@enable_sound_notifications_template = _.template '<a class="btn enable-sound-notifications" href="#"><i class="icon-check-empty"></i> Sounds</a>'
@disable_sound_notifications_template = _.template '<a class="btn disable-sound-notifications" href="#"><i class="icon-check"></i> Sounds</a>'

@fluid_notifications_template: _.template '<div class="notification fluid-notifications"></div>'
@enable_fluid_notifications_template = _.template '<a class="btn enable-fluid-notifications" href="#"><i class="icon-check-empty"></i> Fluid notifications</a>'
@disable_fluid_notifications_template = _.template '<a class="btn disable-fluid-notifications" href="#"><i class="icon-check"></i> Fluid notifications</a>'

@render: ($el)->
$notifications = $("<div class='notifications_list'></div>")
$el.next().hide();

@initPopupsNotificationsButtons()
@initFluidNotificationsButtons()

$el.html($notifications)

@initFluidNotifications($notifications)
@initWebkitNotifications($notifications)
@initSoundNotifications($notifications)

Expand All @@ -36,7 +42,7 @@ class Kandan.Plugins.Notifications
return

@initWebkitNotifications: (container)->
if Modernizr.notification
if Modernizr.notification && not window.fluid
container.append(@popup_notifications_template())

if @webkitNotificationsEnabled()
Expand Down Expand Up @@ -79,6 +85,30 @@ class Kandan.Plugins.Notifications

return

# Fluid notifications -- http://fluidapp.com
@initFluidNotificationsButtons: ()->
$(document).on 'click', '.enable-fluid-notifications', => @enableFluidNotifications()
$(document).on 'click', '.disable-fluid-notifications', => @disableFluidNotifications()
return

@initFluidNotifications: (container)->
if window.fluid
container.append(@fluid_notifications_template())
@enableFluidNotifications()
return

@enableFluidNotifications: ()->
@fluid_notifications_enabled = true
$(".fluid-notifications .enable-fluid-notifications").remove()
$(".notification.fluid-notifications").append(@disable_fluid_notifications_template())
return

@disableFluidNotifications: ()->
@fluid_notifications_enabled = false
$(".fluid-notifications .disable-fluid-notifications").remove()
$(".notification.fluid-notifications").append(@enable_fluid_notifications_template())
return

# If you are wondering why the kandan icon is not displayed on OS X this is the reason:
# If you try notifying users on MacOS Mountain Lion, using a custom notification icon, don't be surprised that the Web browser icon overrides the icon you defined.
# Apple locked notification icons to the app icons (for instance Chrome icon).
Expand All @@ -90,7 +120,26 @@ class Kandan.Plugins.Notifications
@cancel()
return

notification.show();
notification.show()

if @fluid_notifications_enabled
window.fluid.showGrowlNotification {
title: "Kandan",
description: "#{sender} says:\n\n#{message}",
priority: 1,
sticky: true,
identifier: "kandan",
#onclick: callbackFunc,
icon: '/assets/kandanlogo.png'
}
window.fluid.dockBadge = Kandan.Helpers.Utils.unreadActivities
window.fluid.requestUserAttention(false) # bounce once
return

@resetUnreadActivities: ()->
if @fluid_notifications_enabled
window.fluid.dockBadge = null
return

# HTML 5 sounds
@initSoundNotifications: ($container)->
Expand Down

0 comments on commit c48996b

Please sign in to comment.