@ -6,7 +6,7 @@
* @ licstart The following is the entire license notice for the
* JavaScript code in this file .
*
* Copyright ( c ) 2013 , The Roundcube Dev Team
* Copyright ( c ) 2013 - 2016 , The Roundcube Dev Team
*
* The JavaScript code in this page is free software : you can redistribute it
* and / or modify it under the terms of the GNU General Public License
@ -18,13 +18,13 @@
* /
if ( window . rcmail && rcmail . env . task == 'mail' ) {
rcmail . addEventListener ( 'plugin.newmail_notifier' , newmail _notifier _run ) ;
rcmail . addEventListener ( 'actionbefore' , newmail _notifier _stop ) ;
rcmail . addEventListener ( 'init' , function ( ) {
// bind to messages list select event, so favicon will be reverted on message preview too
if ( rcmail . message _list )
rcmail . message _list . addEventListener ( 'select' , newmail _notifier _stop ) ;
} ) ;
rcmail . addEventListener ( 'plugin.newmail_notifier' , newmail _notifier _run )
. addEventListener ( 'actionbefore' , newmail _notifier _stop )
. addEventListener ( 'init' , function ( ) {
// bind to messages list select event, so favicon will be reverted on message preview too
if ( rcmail . message _list )
rcmail . message _list . addEventListener ( 'select' , newmail _notifier _stop ) ;
} ) ;
}
// Executes notification methods
@ -35,7 +35,7 @@ function newmail_notifier_run(prop)
if ( prop . sound )
newmail _notifier _sound ( ) ;
if ( prop . desktop )
newmail _notifier _desktop ( rcmail . get text ( 'body' , 'newmail_notifier' ) ) ;
newmail _notifier _desktop ( rcmail . get _label ( 'body' , 'newmail_notifier' ) ) ;
}
// Stops notification
@ -76,7 +76,7 @@ function newmail_notifier_basic()
// Add IE icon overlay if we're pinned to Taskbar
try {
if ( window . external . msIsSiteMode ( ) ) {
window . external . msSiteModeSetIconOverlay ( path + '/overlay.ico' , rcmail . get text ( 'title' , 'newmail_notifier' ) ) ;
window . external . msSiteModeSetIconOverlay ( path + '/overlay.ico' , rcmail . get _label ( 'title' , 'newmail_notifier' ) ) ;
}
} catch ( e ) { }
}
@ -106,77 +106,46 @@ function newmail_notifier_sound()
}
// Desktop notification
// - Require Chrome or Firefox latest version ( 22+) / 21.0 or older with a plugin
function newmail _notifier _desktop ( body )
// - Require window.Notification API support ( Chrome 22+ or Firefox 22+)
function newmail _notifier _desktop ( body , disabled _callback )
{
var timeout = rcmail . env . newmail _notifier _timeout || 10 ,
icon = rcmail . assets _path ( 'plugins/newmail_notifier/mail.png' ) ;
// As of 17 June 2013, Chrome/Chromium does not implement Notification.permission correctly that
// it gives 'undefined' until an object has been created:
// https://code.google.com/p/chromium/issues/detail?id=163226
try {
if ( Notification . permission == 'granted' || Notification . permission == undefined ) {
var popup = new Notification ( rcmail . gettext ( 'title' , 'newmail_notifier' ) , {
icon = rcmail . assets _path ( 'plugins/newmail_notifier/mail.png' ) ,
success _callback = function ( ) {
var popup = new window . Notification ( rcmail . get _label ( 'title' , 'newmail_notifier' ) , {
dir : "auto" ,
lang : "" ,
body : body ,
tag : "newmail_notifier" ,
icon : icon
} ) ;
popup . onclick = function ( ) {
this . close ( ) ;
}
popup . onclick = function ( ) { this . close ( ) ; } ;
setTimeout ( function ( ) { popup . close ( ) ; } , timeout * 1000 ) ;
if ( popup . permission == 'granted' ) return true ;
}
} ;
try {
window . Notification . requestPermission ( function ( perm ) {
if ( perm == 'granted' )
success _callback ( ) ;
else if ( perm == 'denied' && disabled _callback )
disabled _callback ( ) ;
} ) ;
return true ;
}
catch ( e ) {
var dn = window . webkitNotifications ;
if ( dn && ! dn . checkPermission ( ) ) {
if ( rcmail . newmail _popup )
rcmail . newmail _popup . cancel ( ) ;
var popup = window . webkitNotifications . createNotification ( icon ,
rcmail . gettext ( 'title' , 'newmail_notifier' ) , body ) ;
popup . onclick = function ( ) {
this . cancel ( ) ;
}
popup . show ( ) ;
setTimeout ( function ( ) { popup . cancel ( ) ; } , timeout * 1000 ) ;
rcmail . newmail _popup = popup ;
return true ;
}
return false ;
}
return false ;
}
function newmail _notifier _test _desktop ( )
{
var txt = rcmail . gettext ( 'testbody' , 'newmail_notifier' ) ;
var status = newmail _notifier _desktop ( rcmail . get _label ( 'testbody' , 'newmail_notifier' ) , function ( ) {
rcmail . display _message ( rcmail . get _label ( 'desktopdisabled' , 'newmail_notifier' ) , 'error' ) ;
} ) ;
// W3C draft implementation (with fix for Chrome/Chromium)
try {
var testNotification = new window . Notification ( txt , { tag : "newmail_notifier" } ) ; // Try to show a test message
if ( Notification . permission !== 'granted' || ( testNotification . permission && testNotification . permission !== 'granted' ) )
newmail _notifier _desktop _authorize ( ) ;
}
// webkit implementation
catch ( e ) {
var dn = window . webkitNotifications ;
if ( dn ) {
if ( ! dn . checkPermission ( ) )
newmail _notifier _desktop ( txt ) ;
else
dn . requestPermission ( function ( ) {
if ( ! newmail _notifier _desktop ( txt ) )
rcmail . display _message ( rcmail . gettext ( 'desktopdisabled' , 'newmail_notifier' ) , 'error' ) ;
} ) ;
}
else
// Everything fails, means the browser has no support
rcmail . display _message ( rcmail . gettext ( 'desktopunsupported' , 'newmail_notifier' ) , 'error' ) ;
if ( ! status ) {
rcmail . display _message ( rcmail . get _label ( 'desktopunsupported' , 'newmail_notifier' ) , 'error' ) ;
}
}
@ -189,12 +158,3 @@ function newmail_notifier_test_sound()
{
newmail _notifier _sound ( ) ;
}
function newmail _notifier _desktop _authorize ( ) {
Notification . requestPermission ( function ( perm ) {
if ( perm == 'denied' )
rcmail . display _message ( rcmail . gettext ( 'desktopdisabled' , 'newmail_notifier' ) , 'error' ) ;
if ( perm == 'granted' )
newmail _notifier _test _desktop ( ) ; // Test again, which should show test message
} ) ;
}