diff --git a/common/lkt.js b/common/lkt.js index c2d9881f748ef9b092e0b58a6257da6d13984734..d010534372a2f66b8371d0c129ce6f55c95822b9 100644 --- a/common/lkt.js +++ b/common/lkt.js @@ -87,6 +87,19 @@ class LktClient { /* The status command */ static commandStatus() { + return this.__execGetResult('status'); + } + + /* The current command */ + static commandCurrent() { + return this.__execGetResult('currentsong'); + } + + /* Arguments: + * - command: The command to execute + * Result: + * - A promize with one argument: the dict of the result */ + static __execGetResult(command) { var client = new this(); var once = false; var result = {}; @@ -95,7 +108,7 @@ class LktClient { client.m_socket.setTimeout(0); client.m_socket.on('data', data => { if (!once) { - client.m_socket.write('status\n'); + client.m_socket.write(`${command}\n`); once = true; return null; } else { @@ -141,6 +154,11 @@ class LktClient { LktClient.status_updated = true; logger.debug('lkt', `Got update in status ${JSON.stringify(data)}`); }); + LktClient.commandCurrent().then(data => { + LktClient.__current = data; + LktClient.status_updated = true; + logger.debug('lkt', `Got update in current ${JSON.stringify(data)}`); + }); } static idleActualisation() { @@ -265,6 +283,15 @@ class LktClient { this.timeData.state = state; } + static getCurrent() { + return this.__current; + } + + static getCurrent() { + LktClient.status_updated = false; + return this.__current; + } + static getStatus() { LktClient.status_updated = false; return this.__status; diff --git a/instance/index.js b/instance/index.js index d6eb91dfd0f2a4e72ca66655af05f1bb157cd01b..748607ab826de4ad0d9a6375f9237b2d26279c67 100644 --- a/instance/index.js +++ b/instance/index.js @@ -11,15 +11,18 @@ var currentSong = 0; var dragCounter = 0; var leavedElement; var isDnDFromDB = false; +var isPlaying = false; function updatePlayPauseButton(state) { logger.debug('instance', `State was ${state}`); if (state === 'play') { /* Play */ + isPlaying = true; $('#commandPlay').children().addClass('fa-pause'); $('#commandPlay').children().removeClass('fa-play'); } else { /* Pause or Stop */ + isPlaying = false; $('#commandPlay').children().addClass('fa-play'); $('#commandPlay').children().removeClass('fa-pause'); } @@ -69,16 +72,12 @@ window.onload = () => { var btn = document.getElementById('btn-settings'); var span = document.getElementsByClassName('modal-close')[0]; - btn.onclick = function () { - modal.style.display = 'block'; - }; - - span.onclick = function () { + btn.onclick = () => (modal.style.display = 'block'); + span.onclick = () => { modal.style.display = 'none'; flushFillSettings(); }; - - window.onclick = function (event) { + window.onclick = event => { if (event.target == modal) { modal.style.display = 'none'; } @@ -197,6 +196,19 @@ ipcRenderer.on('reload-queue-responce', (event, arg) => { ipcRenderer.on('send-state', (event, state) => updatePlayPauseButton(state)); +ipcRenderer.on('send-song-mdt', (event, mdt) => { + document.getElementById('mdt-source').innerHTML = mdt.Source; + document.getElementById('mdt-title').innerHTML = `${mdt.Type} - ${mdt.Title}`; + document.getElementById('mdt-text').innerHTML = `Karaoke by ${mdt.Author}${ + isPlaying ? ' is currently playing' : ' is loaded but not playing' + }`; + + document.getElementById('mdt-other').innerHTML = ` + <span class="badge bg-light text-dark">${mdt.Category}</span> + <span class="badge bg-light text-dark">${mdt.Language}</span> + `; +}); + ipcRenderer.on('send-song-time-data', (event, timeData) => { document.getElementById('progressBar').style.width = `${ (timeData.elapsed / timeData.total) * document.documentElement.clientWidth diff --git a/instance/views/menu/mdt.ejs b/instance/views/menu/mdt.ejs index 4405e868c39ffedc84dc70b37825e3085c6f949c..c56d6c927439c1841b5a64c83d0616ab3f1a7b76 100644 --- a/instance/views/menu/mdt.ejs +++ b/instance/views/menu/mdt.ejs @@ -1,7 +1,12 @@ <%# vim: ts=4 syntax=html This is the template for the collapsable mdt view menu %> <div class="collapse" id="mdt-view"> - <div class="card card-body"> - This is the MDT menu view - </div> + <div class="card"> + <div class="card-body"> + <h5 class="card-title" id="mdt-source"></h5> + <h6 class="card-subtitle mb-2" id="mdt-title"></h6> + <p class="card-text" id="mdt-text"></p> + <p id="mdt-other"></p> + </div> + </div> </div> diff --git a/main.js b/main.js index c5651b2671ebdf512ea73ff74851a37f6e572297..544d242088497da044bdd317dac6da7dea397cdf 100644 --- a/main.js +++ b/main.js @@ -340,6 +340,10 @@ ipcMain.on('verify-lektord', (event, arg) => { setInterval(() => { if (!destroyed && lkt.isStatusUpdated()) { win.webContents.send('send-state', lkt.getStatus().state); + const current = lkt.getCurrent(); + if (typeof current != 'undefined') { + win.webContents.send('send-song-mdt', current); + } } }, 50), ]);