
- It makes it easier to use localStorage and sessionStorage "the angular way". It also does all the error handling so we don't need to. - Adds back the automatic saving of the current track's position and playing queue in localStorage. It's fully unit tested. - Adds back the notifications. Every time we change songs (if the setting is true), it displays a notification. Clicking on it goes to the next song, just like before. - Bumps up the versions to the actual value on the various json files.
69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
/**
|
|
* jamstash.notifications Module
|
|
*
|
|
* Provides access to the notification UI.
|
|
*/
|
|
angular.module('jamstash.notifications', ['jamstash.player.service'])
|
|
|
|
.service('notifications', ['$rootScope', 'globals', 'player', function($rootScope, globals, player) {
|
|
'use strict';
|
|
|
|
var msgIndex = 1;
|
|
this.updateMessage = function (msg, autohide) {
|
|
if (msg !== '') {
|
|
var id = $rootScope.Messages.push(msg) - 1;
|
|
$('#messages').fadeIn();
|
|
if (autohide) {
|
|
setTimeout(function () {
|
|
$('#msg_' + id).fadeOut(function () { $(this).remove(); });
|
|
}, globals.settings.Timeout);
|
|
}
|
|
}
|
|
};
|
|
this.requestPermissionIfRequired = function () {
|
|
if (window.Notify.isSupported() && window.Notify.needsPermission()) {
|
|
window.Notify.requestPermission();
|
|
}
|
|
};
|
|
this.hasNotificationPermission = function () {
|
|
return (window.Notify.needsPermission() === false);
|
|
};
|
|
this.hasNotificationSupport = function () {
|
|
return window.Notify.isSupported();
|
|
};
|
|
var notifications = [];
|
|
|
|
this.showNotification = function (pic, title, text, type, bind) {
|
|
if (this.hasNotificationPermission()) {
|
|
//closeAllNotifications()
|
|
var settings = {};
|
|
if (bind === '#NextTrack') {
|
|
settings.notifyClick = function () {
|
|
player.nextTrack();
|
|
this.close();
|
|
//TODO: Hyz: This should be in a directive, so we wouldn't have to use this.
|
|
$rootScope.$apply();
|
|
};
|
|
}
|
|
if (type === 'text') {
|
|
settings.body = text;
|
|
settings.icon = pic;
|
|
} else if (type === 'html') {
|
|
settings.body = text;
|
|
}
|
|
var notification = new Notify(title, settings);
|
|
notifications.push(notification);
|
|
setTimeout(function (notWin) {
|
|
notWin.close();
|
|
}, globals.settings.Timeout, notification);
|
|
notification.show();
|
|
} else {
|
|
console.log("showNotification: No Permission");
|
|
}
|
|
};
|
|
this.closeAllNotifications = function () {
|
|
for (var notification in notifications) {
|
|
notifications[notification].close();
|
|
}
|
|
};
|
|
}]);
|