From c5628a098939a9946fe9b724d20b2c3f5a2a47a8 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Mon, 5 Nov 2018 23:13:22 +0000 Subject: [PATCH] Feat: add keymap file to define keyboard shortcuts #58 --- CMakeLists.txt | 1 + dist/htdocs/index.html | 2 +- dist/htdocs/js/keymap.min.js | 2 + dist/htdocs/js/mympd.min.js | 81 +++++++++++++++++++----------------- dist/htdocs/sw.min.js | 2 +- htdocs/index.html | 3 +- htdocs/js/keymap.js | 25 +++++++++++ htdocs/js/mympd.js | 66 ++++++++--------------------- htdocs/sw.js | 1 + mkdebug.sh | 1 + mkrelease.sh | 6 ++- 11 files changed, 99 insertions(+), 91 deletions(-) create mode 100644 dist/htdocs/js/keymap.min.js create mode 100644 htdocs/js/keymap.js diff --git a/CMakeLists.txt b/CMakeLists.txt index 141544f..95f8bfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ install(FILES dist/htdocs/sw.min.js DESTINATION share/${PROJECT_NAME}/htdocs/) install(FILES dist/htdocs/js/player.min.js DESTINATION share/${PROJECT_NAME}/htdocs/js/) install(FILES dist/htdocs/js/bootstrap-native-v4.min.js DESTINATION share/${PROJECT_NAME}/htdocs/js/) install(FILES dist/htdocs/js/mympd.min.js DESTINATION share/${PROJECT_NAME}/htdocs/js/) +install(FILES dist/htdocs/js/keymap.min.js DESTINATION share/${PROJECT_NAME}/htdocs/js/) install(FILES dist/htdocs/css/bootstrap.min.css DESTINATION share/${PROJECT_NAME}/htdocs/css/) install(FILES dist/htdocs/css/mympd.min.css DESTINATION share/${PROJECT_NAME}/htdocs/css/) install(DIRECTORY htdocs/assets DESTINATION share/${PROJECT_NAME}/htdocs) diff --git a/dist/htdocs/index.html b/dist/htdocs/index.html index dff2299..02edc5d 100644 --- a/dist/htdocs/index.html +++ b/dist/htdocs/index.html @@ -1 +1 @@ -myMPD
Playback

Artist

Album

Queue
#TitleArtistAlbumDuration
PlaylistLast modified
Playlist List
#TitleArtistAlbumDuration
TitleArtistAlbumDuration
Search
TitleArtistAlbumDuration
\ No newline at end of file +myMPD
Playback

Queue
#TitleArtistAlbumDuration
PlaylistLast modified
Playlist List
#TitleArtistAlbumDuration
TitleArtistAlbumDuration
Search
TitleArtistAlbumDuration
\ No newline at end of file diff --git a/dist/htdocs/js/keymap.min.js b/dist/htdocs/js/keymap.min.js new file mode 100644 index 0000000..2d457b7 --- /dev/null +++ b/dist/htdocs/js/keymap.min.js @@ -0,0 +1,2 @@ +var keymap={shiftKey:{83:{cmd:"MPD_API_QUEUE_SHUFFLE",options:[]},67:{cmd:"MPD_API_QUEUE_CROP",options:[]}},key:{37:{cmd:"clickPrev",options:[]},39:{cmd:"clickNext",options:[]},32:{cmd:"clickPlay",options:[]},83:{cmd:"clickStop",options:[]},173:{cmd:"chVolume",options:[-5]},171:{cmd:"chVolume",options:[5]},67:{cmd:"MPD_API_QUEUE_CLEAR",options:[]},85:{cmd:"updateDB",options:[]},82:{cmd:"rescanDB",options:[]},80:{cmd:"updateSmartPlaylists",options:[]},65:{cmd:"showAddToPlaylist",options:["stream"]}, +84:{cmd:"openModal",options:["modalSettings"]},89:{cmd:"openModal",options:["modalAbout"]},49:{cmd:"appGoto",options:["Playback"]},50:{cmd:"appGoto",options:["Queue"]},51:{cmd:"appGoto",options:["Browse"]},52:{cmd:"appGoto",options:["Search"]}}}; diff --git a/dist/htdocs/js/mympd.min.js b/dist/htdocs/js/mympd.min.js index b43ee3e..1f00412 100644 --- a/dist/htdocs/js/mympd.min.js +++ b/dist/htdocs/js/mympd.min.js @@ -6,12 +6,12 @@ $jscomp.polyfill=function(a,b,c,d){if(b){c=$jscomp.global;a=a.split(".");for(d=0 $jscomp.polyfill("Array.prototype.includes",function(a){return a?a:function(a,c){var d=this;d instanceof String&&(d=String(d));var b=d.length;c=c||0;for(0>c&&(c=Math.max(c+b,0));ca||1342177279>>=1)b+=b;return d}},"es6","es3"); -var socket,lastSong="",lastState,currentSong={},playstate="",settings={},alertTimeout,progressTimer,deferredPrompt,dragEl,playlistEl,app={apps:{Playback:{state:"0/-/",scrollPos:0},Queue:{state:"0/any/",scrollPos:0},Browse:{active:"Database",tabs:{Filesystem:{state:"0/-/",scrollPos:0},Playlists:{active:"All",views:{All:{state:"0/-/",scrollPos:0},Detail:{state:"0/-/",scrollPos:0}}},Database:{active:"AlbumArtist",views:{}}}},Search:{state:"0/any/",scrollPos:0}},current:{app:"Playback",tab:void 0,view:void 0, -page:0,filter:"",search:"",scrollPos:0},last:{app:void 0,tab:void 0,view:void 0,filter:"",search:"",scrollPos:0}},domCache={};domCache.navbarBottomBtns=document.getElementById("navbar-bottom").getElementsByTagName("div");domCache.navbarBottomBtnsLen=domCache.navbarBottomBtns.length;domCache.panelHeadingBrowse=document.getElementById("panel-heading-browse").getElementsByTagName("a");domCache.panelHeadingBrowseLen=domCache.panelHeadingBrowse.length;domCache.counter=document.getElementById("counter"); +var socket,lastSong="",lastSongObj={},lastState,currentSong={},playstate="",settings={},alertTimeout,progressTimer,deferredPrompt,dragEl,playlistEl,app={apps:{Playback:{state:"0/-/",scrollPos:0},Queue:{state:"0/any/",scrollPos:0},Browse:{active:"Database",tabs:{Filesystem:{state:"0/-/",scrollPos:0},Playlists:{active:"All",views:{All:{state:"0/-/",scrollPos:0},Detail:{state:"0/-/",scrollPos:0}}},Database:{active:"AlbumArtist",views:{}}}},Search:{state:"0/any/",scrollPos:0}},current:{app:"Playback", +tab:void 0,view:void 0,page:0,filter:"",search:"",scrollPos:0},last:{app:void 0,tab:void 0,view:void 0,filter:"",search:"",scrollPos:0}},domCache={};domCache.navbarBottomBtns=document.getElementById("navbar-bottom").getElementsByTagName("div");domCache.navbarBottomBtnsLen=domCache.navbarBottomBtns.length;domCache.panelHeadingBrowse=document.getElementById("panel-heading-browse").getElementsByTagName("a");domCache.panelHeadingBrowseLen=domCache.panelHeadingBrowse.length;domCache.counter=document.getElementById("counter"); domCache.volumePrct=document.getElementById("volumePrct");domCache.volumeControl=document.getElementById("volumeControl");domCache.volumeIcon=document.getElementById("volumeIcon");domCache.btnsPlay=document.getElementsByClassName("btnPlay");domCache.btnsPlayLen=domCache.btnsPlay.length;domCache.btnPrev=document.getElementById("btnPrev");domCache.btnNext=document.getElementById("btnNext");domCache.progressBar=document.getElementById("progressBar");domCache.volumeBar=document.getElementById("volumeBar"); -domCache.outputs=document.getElementById("outputs");domCache.btnAdd=document.getElementById("nav-add2homescreen");domCache.currentTrack=document.getElementById("currentTrack");domCache.currentArtist=document.getElementById("currentArtist");domCache.currentAlbum=document.getElementById("currentAlbum");domCache.currentCover=document.getElementById("currentCover");domCache.btnVoteUp=document.getElementById("btnVoteUp");domCache.btnVoteDown=document.getElementById("btnVoteDown"); -var modalConnectionError=new Modal(document.getElementById("modalConnectionError"),{backdrop:"static",keyboard:!1}),modalSettings=new Modal(document.getElementById("modalSettings")),modalSavequeue=new Modal(document.getElementById("modalSaveQueue")),modalSongDetails=new Modal(document.getElementById("modalSongDetails")),modalAddToPlaylist=new Modal(document.getElementById("modalAddToPlaylist")),modalRenamePlaylist=new Modal(document.getElementById("modalRenamePlaylist")),modalUpdateDB=new Modal(document.getElementById("modalUpdateDB")), -modalSaveSmartPlaylist=new Modal(document.getElementById("modalSaveSmartPlaylist")),modalDeletePlaylist=new Modal(document.getElementById("modalDeletePlaylist")); +domCache.outputs=document.getElementById("outputs");domCache.btnAdd=document.getElementById("nav-add2homescreen");domCache.currentCover=document.getElementById("currentCover");domCache.currentTitle=document.getElementById("currentTitle");domCache.btnVoteUp=document.getElementById("btnVoteUp");domCache.btnVoteDown=document.getElementById("btnVoteDown"); +var modalConnectionError=new Modal(document.getElementById("modalConnectionError"),{backdrop:"static",keyboard:!1}),modalSettings=new Modal(document.getElementById("modalSettings")),modalAbout=new Modal(document.getElementById("modalAbout")),modalSavequeue=new Modal(document.getElementById("modalSaveQueue")),modalSongDetails=new Modal(document.getElementById("modalSongDetails")),modalAddToPlaylist=new Modal(document.getElementById("modalAddToPlaylist")),modalRenamePlaylist=new Modal(document.getElementById("modalRenamePlaylist")), +modalUpdateDB=new Modal(document.getElementById("modalUpdateDB")),modalSaveSmartPlaylist=new Modal(document.getElementById("modalSaveSmartPlaylist")),modalDeletePlaylist=new Modal(document.getElementById("modalDeletePlaylist")); function appPrepare(a){if(app.current.app!=app.last.app||app.current.tab!=app.last.tab||app.current.view!=app.last.view){for(var b=0;bDatabase"; -settings.tags.sort();settings.searchtags.sort();settings.browsetags.sort();filterCols("colsSearch");filterCols("colsQueue");filterCols("colsBrowsePlaylistsDetail");filterCols("colsBrowseFilesystem");filterCols("colsBrowseDatabase");settings.featLocalplayer&&(""==settings.streamurl?(settings.mpdstream="http://",settings.mpdstream="127.0.0.1"==settings.mpdhost||"localhost"==settings.mpdhost?settings.mpdstream+window.location.hostname:settings.mpdstream+settings.mpdhost,settings.mpdstream+=":"+settings.streamport+ -"/"):settings.mpdstream=settings.streamurl);addTagList("BrowseDatabaseByTagDropdown","browsetags");addTagList("searchqueuetags","searchtags");addTagList("searchtags","searchtags");for(a=0;a',a=0;a"+settings.syscmds[a]+"";document.getElementById("syscmds").innerHTML=b}else document.getElementById("syscmds").innerHTML="";setCols("Queue");setCols("Search");setCols("BrowseFilesystem");setCols("BrowsePlaylistsDetail");setCols("BrowseDatabase",".tblAlbumTitles");"Queue"==app.current.app?getQueue():"Search"==app.current.app?appRoute():"Browse"==app.current.app&&"Filesystem"==app.current.tab?appRoute():"Browse"==app.current.app&&"Playlists"==app.current.tab&&"Detail"== -app.current.view?appRoute():"Browse"==app.current.app&&"Database"==app.current.tab&&""!=app.current.search&&appRoute()} -function setCols(a,b){var c="",d=settings.tags.slice();0==settings.featTags&&d.push("Title");d.push("Duration");"Queue"!=a&&"BrowsePlaylistsDetail"!=a||d.push("Pos");"BrowseFilesystem"==a&&d.push("Type");d.sort();for(var e=0;e  '+d[e]+"";document.getElementById(a+ -"ColsDropdown").firstChild.innerHTML=c;c="";for(e=0;e';if("Track"==d||"Pos"==d)d="#";c+=d+""}c+="";if(void 0==b)document.getElementById(a+"List").getElementsByTagName("tr")[0].innerHTML=c;else for(a=document.querySelectorAll(b),e=0;e'+settings.colsPlayback[a]+"";document.getElementById("cardPlaybackTags").innerHTML=b}1== +settings.mixramp?document.getElementsByClassName("mixramp")[0].style.display="":document.getElementsByClassName("mixramp")[0].style.display="none";!settings.tags.includes("AlbumArtist")&&settings.featTags&&(settings.tags.includes("Artist")?app.apps.Browse.tabs.Database.active="Artist":app.apps.Browse.tabs.Database.active=settings.tags[0]);document.getElementById("selectJukeboxMode").value=settings.jukeboxMode;document.getElementById("inputJukeboxQueueLength").value=settings.jukeboxQueueLength;0== +settings.jukeboxMode||2==settings.jukeboxMode?(document.getElementById("inputJukeboxQueueLength").setAttribute("disabled","disabled"),document.getElementById("selectJukeboxPlaylist").setAttribute("disabled","disabled")):1==settings.jukeboxMode&&(document.getElementById("inputJukeboxQueueLength").removeAttribute("disabled"),document.getElementById("selectJukeboxPlaylist").removeAttribute("disabled"));settings.featPlaylists?(playlistEl="selectJukeboxPlaylist",sendAPI({cmd:"MPD_API_PLAYLIST_LIST",data:{offset:0, +filter:"-"}},getAllPlaylists)):document.getElementById("selectJukeboxPlaylist").innerHTML="";settings.tags.sort();settings.searchtags.sort();settings.browsetags.sort();filterCols("colsSearch");filterCols("colsQueue");filterCols("colsBrowsePlaylistsDetail");filterCols("colsBrowseFilesystem");filterCols("colsBrowseDatabase");filterCols("colsPlayback");settings.featLocalplayer&&(""==settings.streamurl?(settings.mpdstream="http://",settings.mpdstream="127.0.0.1"==settings.mpdhost|| +"localhost"==settings.mpdhost?settings.mpdstream+window.location.hostname:settings.mpdstream+settings.mpdhost,settings.mpdstream+=":"+settings.streamport+"/"):settings.mpdstream=settings.streamurl);addTagList("BrowseDatabaseByTagDropdown","browsetags");addTagList("searchqueuetags","searchtags");addTagList("searchtags","searchtags");for(a=0;a"+settings.syscmds[a]+"";document.getElementById("syscmds").innerHTML=b}else document.getElementById("syscmds").innerHTML="";setCols("Queue");setCols("Search");setCols("BrowseFilesystem");setCols("BrowsePlaylistsDetail");setCols("BrowseDatabase",".tblAlbumTitles");setCols("Playback");"Queue"==app.current.app? +getQueue():"Search"==app.current.app?appRoute():"Browse"==app.current.app&&"Filesystem"==app.current.tab?appRoute():"Browse"==app.current.app&&"Playlists"==app.current.tab&&"Detail"==app.current.view?appRoute():"Browse"==app.current.app&&"Database"==app.current.tab&&""!=app.current.search&&appRoute()} +function setCols(a,b){var c="",d=settings.tags.slice();0==settings.featTags&&d.push("Title");d.push("Duration");"Queue"!=a&&"BrowsePlaylistsDetail"!=a||d.push("Pos");"BrowseFilesystem"==a&&d.push("Type");d.sort();for(var e=0;e  '+ +d[e]+"";document.getElementById(a+"ColsDropdown").firstChild.innerHTML=c;if("Playback"!=a){c="";for(e=0;e';if("Track"==d||"Pos"==d)d="#";c+=d+""}c+="";if(void 0==b)document.getElementById(a+"List").getElementsByTagName("tr")[0].innerHTML=c;else for(a=document.querySelectorAll(b),e=0;e"+b[d].name+"

",e.setAttribute("id","current"+b[d].name),e.setAttribute("data-tag",b[d].name),c.appendChild(e))}a={cmd:"MPD_API_COLS_SAVE",data:{table:"cols"+a, +cols:[]}};c=c.getElementsByTagName("div");for(d=0;d";domCache.outputs.innerHTML=b} function setCounter(a,b,c){currentSong.totalTime=b;currentSong.elapsedTime=c;currentSong.currentSongId=a;var d=Math.floor(b/60),e=b-60*d,f=Math.floor(c/60),g=c-60*f;domCache.progressBar.value=Math.floor(100*c/b);b=f+":"+(10>g?"0":"")+g+" / "+d+":"+(10>e?"0":"")+e;domCache.counter.innerText=b;if(lastState&&lastState.data.currentSongId!=a&&(c=document.getElementById("queueTrackId"+lastState.data.currentSongId))){if(d=c.querySelector("[data-col=Duration]"))d.innerText=c.getAttribute("data-duration"); if(d=c.querySelector("[data-col=Pos]"))d.classList.remove("material-icons"),d.innerText=c.getAttribute("data-songpos");c.classList.remove("font-weight-bold")}if(c=document.getElementById("queueTrackId"+a)){if(d=c.querySelector("[data-col=Duration]"))d.innerText=b;(d=c.querySelector("[data-col=Pos]"))&&!d.classList.contains("material-icons")&&(d.classList.add("material-icons"),d.innerText="play_arrow");c.classList.add("font-weight-bold")}progressTimer&&clearTimeout(progressTimer);"play"==playstate&& (progressTimer=setTimeout(function(){currentSong.elapsedTime++;setCounter(currentSong.currentSongId,currentSong.totalTime,currentSong.elapsedTime)},1E3))} function parseState(a){if(JSON.stringify(a)!==JSON.stringify(lastState)){if(1==a.data.state){for(var b=0;b=a.data.songPos?domCache.btnPrev.setAttribute("disabled","disabled"):domCache.btnPrev.removeAttribute("disabled");if(0==a.data.queueLength)for(b=0;ba.data.volume?"volume_down":"volume_up");domCache.volumeBar.value=a.data.volume} function getQueue(){2<=app.current.search.length?sendAPI({cmd:"MPD_API_QUEUE_SEARCH",data:{filter:app.current.filter,offset:app.current.page,searchstr:app.current.search}},parseQueue):sendAPI({cmd:"MPD_API_QUEUE_LIST",data:{offset:app.current.page}},parseQueue)} function parseQueue(a){if("Queue"===app.current.app){0";document.getElementById(c+d[e]+"Pages").innerHTML=f}else document.getElementById(c+d[e]+"Page").setAttribute("disabled","disabled");a>app.current.page+settings.maxElementsPerPage?(document.getElementById(c+d[e]+"Next").removeAttribute("disabled"),document.getElementById(c+d[e]).classList.remove("hide"),document.getElementById(c+"ButtonsBottom").classList.remove("hide")):(document.getElementById(c+d[e]+"Next").setAttribute("disabled","disabled"),document.getElementById(c+d[e]).classList.add("hide"), document.getElementById(c+"ButtonsBottom").classList.add("hide"));0"+settings.tags[d]+""+a.data[settings.tags[d]]+"";var e=a.data.Duration;d=Math.floor(e/60);e-=60*d;c+="Duration"+(d+":"+(10>e?"0":"")+e)+"";c=settings.featLibrary?c+('Filename'+a.data.uri+""):c+("Filename"+a.data.uri+"");1==settings.featStickers&&(d="not voted",0==a.data.like?d='thumb_down_alt':2==a.data.like&&(d='thumb_up_alt'),c+='StatisticsPlay count'+a.data.playCount+"Skip count"+a.data.skipCount+"Last played"+(0==a.data.lastPlayed?"never": (new Date(1E3*a.data.lastPlayed)).toUTCString())+"Like"+d+"");b.getElementsByTagName("tbody")[0].innerHTML=c}function execSyscmd(a){sendAPI({cmd:"MPD_API_SYSCMD",data:{cmd:a}})}function playlistDetails(a){document.getElementById("BrowsePlaylistsAllList").classList.add("opacity05");appGoto("Browse","Playlists","Detail","0/-/"+a)} @@ -176,12 +179,12 @@ function saveQueue(){var a=document.getElementById("saveQueueName").value,b=a.re function showNotification(a,b,c,d){1==settings.notificationWeb&&(b=new Notification(a,{icon:"assets/favicon.ico",body:b}),setTimeout(function(a){a.close()},3E3,b));1==settings.notificationPage&&(document.getElementById("alertBox")?b=document.getElementById("alertBox"):(b=document.createElement("div"),b.setAttribute("id","alertBox"),b.addEventListener("click",function(){hideNotification()},!1)),b.classList.remove("alert-success","alert-danger"),b.classList.add("alert","alert-"+d),b.innerHTML="
"+ a+"
"+c+"
",document.getElementsByTagName("main")[0].append(b),document.getElementById("alertBox").classList.add("alertBoxActive"),alertTimeout&&clearTimeout(alertTimeout),alertTimeout=setTimeout(function(){hideNotification()},3E3))}function hideNotification(){document.getElementById("alertBox")&&(document.getElementById("alertBox").classList.remove("alertBoxActive"),setTimeout(function(){var a=document.getElementById("alertBox");a&&a.remove()},600))} function notificationsSupported(){return"Notification"in window} -function songChange(a){if("error"!=a.type&&"result"!=a.type){var b=a.data.Title+a.data.Artist+a.data.Album+a.data.uri+a.data.currentSongId;if(lastSong!=b){var c="",d="",e="myMPD: ";domCache.currentCover.style.backgroundImage='url("'+a.data.cover+'")';"undefined"!=typeof a.data.Artist&&0=c;c++)b+='";a=document.getElementById(a);a.innerHTML=b;a.addEventListener("click",function(a){switch(a.target.innerText){case "delete":b="-";break;case "#":b="0";break;default:b=a.target.innerText}appGoto(app.current.app, app.current.tab,app.current.view,"0/"+b+"/"+app.current.search)},!1)}function selectTag(a,b,c){a=document.getElementById(a);var d=a.querySelector(".active");d&&d.classList.remove("active");if(d=a.querySelector("[data-tag="+c+"]"))d.classList.add("active"),document.getElementById(b).innerText=d.innerText} function addTagList(a,b){var c="";"searchtags"==b&&(1==settings.featTags&&(c+=''),c+='');for(var d=0;d'+settings[b][d]+"";document.getElementById(a).innerHTML=c} -function gotoTagList(){appGoto(app.current.app,app.current.tab,app.current.view,"0/-/")}function chVolume(a){a=parseInt(domCache.volumeBar.value)+a;0>a?a=0:100d?"0":""):"")+d+"\u2009m "+(10>a?"0":"")+a+"\u2009s"} -function genId(a){return"id"+a.replace(/[^\w\-]/g,"")}appInit(); +function gotoTagList(){appGoto(app.current.app,app.current.tab,app.current.view,"0/-/")}function openModal(a){window[a].show()}function chVolume(a){a=parseInt(domCache.volumeBar.value)+a;0>a?a=0:100d?"0":""):"")+d+"\u2009m "+(10>a?"0":"")+a+"\u2009s"}function genId(a){return"id"+a.replace(/[^\w\-]/g,"")}appInit(); diff --git a/dist/htdocs/sw.min.js b/dist/htdocs/sw.min.js index 9251b74..d2c5825 100644 --- a/dist/htdocs/sw.min.js +++ b/dist/htdocs/sw.min.js @@ -10,5 +10,5 @@ function(){function a(a){return function(d){c||(c=!0,a.call(b,d))}}var b=this,c= void 0;try{d=a.then}catch(h){this.reject_(h);return}"function"==typeof d?this.settleSameAsThenable_(d,a):this.fulfill_(a)};c.prototype.reject_=function(a){this.settle_(2,a)};c.prototype.fulfill_=function(a){this.settle_(1,a)};c.prototype.settle_=function(a,b){if(0!=this.state_)throw Error("Cannot settle("+a+", "+b+"): Promise already settled in state"+this.state_);this.state_=a;this.result_=b;this.executeOnSettledCallbacks_()};c.prototype.executeOnSettledCallbacks_=function(){if(null!=this.onSettledCallbacks_){for(var a= 0;a - + + diff --git a/htdocs/js/keymap.js b/htdocs/js/keymap.js new file mode 100644 index 0000000..373308f --- /dev/null +++ b/htdocs/js/keymap.js @@ -0,0 +1,25 @@ +var keymap = { + "shiftKey": { + "83": {"cmd": "MPD_API_QUEUE_SHUFFLE", "options": []}, // S + "67": {"cmd": "MPD_API_QUEUE_CROP", "options": []} // C + }, + "key": { + "37": {"cmd": "clickPrev", "options": []}, // cursor left + "39": {"cmd": "clickNext", "options": []}, // cursor right + "32": {"cmd": "clickPlay", "options": []}, // space + "83": {"cmd": "clickStop", "options": []}, // s + "173": {"cmd": "chVolume", "options": [-5]}, // + + "171": {"cmd": "chVolume", "options": [5]}, // - + "67": {"cmd": "MPD_API_QUEUE_CLEAR", "options": []}, // c + "85": {"cmd": "updateDB", "options": []}, // u + "82": {"cmd": "rescanDB", "options": []}, // r + "80": {"cmd": "updateSmartPlaylists", "options": []}, // p + "65": {"cmd": "showAddToPlaylist", "options": ["stream"]}, // a + "84": {"cmd": "openModal", "options": ["modalSettings"]}, // t + "89": {"cmd": "openModal", "options": ["modalAbout"]}, // y + "49": {"cmd": "appGoto", "options": ["Playback"]}, // 1 + "50": {"cmd": "appGoto", "options": ["Queue"]}, // 2 + "51": {"cmd": "appGoto", "options": ["Browse"]}, // 3 + "52": {"cmd": "appGoto", "options": ["Search"]} // 4 + } +} diff --git a/htdocs/js/mympd.js b/htdocs/js/mympd.js index f6a6972..4897e5e 100644 --- a/htdocs/js/mympd.js +++ b/htdocs/js/mympd.js @@ -85,6 +85,7 @@ domCache.btnVoteDown = document.getElementById('btnVoteDown'); var modalConnectionError = new Modal(document.getElementById('modalConnectionError'), { backdrop: 'static', keyboard: false}); var modalSettings = new Modal(document.getElementById('modalSettings')); +var modalAbout = new Modal(document.getElementById('modalAbout')); var modalSavequeue = new Modal(document.getElementById('modalSaveQueue')); var modalSongDetails = new Modal(document.getElementById('modalSongDetails')); var modalAddToPlaylist = new Modal(document.getElementById('modalAddToPlaylist')); @@ -607,59 +608,24 @@ function appInit() { sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState); }, false); + document.addEventListener('keydown', function(event) { if (event.target.tagName == 'INPUT' || event.target.tagName == 'SELECT') return; if (event.ctrlKey || event.altKey) return; - if (event.shiftKey) { - switch (event.which) { - case 83: //S - sendAPI({"cmd": "MPD_API_QUEUE_SHUFFLE"}); - break; - case 67: //C - sendAPI({"cmd": "MPD_API_QUEUE_CROP"}); - break; - default: - return; - } - } - else { - switch (event.which) { - case 37: //left - clickPrev(); - break; - case 39: //right - clickNext(); - break; - case 32: //space - clickPlay(); - break; - case 83: //s - clickStop(); - break; - case 173: //- - chVolume(-5); - break; - case 171: //+ - chVolume(5); - break; - case 67: //c - sendAPI({"cmd": "MPD_API_QUEUE_CLEAR"}); - break; - case 85: //u - updateDB(); - break; - case 82: //r - rescanDB(); - break; - case 80: //p - updateSmartPlaylists(); - break; - default: - return; - } - } + var cmd; + if (event.shiftKey) + cmd = keymap.shiftKey[event.which]; + else + cmd = keymap.key[event.which]; + + if (cmd && typeof window[cmd.cmd] === 'function') { + if (cmd.cmd == 'sendAPI') + sendAPI(... cmd.options); + else + window[cmd.cmd](... cmd.options); + } event.preventDefault(); }, false); @@ -2851,6 +2817,10 @@ function gotoTagList() { appGoto(app.current.app, app.current.tab, app.current.view, '0/-/'); } +function openModal(modal) { + window[modal].show(); +} + function chVolume(increment) { var newValue = parseInt(domCache.volumeBar.value) + increment; if (newValue < 0) diff --git a/htdocs/sw.js b/htdocs/sw.js index 4a683b5..f289d04 100644 --- a/htdocs/sw.js +++ b/htdocs/sw.js @@ -7,6 +7,7 @@ var urlsToCache = [ '/js/bootstrap-native-v4.min.js', '/js/mympd.min.js', '/js/player.min.js', + '/js/keymap.min.js', '/assets/appicon-167.png', '/assets/appicon-192.png', '/assets/appicon-512.png', diff --git a/mkdebug.sh b/mkdebug.sh index dfcd094..853cd24 100755 --- a/mkdebug.sh +++ b/mkdebug.sh @@ -3,6 +3,7 @@ [ -e $PWD/htdocs/js/mympd.min.js ] || ln -s $PWD/htdocs/js/mympd.js $PWD/htdocs/js/mympd.min.js [ -e $PWD/htdocs/js/player.min.js ] || ln -s $PWD/htdocs/js/player.js $PWD/htdocs/js/player.min.js [ -e $PWD/htdocs/js/bootstrap-native-v4.min.js ] || ln -s $PWD/dist/htdocs/js/bootstrap-native-v4.js $PWD/htdocs/js/bootstrap-native-v4.min.js +[ -e $PWD/htdocs/js/keymap.min.js ] || ln -s $PWD/htdocs/js/keymap.js $PWD/htdocs/js/keymap.min.js [ -e $PWD/htdocs/css/mympd.min.css ] || ln -s $PWD/htdocs/css/mympd.css $PWD/htdocs/css/mympd.min.css [ -e $PWD/htdocs/css/bootstrap.min.css ] || ln -s $PWD/dist/htdocs/css/bootstrap.min.css $PWD/htdocs/css/bootstrap.min.css diff --git a/mkrelease.sh b/mkrelease.sh index 8481668..9d4763a 100755 --- a/mkrelease.sh +++ b/mkrelease.sh @@ -11,6 +11,8 @@ then java -jar dist/buildtools/closure-compiler.jar htdocs/js/mympd.js > dist/htdocs/js/mympd.min.js [ htdocs/sw.js -nt dist/htdocs/sw.min.js ] && \ java -jar dist/buildtools/closure-compiler.jar htdocs/sw.js > dist/htdocs/sw.min.js + [ htdocs/js/keymap.js -nt dist/htdocs/js/keymap.min.js ] && \ + java -jar dist/buildtools/closure-compiler.jar htdocs/js/keymap.js > dist/htdocs/js/keymap.min.js else echo "dist/buildtools/closure-compiler.jar not found, using non-minified files" [ htdocs/js/player.js -nt dist/htdocs/js/player.min.js ] && \ @@ -18,7 +20,9 @@ else [ htdocs/js/mympd.js -nt dist/htdocs/js/mympd.min.js ] && \ cp htdocs/js/mympd.js dist/htdocs/js/mympd.min.js [ htdocs/sw.js -nt dist/htdocs/sw.min.js ] && \ - cp htdocs/sw.js dist/htdocs/sw.min.js + cp htdocs/sw.js dist/htdocs/sw.min.js + [ htdocs/js/keymap.js -nt dist/htdocs/js/keymap.min.js ] && \ + cp htdocs/js/keymap.js dist/htdocs/js/keymap.min.js fi if [ -f dist/buildtools/closure-stylesheets.jar ] && [ "$java" != "" ]