mirror of
https://github.com/SuperBFG7/ympd
synced 2025-04-10 04:36:46 +00:00
Fix: refresh queue length after queue edit
This commit is contained in:
parent
7e300d5be9
commit
2686587b04
@ -266,7 +266,7 @@ function appRoute() {
|
||||
}
|
||||
|
||||
if (app.current.search.length >= 2) {
|
||||
sendAPI({"cmd": "MPD_API_SEARCH", "data": { "mpdtag": app.current.filter, "offset": app.current.page, "searchstr": app.current.search}}, parseSearch);
|
||||
sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": { "mpdtag": app.current.filter, "offset": app.current.page, "searchstr": app.current.search}}, parseSearch);
|
||||
} else {
|
||||
document.getElementById('SearchList').getElementsByTagName('tbody')[0].innerHTML = '';
|
||||
document.getElementById('searchAddAllSongs').setAttribute('disabled', 'disabled');
|
||||
@ -302,6 +302,9 @@ function appInit() {
|
||||
webSocketConnect();
|
||||
|
||||
domCache.volumeBar.value = 0;
|
||||
domCache.volumeBar.addEventListener('click', function(event) {
|
||||
event.stopPropagation();
|
||||
}, false);
|
||||
domCache.volumeBar.addEventListener('change', function(event) {
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_VOLUME", "data": {"volume": domCache.volumeBar.value}});
|
||||
}, false);
|
||||
@ -390,7 +393,7 @@ function appInit() {
|
||||
document.getElementById('outputs').addEventListener('click', function(event) {
|
||||
if (event.target.nodeName == 'BUTTON')
|
||||
event.stopPropagation();
|
||||
sendAPI({"cmd": "MPD_API_TOGGLE_OUTPUT", "data": {"output": event.target.getAttribute('data-output-id'), "state": (event.target.classList.contains('active') ? 0 : 1)}});
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_TOGGLE_OUTPUT", "data": {"output": event.target.getAttribute('data-output-id'), "state": (event.target.classList.contains('active') ? 0 : 1)}});
|
||||
toggleBtn(event.target.id);
|
||||
}, false);
|
||||
|
||||
@ -650,7 +653,7 @@ function dragAndDropTable(table) {
|
||||
|
||||
function playlistMoveTrack(from, to) {
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_MOVE_TRACK","data": { "plist": app.current.search, "from": from, "to": to}});
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT","data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT_LIST","data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
|
||||
}
|
||||
|
||||
function webSocketConnect() {
|
||||
@ -853,7 +856,7 @@ function parseOutputs(obj) {
|
||||
var btns = '';
|
||||
var outputsLen = obj.data.outputs.length;
|
||||
for (var i = 0; i < outputsLen; i++) {
|
||||
btns += '<button data-output-id="' + obj.data.outputs[i].id + '" class="btn btn-secondary btn-block';
|
||||
btns += '<button id="btnOutput' + obj.data.outputs[i].id +'" data-output-id="' + obj.data.outputs[i].id + '" class="btn btn-secondary btn-block';
|
||||
if (obj.data.outputs[i].state == 1)
|
||||
btns += ' active';
|
||||
btns += '"><span class="material-icons float-left">volume_up</span> ' + obj.data.outputs[i].name + '</button>';
|
||||
@ -1463,14 +1466,14 @@ function removeFromPlaylist(uri, pos) {
|
||||
pos--;
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_RM_TRACK", "data": {"uri": uri, "track": pos}});
|
||||
document.getElementById('BrowsePlaylistsDetailList').classList.add('opacity05');
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT", "data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT_LIST", "data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
|
||||
}
|
||||
|
||||
function playlistClear() {
|
||||
var uri = document.getElementById('BrowsePlaylistsDetailList').getAttribute('data-uri');
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_CLEAR", "data": {"uri": uri}});
|
||||
document.getElementById('BrowsePlaylistsDetailList').classList.add('opacity05');
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT", "data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
|
||||
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT_LIST", "data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
|
||||
}
|
||||
|
||||
function getAllPlaylists(obj) {
|
||||
@ -1538,6 +1541,7 @@ function toggleAddToPlaylistFrm() {
|
||||
function showAddToPlaylist(uri) {
|
||||
document.getElementById('addToPlaylistUri').value = uri;
|
||||
document.getElementById('addToPlaylistPlaylist').innerHTML = '';
|
||||
document.getElementById('addToPlaylistNewPlaylist').value = '';
|
||||
document.getElementById('addToPlaylistNewPlaylistDiv').classList.add('hide');
|
||||
document.getElementById('addToPlaylistFrm').classList.remove('was-validated');
|
||||
document.getElementById('addToPlaylistNewPlaylist').classList.remove('is-invalid');
|
||||
@ -1706,14 +1710,16 @@ function showMenu(el) {
|
||||
document.getElementsByClassName('popover-content')[0].addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
var cmd = JSON.parse(event.target.getAttribute('data-href').replace(/\'/g, '"'));
|
||||
if (typeof window[cmd.cmd] === 'function') {
|
||||
switch(cmd.cmd) {
|
||||
case 'sendAPI':
|
||||
sendAPI(... cmd.options);
|
||||
break;
|
||||
default:
|
||||
window[cmd.cmd](... cmd.options);
|
||||
if (event.target.nodeName == 'A') {
|
||||
var cmd = JSON.parse(event.target.getAttribute('data-href').replace(/\'/g, '"'));
|
||||
if (typeof window[cmd.cmd] === 'function') {
|
||||
switch(cmd.cmd) {
|
||||
case 'sendAPI':
|
||||
sendAPI(... cmd.options);
|
||||
break;
|
||||
default:
|
||||
window[cmd.cmd](... cmd.options);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
@ -1884,7 +1890,7 @@ function addAllFromBrowse() {
|
||||
|
||||
function addAllFromSearch() {
|
||||
if (app.current.search.length >= 2) {
|
||||
sendAPI({"cmd": "MPD_API_SEARCH_ADD_QUEUE", "data":{"filter": app.current.filter, "searchstr": app.current.search}});
|
||||
sendAPI({"cmd": "MPD_API_DATABASE_SEARCH_ADD_QUEUE", "data":{"filter": app.current.filter, "searchstr": app.current.search}});
|
||||
showNotification('Added '+ parseInt(document.getElementById('panel-heading-search').innerText) +' songs from search', '', '', 'success');
|
||||
}
|
||||
}
|
||||
@ -1895,7 +1901,7 @@ function addAllFromSearchPlist(plist) {
|
||||
if (filter == 'Any Tag')
|
||||
filter = 'any';
|
||||
|
||||
sendAPI({"cmd": "MPD_API_SEARCH_ADD_PLAYLIST", "data":{"plist": plist, "filter": filter, "searchstr": app.current.search}});
|
||||
sendAPI({"cmd": "MPD_API_DATABASE_SEARCH_ADD_PLAYLIST", "data":{"plist": plist, "filter": filter, "searchstr": app.current.search}});
|
||||
showNotification('Added '+ parseInt(document.getElementById('panel-heading-search').innerText) +' songs from search to ' + plist, '', '', 'success');
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) {
|
||||
case MPD_API_QUEUE_LIST:
|
||||
je = json_scanf(msg.p, msg.len, "{data: {offset: %u }}", &uint_buf1);
|
||||
if (je == 1) {
|
||||
n = mympd_put_queue(mpd.buf, uint_buf1);
|
||||
n = mympd_put_queue(mpd.buf, uint_buf1, &mpd.queue_version, &mpd.queue_length);
|
||||
}
|
||||
break;
|
||||
case MPD_API_PLAYER_CURRENT_SONG:
|
||||
@ -1125,14 +1125,18 @@ int mympd_put_songdetails(char *buffer, char *uri) {
|
||||
return len;
|
||||
}
|
||||
|
||||
int mympd_put_queue(char *buffer, unsigned int offset) {
|
||||
int mympd_put_queue(char *buffer, unsigned int offset, unsigned *queue_version, unsigned *queue_length) {
|
||||
struct mpd_entity *entity;
|
||||
unsigned long totalTime = 0;
|
||||
unsigned long entity_count = 0;
|
||||
unsigned long entities_returned = 0;
|
||||
int len;
|
||||
struct json_out out = JSON_OUT_BUF(buffer, MAX_SIZE);
|
||||
|
||||
struct mpd_status *status = mpd_run_status(mpd.conn);
|
||||
|
||||
if (!status)
|
||||
RETURN_ERROR_AND_RECOVER("mpd_run_status");
|
||||
|
||||
if (!mpd_send_list_queue_range_meta(mpd.conn, offset, offset + MAX_ELEMENTS_PER_PAGE))
|
||||
RETURN_ERROR_AND_RECOVER("mpd_send_list_queue_meta");
|
||||
|
||||
@ -1163,11 +1167,15 @@ int mympd_put_queue(char *buffer, unsigned int offset) {
|
||||
|
||||
len += json_printf(&out, "], totalTime: %d, totalEntities: %d, offset: %d, returnedEntities: %d, queue_version: %d}",
|
||||
totalTime,
|
||||
mpd.queue_length,
|
||||
mpd_status_get_queue_length(status),
|
||||
offset,
|
||||
entities_returned,
|
||||
mpd.queue_version
|
||||
mpd_status_get_queue_version(status)
|
||||
);
|
||||
|
||||
*queue_version = mpd_status_get_queue_version(status);
|
||||
*queue_length = mpd_status_get_queue_length(status);
|
||||
mpd_status_free(status);
|
||||
|
||||
if (len > MAX_SIZE)
|
||||
printf("Buffer truncated\n");
|
||||
|
@ -175,7 +175,7 @@ int mympd_get_updatedb_state(char *buffer);
|
||||
int mympd_put_state(char *buffer, int *current_song_id, int *next_song_id, int *last_song_id, unsigned *queue_version, unsigned *queue_length);
|
||||
int mympd_put_outputs(char *buffer);
|
||||
int mympd_put_current_song(char *buffer);
|
||||
int mympd_put_queue(char *buffer, unsigned int offset);
|
||||
int mympd_put_queue(char *buffer, unsigned int offset, unsigned *queue_version, unsigned *queue_length);
|
||||
int mympd_put_browse(char *buffer, char *path, unsigned int offset, char *filter);
|
||||
int mympd_search(char *buffer, char *mpdtagtype, unsigned int offset, char *searchstr);
|
||||
int mympd_search_add(char *buffer, char *mpdtagtype, char *searchstr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user