-
Notifications
You must be signed in to change notification settings - Fork 274
Native Notifications #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
34c3b62
Notifications functionality
e6c5811
Fix tests
17775b2
Show Notifications settings
9056d38
Fix tests
b1389a7
Merge remote-tracking branch 'origin/master' into native-notifications
c15c662
Show more info if one 1 new notification
c7629cc
Merge branch 'master' into native-notifications
06093ae
Split to 'sound-notification' store & get the correct full_name & sub…
62532c9
Tests for 'sound-notification' store
b84c909
Require 'sound-notification' store to be included in the build
eef99c8
Mocks for Audio & notifcations
c2b47ce
Remove coveralls!
adabd09
Jake's comments
eca42dd
Revert setting audio in store's init
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*global jest, describe, it, expect, spyOn, beforeEach */ | ||
|
||
'use strict'; | ||
|
||
jest.dontMock('reflux'); | ||
jest.dontMock('../../stores/sound-notification.js'); | ||
jest.dontMock('../../utils/api-requests.js'); | ||
jest.dontMock('../../actions/actions.js'); | ||
|
||
describe('Tests for SoundNotificationStore', function () { | ||
|
||
var SoundNotificationStore, Actions; | ||
|
||
beforeEach(function () { | ||
|
||
// Mock Electron's window.require | ||
window.require = function () { | ||
return { | ||
sendChannel: function () { | ||
return; | ||
} | ||
}; | ||
}; | ||
|
||
// Mock localStorage | ||
window.localStorage = { | ||
item: false, | ||
getItem: function () { | ||
return this.item; | ||
}, | ||
setItem: function (item) { | ||
this.item = item; | ||
} | ||
}; | ||
|
||
// Mock Audio | ||
window.Audio = function () { | ||
return { | ||
play: function () {} | ||
}; | ||
}; | ||
|
||
// Mock Notifications | ||
window.Notification = function () { | ||
return { | ||
onClick: function () {} | ||
}; | ||
}; | ||
|
||
Actions = require('../../actions/actions.js'); | ||
SoundNotificationStore = require('../../stores/sound-notification.js'); | ||
}); | ||
|
||
it('should get a payload and check if it should play sound & show notification.', function () { | ||
|
||
spyOn(SoundNotificationStore, 'showNotification'); | ||
|
||
var payload = [{ | ||
'id': '1', | ||
'repository': { | ||
'id': 1296269, | ||
'full_name': 'octocat/Hello-World', | ||
'description': 'This your first repo!' | ||
}, | ||
'subject': { | ||
'title': 'Greetings', | ||
'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123' | ||
} | ||
}]; | ||
|
||
SoundNotificationStore.onIsNewNotification(payload); | ||
|
||
expect(SoundNotificationStore.showNotification).toHaveBeenCalled(); | ||
|
||
}); | ||
|
||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var ipc = window.require('ipc'); | ||
var Reflux = require('reflux'); | ||
var _ = require('underscore'); | ||
|
||
var Actions = require('../actions/actions'); | ||
var SettingsStore = require('../stores/settings'); | ||
|
||
var SoundNotificationStore = Reflux.createStore({ | ||
listenables: Actions, | ||
|
||
init: function () { | ||
this._previousNotifications = []; | ||
}, | ||
|
||
playSound: function () { | ||
var audio = new Audio('sounds/digi.wav'); | ||
audio.play(); | ||
}, | ||
|
||
showNotification: function (countNew, response, latestNotification) { | ||
var title = (countNew == 1 ? | ||
'Gitify - ' + latestNotification.full_name : | ||
'Gitify'); | ||
var body = (countNew == 1 ? | ||
latestNotification.subject : | ||
'You\'ve got ' + countNew + ' notifications.'); | ||
var nativeNotification = new Notification(title, { | ||
body: body | ||
}); | ||
nativeNotification.onclick = function () { | ||
ipc.sendChannel('reopen-window'); | ||
}; | ||
}, | ||
|
||
onIsNewNotification: function (response) { | ||
var self = this; | ||
var playSound = SettingsStore.getSettings().playSound; | ||
var showNotifications = SettingsStore.getSettings().showNotifications; | ||
|
||
if (!playSound && !showNotifications) { return; } | ||
|
||
// Check if notification is already in the store. | ||
var newNotifications = _.filter(response, function (obj) { | ||
return !_.contains(self._previousNotifications, obj.id); | ||
}); | ||
|
||
// Play Sound / Show Notification. | ||
if (newNotifications && newNotifications.length) { | ||
if (playSound) { | ||
self.playSound(); | ||
} | ||
if (showNotifications) { | ||
this.showNotification(newNotifications.length, response, { | ||
full_name: newNotifications[0].repository.full_name, | ||
subject: newNotifications[0].subject.title | ||
}); | ||
} | ||
} | ||
|
||
// Now Reset the previousNotifications array. | ||
self._previousNotifications = _.map(response, function (obj) { | ||
return obj.id; | ||
}); | ||
} | ||
|
||
}); | ||
|
||
module.exports = SoundNotificationStore; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd load this into the store on init
this._audio
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also store a variable to tell whether the audio has been loaded.