From f806ed5c9e66e970efb958f087530b1b75afcd78 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 12 Sep 2013 06:06:12 -0400
Subject: [PATCH] Implemented configurable timeout for desktop notification (#1489205)
---
plugins/newmail_notifier/newmail_notifier.php | 25 +++++++++++++++++++++++++
plugins/newmail_notifier/package.xml | 4 ++--
plugins/newmail_notifier/config.inc.php.dist | 3 +++
plugins/newmail_notifier/newmail_notifier.js | 14 ++++++--------
plugins/newmail_notifier/localization/en_US.inc | 1 +
5 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/plugins/newmail_notifier/config.inc.php.dist b/plugins/newmail_notifier/config.inc.php.dist
index cdb563c..1a7c0d7 100644
--- a/plugins/newmail_notifier/config.inc.php.dist
+++ b/plugins/newmail_notifier/config.inc.php.dist
@@ -9,4 +9,7 @@
// Enables desktop notification
$config['newmail_notifier_desktop'] = false;
+// Desktop notification close timeout in seconds
+$config['newmail_notifier_desktop_timeout'] = 10;
+
?>
diff --git a/plugins/newmail_notifier/localization/en_US.inc b/plugins/newmail_notifier/localization/en_US.inc
index 7c1c5cf..1c40546 100644
--- a/plugins/newmail_notifier/localization/en_US.inc
+++ b/plugins/newmail_notifier/localization/en_US.inc
@@ -25,5 +25,6 @@
$labels['testbody'] = 'This is a test notification.';
$labels['desktopdisabled'] = 'Desktop notifications are disabled in your browser.';
$labels['desktopunsupported'] = 'Your browser does not support desktop notifications.';
+$labels['desktoptimeout'] = 'Close desktop notification';
?>
diff --git a/plugins/newmail_notifier/newmail_notifier.js b/plugins/newmail_notifier/newmail_notifier.js
index b00f33d..846bc94 100644
--- a/plugins/newmail_notifier/newmail_notifier.js
+++ b/plugins/newmail_notifier/newmail_notifier.js
@@ -90,13 +90,11 @@
// - Require Chrome or Firefox latest version (22+) / 21.0 or older with a plugin
function newmail_notifier_desktop(body)
{
+ var timeout = rcmail.env.newmail_notifier_timeout || 10;
-/**
- * Fix: 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
- *
- */
+ // 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'), {
@@ -109,7 +107,7 @@
popup.onclick = function() {
this.close();
}
- setTimeout(function() { popup.close(); }, 10000); // close after 10 seconds
+ setTimeout(function() { popup.close(); }, timeout * 1000);
if (popup.permission == 'granted') return true;
}
}
@@ -125,7 +123,7 @@
this.cancel();
}
popup.show();
- setTimeout(function() { popup.cancel(); }, 10000); // close after 10 seconds
+ setTimeout(function() { popup.cancel(); }, timeout * 1000);
rcmail.newmail_popup = popup;
return true;
}
diff --git a/plugins/newmail_notifier/newmail_notifier.php b/plugins/newmail_notifier/newmail_notifier.php
index ca1c2ff..20c542f 100644
--- a/plugins/newmail_notifier/newmail_notifier.php
+++ b/plugins/newmail_notifier/newmail_notifier.php
@@ -123,6 +123,23 @@
}
}
+ $type = 'desktop_timeout';
+ $key = 'newmail_notifier_' . $type;
+ if (!in_array($key, $dont_override)) {
+ $field_id = '_' . $key;
+ $select = new html_select(array('name' => $field_id, 'id' => $field_id));
+
+ foreach (array(5, 10, 15, 30, 45, 60) as $sec) {
+ $label = $this->rc->gettext(array('name' => 'afternseconds', 'vars' => array('n' => $sec)));
+ $select->add($label, $sec);
+ }
+
+ $args['blocks']['new_message']['options'][$key] = array(
+ 'title' => html::label($field_id, rcube::Q($this->gettext('desktoptimeout'))),
+ 'content' => $select->show((int) $this->rc->config->get($key))
+ );
+ }
+
return $args;
}
@@ -145,6 +162,13 @@
$key = 'newmail_notifier_' . $type;
if (!in_array($key, $dont_override)) {
$args['prefs'][$key] = rcube_utils::get_input_value('_'.$key, rcube_utils::INPUT_POST) ? true : false;
+ }
+ }
+
+ $option = 'newmail_notifier_desktop_timeout';
+ if (!in_array($option, $dont_override)) {
+ if ($value = (int) rcube_utils::get_input_value('_' . $option, rcube_utils::INPUT_POST)) {
+ $args['prefs'][$option] = $value;
}
}
@@ -180,6 +204,7 @@
if ($unseen->count()) {
$this->notified = true;
+ $this->rc->output->set_env('newmail_notifier_timeout', $this->rc->config->get('newmail_notifier_desktop_timeout'));
$this->rc->output->command('plugin.newmail_notifier',
array(
'basic' => $this->opt['basic'],
diff --git a/plugins/newmail_notifier/package.xml b/plugins/newmail_notifier/package.xml
index b8ef349..e46c9bc 100644
--- a/plugins/newmail_notifier/package.xml
+++ b/plugins/newmail_notifier/package.xml
@@ -19,9 +19,9 @@
<email>alec@alec.pl</email>
<active>yes</active>
</lead>
- <date>2013-03-16</date>
+ <date>2013-09-12</date>
<version>
- <release>0.5</release>
+ <release>0.6</release>
<api>0.5</api>
</version>
<stability>
--
Gitblit v1.9.1