Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 2b77117a rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Can now reload kara list from DB

parent a16eaf10
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!3Dev kubat,!2Base interface and system
......@@ -6,3 +6,8 @@ prepare:
run:
$(YARN) start --no-sandbox
debug:
$(YARN) test --no-sandbox
.PHONY: test debug run prepare
......@@ -58,7 +58,30 @@ class KaraDatabase {
return new Promise(resolv => {
db.all(__sqlQuery, [`%${queryString}%`, queryString], (err, rows) => {
if (err) {
logger.log("error", err);
logger.error(err);
throw err;
}
rows.forEach((row) => { __ret.push(row); });
resolv(__ret);
});
});
};
return __getRecords(this.m_db);
}
/* List all the kara in the db.
* => a promize, callback with [(id: Int, string: String, cat: String, type: String)] */
all() {
var __ret = [];
let __sqlQuery = `SELECT id, string, category AS cat, (song_type || song_number) AS type
FROM kara;`;
function __getRecords(db) {
return new Promise(resolv => {
db.all(__sqlQuery, [], (err, rows) => {
if (err) {
logger.error(err);
throw err;
}
rows.forEach((row) => { __ret.push(row); });
......
const { ipcRenderer } = require('electron');
const logger = require('../common/logger.js');
const karaJSON = require('../test/dummyKara.json');
const buttonList = [
[ "left", "Reload", "reloadDb" ],
[ "left", "Play", "commandPlay" ],
[ "left", "Stop", "commandStop" ],
[ "right", "Quit LektorApp", "closeButton" ]
[ "right", "Quit LektorApp", "closeButton" ],
];
const karaJSON = require('../test/dummyKara.json');
window.onload = () => {
createButtonList(buttonList);
karaList(karaJSON);
// karaList(karaJSON);
document.getElementById("closeButton").addEventListener('click', () => {
ipcRenderer.send('close-app')
});
document.getElementById("commandPlay").addEventListener('click', () => {
logger.debug("Command play !");
ipcRenderer.send('cmd-play', null);
});
document.getElementById("commandStop").addEventListener('click', () => {
logger.debug("Command stop !");
ipcRenderer.send("cmd-stop", null);
});
document.getElementById("reloadDb").addEventListener("click", () => {
ipcRenderer.send("reload-db-request", document.getElementById("buttonPanelListLeft").innerHTML);
});
logger.debug("Window loaded");
}
};
function createButtonList(list) {
var renderHtmlLeft = "";
......@@ -43,6 +53,11 @@ function createButtonList(list) {
document.getElementById("buttonPanelListLeft").innerHTML = renderHtmlLeft + renderHtmlRight;
}
ipcRenderer.on("reload-db-responce", (event, arg) => {
logger.debug(`Web page got reload-db`);
document.getElementById("panelLeft").innerHTML = arg;
});
function karaList(karas) {
var karaList = "";
var playingList = "";
......
......@@ -3,19 +3,26 @@ const electron = require('electron')
const { app, BrowserWindow } = require('electron')
const { ipcMain } = require('electron')
const { fork, spawn } = require('child_process');
const fs = require("fs");
var tail = require('tail').Tail;
var client; /* Sub process for the express server */
const fs = require("fs");
const db = require.main.require("./common/db.js");
const lkt = require.main.require("./common/lkt.js");
var tail = require('tail').Tail;
var client; /* Sub process for the express server */
var myDb = new db("/home/kara/kara.db");
/**********************
* Reinit the logfile *
**********************/
/* Reinit the logfile */
fs.truncate(logger.logfile, 0, () => {});
var tail = new tail(logger.logfile);
tail.on("line", function(data) { console.log(data); });
tail.on("line", function(data) {
console.log(data);
});
/***************************************************************
* Creates the main window and process for the admin interface *
***************************************************************/
/* Creates the main window and process for the admin interface */
function createInstanceWindow () {
const win = new BrowserWindow({
width: 1280,
......@@ -30,18 +37,50 @@ function createInstanceWindow () {
// win.webContents.openDevTools();
}
/******************************
* The end of the application *
******************************/
ipcMain.on('close-app', (evt, arg) => {
app.quit()
})
app.on("quit", () => {
logger.info("Send SIGTERM to express process and tailler process");
logger.info("Send SIGTERM to express process and tailler process");
client.kill("SIGTERM");
});
/*********************************
* The beggin of the application *
*********************************/
app.on('ready', () => {
logger.info("Main window is ready");
createInstanceWindow();
client = fork('client/main.js');
});
/*********************************
* Messages from the main window *
*********************************/
ipcMain.on("cmd-play", (event, arg) => {
logger.debug(`${event}: ${arg}`);
});
ipcMain.on("cmd-stop", (event, arg) => {
logger.debug(`${event}: ${arg}`);
});
/* Fill the pannel with the content of the DB.
* The `arg` is the HTML object of the pannel */
ipcMain.on("reload-db-request", (event, arg) => {
logger.info("Reloading the left panel with all the DB");
myDb.all().then( karas => {
var karaList = "";
karas.forEach( kara => {
karaList += `<div class="card shadow" style="margin: 5px; border-radius: 10px; margin: 20px 0px 20px 0px;">
<div class="card-body">${kara.string} </div></div>`;
});
event.reply("reload-db-responce", karaList);
});
});
......@@ -12,7 +12,7 @@
"license": "ISC",
"scripts": {
"start": "electron .",
"test": "ELECTRON_ENABLE_LOGGING=0 ELECTRON_NO_ATTACH_CONSOLE=true electron ."
"test": "ELECTRON_ENABLE_LOGGING=0 ELECTRON_NO_ATTACH_CONSOLE=true electron --trace-uncaught ."
},
"dependencies": {
"ejs": "^3.1.5",
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter