diff --git a/common/lkt.js b/common/lkt.js index 87e4b3b667b67f0f6c95427c97cb49966d7cfa8e..916f2b9dbd9ed91d850c4b089519e5767aaabcbf 100644 --- a/common/lkt.js +++ b/common/lkt.js @@ -1,5 +1,7 @@ const logger = require.main.require('./common/logger.js'); const net = require('net'); +const { finished } = require('stream'); +const { cli } = require('winston/lib/winston/config'); class LktClient { /*************************************** @@ -15,6 +17,7 @@ class LktClient { * * Node: You should not use that directly, prefere the use of static * methods */ + constructor(port = 6600) { this.m_online = false; this.m_port = port; @@ -91,6 +94,7 @@ class LktClient { var result = {}; function __getResult(client) { return new Promise(resolv => { + client.m_socket.setTimeout(0); client.m_socket.on('data', data => { if (!once) { client.m_socket.write('status\n'); @@ -132,6 +136,26 @@ class LktClient { } return __getResult(client); } + + + static idleActualisation() + { + var client = new this(); + client.m_socket.setTimeout(0); + function __getResult(client) { + return new Promise((resolve,reject) => { + client.m_socket.on('data',data => { + if(String(data).includes("playlist")) { + LktClient.setQueueUpdated(true); + } + client.m_socket.write(`idle\n`); + return null; + }); + }); + + } + return __getResult(client); + } static commandPlay() { var status= LktClient.commandStatus(); @@ -155,6 +179,7 @@ class LktClient { } } static commandStop() { + //return LktClient.idleActualisation(); return LktClient.__execSimple('stop'); } static commandPrev() { @@ -166,6 +191,9 @@ class LktClient { static commandShuffle() { return LktClient.__execSimple('shuffle'); } + static commandClear(){ + return LktClient.__execSimple('clear'); + } static commandQueueAddId(id) { return LktClient.__execSimple(`add id ${id}`); @@ -177,6 +205,16 @@ class LktClient { { logger.error("Unable to access lektor status:" + error); } + + static queue_updated = false; + + static setQueueUpdated(state) { + this.queue_updated = state; + } + + static isQueueUpdated() { + return this.queue_updated; + } } function __mpdToObject(string) { @@ -193,6 +231,7 @@ function __mpdStatusToBool(string) { string = string.split('\n'); string = string[string.length - 1]; return string.split(/ /) == 'OK' ? true : false; + } module.exports = LktClient; diff --git a/instance/main.js b/instance/main.js index 7e317f3b03b5d49bdc46b2142f65418a390f5a95..9d491f0de62d9245859b0f1ab256f2655ea9b660 100644 --- a/instance/main.js +++ b/instance/main.js @@ -47,8 +47,9 @@ window.onload = () => { addIpcToButton('reloadDb', ['reload-db-request', 'reload-queue-request']); logger.debug('Window loaded'); -}; - + setTimeout(()=>ipcRenderer.send('reload-queue-request'),500); + setInterval(()=>ipcRenderer.send('verify-queue-reloaded-request'),1000); +} /* Create the button list */ function createButtonList(list) { function action(ipc, argument) { @@ -136,3 +137,5 @@ ipcRenderer.on('reload-queue-responce', (event, arg) => { }); document.getElementById('panelRight').innerHTML = karaList; }); + + diff --git a/main.js b/main.js index 76296c6161434db1cbdecac28673533d45d33483..8cd34fa1bc8f7f8329ba697d4fa41491bba712f4 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ const logger = require.main.require('./common/logger.js'); const electron = require('electron'); -const { app, BrowserWindow } = require('electron'); +const { app, BrowserWindow, ipcRenderer } = require('electron'); const { globalShortcut } = require('electron'); const { ipcMain } = require('electron'); const { fork, spawn } = require('child_process'); @@ -67,7 +67,6 @@ app.on('ready', () => { createInstanceWindow(); client = fork('client/main.js'); lektor = spawn('lektord', ['-F']); - globalShortcut.register('CommandOrControl+D', () => { var win = BrowserWindow.getFocusedWindow(); if (win === null) { @@ -79,7 +78,6 @@ app.on('ready', () => { contents.send('reload-db-responce', karas); }); }); - globalShortcut.register('CommandOrControl+C', () => {}); globalShortcut.register('F12', () => { var focused = BrowserWindow.getFocusedWindow(); if (focused) { @@ -112,6 +110,7 @@ app.on('ready', () => { } }); }); + setTimeout(() => {lkt.idleActualisation(ipcRenderer);},500); lektor.on('close', code => { logger.warn(`Lektor exited with code ${code}`); lektor_closed = true; @@ -155,3 +154,18 @@ ipcMain.on('reload-queue-request', (event, arg) => { event.reply('reload-queue-responce', karas); }); }); + +ipcMain.on('verify-queue-reloaded-request', (event, arg) => { + if(lkt.isQueueUpdated()) { + lkt.setQueueUpdated(false); + myDb.queue(0, 100).then(karas => { + event.reply('reload-queue-responce', karas); + }); + } +}); + +ReloadQueue = () => { + myDb.queue(0,100).then(karas=>{ + + }) +}