Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/notifications/commit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notifications/gitify.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notifications/issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/notifications/pull-request.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 34 additions & 1 deletion src/js/__tests__/stores/sound-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,44 @@ describe('Tests for SoundNotificationStore', function () {
}];

SoundNotificationStore.onIsNewNotification(payload);

expect(SoundNotificationStore.showNotification).toHaveBeenCalled();

});

it('Should test notifications type/icon', function () {

spyOn(SoundNotificationStore, 'newNotification');

var latestNotification = {
'title': 'Greetings', 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', 'type': 'Commit'
};
SoundNotificationStore.showNotification(1, latestNotification);
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();

var latestNotification = {
'title': 'Greetings', 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', 'type': 'Issue'
};
SoundNotificationStore.showNotification(1, latestNotification);
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();

var latestNotification = {
'title': 'Greetings', 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', 'type': 'PullRequest'
};
SoundNotificationStore.showNotification(1, latestNotification);
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();

var latestNotification = {
'title': 'Greetings', 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123', 'type': 'AnotherType'
};
SoundNotificationStore.showNotification(1, latestNotification);
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();

var latestNotification = {};
SoundNotificationStore.showNotification(2, latestNotification);
expect(SoundNotificationStore.newNotification).toHaveBeenCalled();

});

it('Should reopen gitify when a notification is clicked', function () {
var nativeNotification = SoundNotificationStore.newNotification('Test', 'Hello, world!');

Expand Down
31 changes: 25 additions & 6 deletions src/js/stores/sound-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,42 @@ var SoundNotificationStore = Reflux.createStore({
audio.play();
},

newNotification: function (title, body) {
newNotification: function (title, body, icon) {
var nativeNotification = new Notification(title, {
body: body
body: body,
icon: icon || false
});
nativeNotification.onclick = function () {
ipcRenderer.send('reopen-window');
};
return nativeNotification;
},

showNotification: function (countNew, response, latestNotification) {
showNotification: function (countNew, latestNotification) {
var title = (countNew == 1 ?
'Gitify - ' + latestNotification.full_name :
'Gitify');
var body = (countNew == 1 ?
latestNotification.subject :
'You\'ve got ' + countNew + ' notifications.');
this.newNotification(title, body);

var icon;
if (countNew == 1) {
switch (latestNotification.type) {
case 'Issue':
icon = 'images/notifications/issue.png';
break;
case 'Commit':
icon = 'images/notifications/commit.png';
break;
case 'PullRequest':
icon = 'images/notifications/pull-request.png';
break;
default:
icon = 'images/notifications/gitify.png';
}
}
this.newNotification(title, body, icon);
},

onIsNewNotification: function (response) {
Expand All @@ -56,9 +74,10 @@ var SoundNotificationStore = Reflux.createStore({
self.playSound();
}
if (showNotifications) {
this.showNotification(newNotifications.length, response, {
this.showNotification(newNotifications.length, {
full_name: newNotifications[0].repository.full_name,
subject: newNotifications[0].subject.title
subject: newNotifications[0].subject.title,
type: newNotifications[0].subject.type
});
}
}
Expand Down