1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-11-26 06:47:17 +00:00

Merged nicos notifications, add cookie support

This commit is contained in:
Andrew Karpow 2014-01-17 18:34:22 +01:00
parent da52814926
commit 4a4e8e2480
3 changed files with 58 additions and 6 deletions

View File

@ -138,6 +138,12 @@
</button> </button>
</div> </div>
<div class="btn-group-vertical btn-block btn-group-lg" data-toggle="buttons">
<button type="button" class="btn btn-default" id="btnnotify">
<span class="glyphicon glyphicon-comment"></span> Notifications
</button>
</div>
</div> </div>
</div><!-- /.col-md-2 --> </div><!-- /.col-md-2 -->
</div><!-- /.row --> </div><!-- /.row -->
@ -185,6 +191,7 @@
================================================== --> ================================================== -->
<!-- Placed at the end of the document so the pages load faster --> <!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script> <script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.cookie.js"></script>
<script src="js/bootstrap.min.js"></script> <script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-notify.js"></script> <script src="js/bootstrap-notify.js"></script>
<script src="js/bootstrap-slider.js"></script> <script src="js/bootstrap-slider.js"></script>

View File

@ -1,7 +1,9 @@
var socket; var socket;
var last_state; var last_state;
var current_app; var current_app;
var lastSongTitle = "";
var current_song = new Object(); var current_song = new Object();
var desktopNotification;
var app = $.sammy(function() { var app = $.sammy(function() {
this.before('/', function(e, data) { this.before('/', function(e, data) {
@ -60,6 +62,12 @@ $(document).ready(function(){
socket.send("MPD_API_SET_SEEK,"+current_song.currentSongId+","+seekVal); socket.send("MPD_API_SET_SEEK,"+current_song.currentSongId+","+seekVal);
} }
}); });
if(!notificationsSupported())
$('#btnnotify').addClass("disabled");
else
if ($.cookie("notification") === "true")
$('#btnnotify').addClass("active")
}); });
@ -125,7 +133,6 @@ function webSocketConnect() {
$(this).children().last().find("a").stop().remove(); $(this).children().last().find("a").stop().remove();
} }
}); });
break; break;
case "browse": case "browse":
if(current_app !== 'browse') if(current_app !== 'browse')
@ -269,10 +276,14 @@ function webSocketConnect() {
notification += obj.data.artist + "<br />"; notification += obj.data.artist + "<br />";
} }
$('.top-right').notify({ if ($.cookie("notification") === "true")
message:{html: notification}, songNotify(obj.data.title, obj.data.artist + " " + obj.data.album );
type: "info", else
}).show(); $('.top-right').notify({
message:{html: notification},
type: "info",
}).show();
break; break;
case "error": case "error":
$('.top-right').notify({ $('.top-right').notify({
@ -394,6 +405,20 @@ $('#btnrepeat').on('click', function (e) {
socket.send("MPD_API_TOGGLE_REPEAT," + ($(this).hasClass('active') ? 0 : 1)); socket.send("MPD_API_TOGGLE_REPEAT," + ($(this).hasClass('active') ? 0 : 1));
}); });
$('#btnnotify').on('click', function (e) {
console.log("setting this");
if($.cookie("notification") === "true")
$.cookie("notification", false);
else {
window.webkitNotifications.requestPermission();
if (window.webkitNotifications.checkPermission() == 0)
{
$.cookie("notification", true);
$('btnnotify').addClass("active");
}
}
});
function getVersion() function getVersion()
{ {
$.get( "/api/get_version", function(response) { $.get( "/api/get_version", function(response) {
@ -401,3 +426,22 @@ function getVersion()
$('#mpd_version').text(response.data.mpd_version); $('#mpd_version').text(response.data.mpd_version);
}); });
} }
function notificationsSupported() {
return "webkitNotifications" in window;
}
function songNotify(artist, title) {
if (!notificationsSupported())
return;
if (window.webkitNotifications.checkPermission() == 0) {
var notification = window.webkitNotifications.createNotification("assets/favicon.ico", artist, title);
notification.show();
setTimeout(function(notification) {
notification.cancel();
}, 2000, notification);
} else {
window.webkitNotifications.requestPermission();
}
}

View File

@ -25,6 +25,7 @@ static const struct serveable whitelist[] = {
{ "/js/bootstrap.min.js", "text/javascript" }, { "/js/bootstrap.min.js", "text/javascript" },
{ "/js/mpd.js", "text/javascript" }, { "/js/mpd.js", "text/javascript" },
{ "/js/jquery-1.10.2.min.js", "text/javascript" }, { "/js/jquery-1.10.2.min.js", "text/javascript" },
{ "/js/jquery.cookie.js", "text/javascript" },
{ "/js/bootstrap-slider.js", "text/javascript" }, { "/js/bootstrap-slider.js", "text/javascript" },
{ "/js/bootstrap-notify.js", "text/javascript" }, { "/js/bootstrap-notify.js", "text/javascript" },
{ "/js/sammy.js", "text/javascript" }, { "/js/sammy.js", "text/javascript" },