Skip to content

Commit 1f4d660

Browse files
committed
Add sticky notification option to notify plugin.
1 parent 6998d21 commit 1f4d660

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

src/jupyter_contrib_nbextensions/nbextensions/notify/notify.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,32 @@ Add this file to $(ipython locate)/nbextensions/
88
99
*/
1010

11-
define(["require"], function (require) {
11+
define([
12+
"jquery",
13+
"base/js/namespace",
14+
"base/js/utils",
15+
"services/config",
16+
], function ($, IPython, utils, configmod) {
1217
"use strict";
1318

19+
var params = {
20+
sticky: false
21+
};
22+
23+
var base_url = utils.get_body_data("baseUrl");
24+
var config = new configmod.ConfigSection('notebook', {base_url: base_url});
25+
26+
var update_params = function() {
27+
for (var key in params) {
28+
if (config.data.hasOwnProperty(key)) {
29+
params[key] = config.data[key];
30+
}
31+
}
32+
}
33+
config.loaded.then(function() {
34+
update_params();
35+
})
36+
1437
var current_time = function() {
1538
return new Date().getTime() / 1000;
1639
};
@@ -95,7 +118,10 @@ define(["require"], function (require) {
95118
var notify = function () {
96119
var elapsed_time = current_time() - start_time;
97120
if (enabled && !first_start && !busy_kernel && elapsed_time >= min_time) {
98-
var n = new Notification(IPython.notebook.notebook_name, {body: "Kernel is now idle\n(ran for " + Math.round(elapsed_time) + " secs)"});
121+
var n = new Notification(IPython.notebook.notebook_name, {
122+
body: "Kernel is now idle\n(ran for " + Math.round(elapsed_time) + " secs)",
123+
requireInteraction: params.sticky
124+
});
99125
n.onclick = function(event){ window.focus(); }
100126
}
101127
if (first_start) {
@@ -155,6 +181,7 @@ define(["require"], function (require) {
155181
};
156182

157183
var load_ipython_extension = function () {
184+
config.load();
158185
ensure_permission();
159186
setup_notifier();
160187
};

src/jupyter_contrib_nbextensions/nbextensions/notify/notify.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ Link: readme.md
77
Icon: notification.png
88
Main: notify.js
99
Compatibility: 4.x, 5.x
10+
Parameters:
11+
- name: sticky
12+
description: Require interactions on notifications to dismiss them.
13+
input_type: checkbox
14+
default: false

src/jupyter_contrib_nbextensions/nbextensions/notify/readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ trigger a notification (e.g. if selecting 5, a notification will only be shown
1616
if the kernel was busy for more than 5 seconds). The selection is saved in the
1717
notebook's metadata and restored when the notebook is re-opened.
1818

19+
You may configure the plugin so that notifications require manual dismissal
20+
before disappearing. Browser support is limited, see
21+
[here](https://developer.mozilla.org/en-US/docs/Web/API/notification/requireInteraction)
22+
to check if your browser supports this.
23+
1924
![notification](notification.png "notification")
2025

2126

@@ -33,4 +38,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
3338

3439
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
3540

36-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)