Skip to content

Commit 13f88a0

Browse files
author
Stephen Brennan
committed
Add support for sound in notify plugin.
1 parent 4b37d26 commit 13f88a0

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/jupyter_contrib_nbextensions/nbextensions/notify/notify.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Add this file to $(ipython locate)/nbextensions/
1111
define([
1212
"jquery",
1313
"base/js/namespace",
14-
], function ($, IPython) {
14+
"require",
15+
], function ($, IPython, require) {
1516
"use strict";
1617

1718
var params = {
18-
sticky: false
19+
sticky: false,
20+
sound: false
1921
};
2022

2123
var current_time = function() {
@@ -102,10 +104,15 @@ define([
102104
var notify = function () {
103105
var elapsed_time = current_time() - start_time;
104106
if (enabled && !first_start && !busy_kernel && elapsed_time >= min_time) {
105-
var n = new Notification(IPython.notebook.notebook_name, {
107+
var opts = {
106108
body: "Kernel is now idle\n(ran for " + Math.round(elapsed_time) + " secs)",
109+
icon: "/static/base/images/favicon.ico",
107110
requireInteraction: params.sticky
108-
});
111+
};
112+
if (params.sound) {
113+
opts["sound"] = require.toUrl("./notify.mp3");
114+
}
115+
var n = new Notification(IPython.notebook.notebook_name, opts);
109116
n.onclick = function(event){ window.focus(); }
110117
}
111118
if (first_start) {
Binary file not shown.

src/jupyter_contrib_nbextensions/nbextensions/notify/notify.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Main: notify.js
99
Compatibility: 4.x, 5.x
1010
Parameters:
1111
- name: notify.sticky
12-
description: Require interactions on notifications to dismiss them.
12+
description: Require interactions on notifications to dismiss them. (Chrome only)
13+
input_type: checkbox
14+
default: false
15+
- name: notify.sound
16+
description: Play notification sound. (Not yet supported in browsers)
1317
input_type: checkbox
1418
default: false

src/jupyter_contrib_nbextensions/nbextensions/notify/readme.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ notebook's metadata and restored when the notebook is re-opened.
1919
You may configure the plugin so that notifications require manual dismissal
2020
before disappearing. Browser support is limited, see
2121
[here](https://developer.mozilla.org/en-US/docs/Web/API/notification/requireInteraction)
22-
to check if your browser supports this.
22+
to check if your browser supports this. You may also configure the plugin so
23+
that notifications play a sound, although this is currently
24+
[unsupported](https://developer.mozilla.org/en-US/docs/Web/API/notification/sound)
25+
in all major browsers.
2326

2427
![notification](notification.png "notification")
2528

2629

2730
## Original Source
2831
This extension originally comes from [@sjpfenniger](https://github.com/sjpfenninger)'s [GitHub repository](https://github.com/sjpfenninger/ipython-extensions).
2932

33+
## Credits
34+
35+
This extension contains sounds created by RSilveira_88 on fresound.org, licensed
36+
under the CC-BY 3.0 License. Modifications by morrisjim. You may find the
37+
modified version [here](http://freesound.org/people/morrisjm/sounds/268756/) and
38+
the original [here](http://freesound.org/people/RSilveira_88/sounds/216306/).
3039

3140
## License
3241

0 commit comments

Comments
 (0)