From e128e9fabc9ef65f5b07aa682cd310d5ec8ac563 Mon Sep 17 00:00:00 2001 From: "Mark J. Titorenko" Date: Fri, 1 Mar 2013 14:58:01 +0000 Subject: [PATCH] Fluid notifications (to support Fluid App, http://fluidapp.com) --- .../javascripts/backbone/kandan.js.coffee.erb | 1 + .../backbone/plugins/notifications.js.coffee | 57 +++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/backbone/kandan.js.coffee.erb b/app/assets/javascripts/backbone/kandan.js.coffee.erb index f97a47bb..1d68c318 100644 --- a/app/assets/javascripts/backbone/kandan.js.coffee.erb +++ b/app/assets/javascripts/backbone/kandan.js.coffee.erb @@ -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') ) diff --git a/app/assets/javascripts/backbone/plugins/notifications.js.coffee b/app/assets/javascripts/backbone/plugins/notifications.js.coffee index d85029b8..84f580b2 100644 --- a/app/assets/javascripts/backbone/plugins/notifications.js.coffee +++ b/app/assets/javascripts/backbone/plugins/notifications.js.coffee @@ -5,21 +5,27 @@ class Kandan.Plugins.Notifications @pluginNamespace: "Kandan.Plugins.Notifications" @popup_notifications_template: _.template '' - @enable_popup_notifications_template = _.template ' Notifications' - @disable_popup_notifications_template = _.template ' Notifications' + @enable_popup_notifications_template = _.template ' Desktop notifications' + @disable_popup_notifications_template = _.template ' Desktop notifications' @sound_notifications_template: _.template '
' @enable_sound_notifications_template = _.template ' Sounds' @disable_sound_notifications_template = _.template ' Sounds' + @fluid_notifications_template: _.template '
' + @enable_fluid_notifications_template = _.template ' Fluid notifications' + @disable_fluid_notifications_template = _.template ' Fluid notifications' + @render: ($el)-> $notifications = $("
") $el.next().hide(); @initPopupsNotificationsButtons() + @initFluidNotificationsButtons() $el.html($notifications) + @initFluidNotifications($notifications) @initWebkitNotifications($notifications) @initSoundNotifications($notifications) @@ -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() @@ -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). @@ -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)->