Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e78c37

Browse files
Merge pull request #56 from ekonstantinidis/play-sound
Notifications / Sounds
2 parents 769be56 + 24c973e commit 5e78c37

File tree

8 files changed

+58
-8
lines changed

8 files changed

+58
-8
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"grunt-contrib-copy": "=0.8.0",
145145
"grunt-contrib-less": "=1.0.1",
146146
"grunt-contrib-watch": "=0.6.1",
147-
"jest-cli": "=0.4.5",
147+
"jest-cli": "=0.4.12",
148148
"jscs": "^1.13.1",
149149
"jshint-stylish": "=1.0.2",
150150
"jsxhint": "=0.15.0",

‎sounds/click.wav‎

20.5 KB
Binary file not shown.

‎sounds/digi.wav‎

32.1 KB
Binary file not shown.

‎src/js/__tests__/components/settings.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ describe('Test for Settings Component', function () {
4343
var instance = TestUtils.renderIntoDocument(<Settings />);
4444

4545
expect(instance.state.participating).toBeFalsy();
46-
expect(instance.toggleParticipating).toBeDefined();
46+
expect(instance.toggleSetting).toBeDefined();
4747
expect(instance.appQuit).toBeDefined();
4848

49-
instance.toggleParticipating({
49+
instance.toggleSetting('participating',{
5050
target: {
5151
checked: true
5252
}

‎src/js/__tests__/stores/notifications.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ describe('Tests for NotificationsStore', function () {
3030
}
3131
};
3232

33+
// Mock Audio
34+
window.Audio = function (src) {
35+
console.log('Loading Audio: ' + src);
36+
return {
37+
play: function () {}
38+
};
39+
};
40+
3341
Actions = require('../../actions/actions.js');
3442
apiRequests = require('../../utils/api-requests.js');
3543
NotificationsStore = require('../../stores/notifications.js');

‎src/js/components/settings.js‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ var SettingsStore = require('../stores/settings');
88

99
var SettingsPage = React.createClass({
1010
getInitialState: function () {
11+
var settings = SettingsStore.getSettings();
1112
return {
12-
participating: SettingsStore.getSettings().participating
13+
participating: settings.participating,
14+
playSound: settings.playSound
1315
};
1416
},
1517

16-
toggleParticipating: function (event) {
17-
Actions.setSetting('participating', event.target.checked);
18+
toggleSetting: function (key,event) {
19+
Actions.setSetting(key, event.target.checked);
1820
},
1921

2022
appQuit: function () {
@@ -29,7 +31,15 @@ var SettingsPage = React.createClass({
2931
<div className='col-xs-4'>
3032
<Toggle
3133
defaultChecked={this.state.participating}
32-
onChange={this.toggleParticipating} />
34+
onChange={this.toggleSetting.bind(this, 'participating')} />
35+
</div>
36+
</div>
37+
<div className='row'>
38+
<div className='col-xs-8'>Play sound</div>
39+
<div className='col-xs-4'>
40+
<Toggle
41+
defaultChecked={this.state.playSound}
42+
onChange={this.toggleSetting.bind(this, 'playSound')} />
3343
</div>
3444
</div>
3545
<div className='row'>

‎src/js/stores/notifications.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var NotificationsStore = Reflux.createStore({
1111

1212
init: function () {
1313
this._notifications = [];
14+
this._previousNotifications = [];
1415
},
1516

1617
updateTrayIcon: function (notifications) {
@@ -21,6 +22,35 @@ var NotificationsStore = Reflux.createStore({
2122
}
2223
},
2324

25+
isNewNotification: function (response) {
26+
var self = this;
27+
var playSound = SettingsStore.getSettings().playSound;
28+
29+
if (!playSound) { return; }
30+
31+
// Check if notification is already in the store.
32+
var isNew = false;
33+
_.map(response, function (obj) {
34+
if (!_.contains(self._previousNotifications, obj.id)) {
35+
isNew = true;
36+
}
37+
});
38+
39+
// Play Sound.
40+
if (isNew) {
41+
if (playSound) {
42+
var audio = new Audio('sounds/digi.wav');
43+
audio.play();
44+
}
45+
}
46+
47+
// Now Reset the previousNotifications array.
48+
self._previousNotifications = [];
49+
_.map(response, function (obj) {
50+
self._previousNotifications.push(obj.id);
51+
});
52+
},
53+
2454
onGetNotifications: function () {
2555
var self = this;
2656
var participating = SettingsStore.getSettings().participating;
@@ -33,6 +63,7 @@ var NotificationsStore = Reflux.createStore({
3363
// Success - Do Something.
3464
Actions.getNotifications.completed(response.body);
3565
self.updateTrayIcon(response.body);
66+
self.isNewNotification(response.body);
3667
} else {
3768
// Error - Show messages.
3869
Actions.getNotifications.failed(err);

‎src/js/stores/settings.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var SettingsStore = Reflux.createStore({
99

1010
if (!settings) {
1111
settings = {
12-
'participating': false
12+
'participating': false,
13+
'playSound': true
1314
};
1415
}
1516

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /