2022-03-03 18:57:40 +00:00
|
|
|
const path = require('path');
|
|
|
|
const {ipcRenderer} = require('electron');
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/26227660
|
|
|
|
var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.config")
|
|
|
|
var configFolder = path.join(appDataFolder, "FreeDATA");
|
|
|
|
var configPath = path.join(configFolder, 'config.json')
|
|
|
|
const config = require(configPath);
|
|
|
|
|
|
|
|
|
|
|
|
// WINDOW LISTENER
|
|
|
|
window.addEventListener('DOMContentLoaded', () => {
|
2022-11-09 11:59:35 +00:00
|
|
|
document.getElementById('enable_filter_info').addEventListener('click', () => {
|
|
|
|
if (document.getElementById('enable_filter_info').checked){
|
|
|
|
display_class("table-info", true)
|
|
|
|
} else {
|
|
|
|
display_class("table-info", false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
document.getElementById('enable_filter_debug').addEventListener('click', () => {
|
|
|
|
if (document.getElementById('enable_filter_debug').checked){
|
|
|
|
display_class("table-debug", true)
|
|
|
|
} else {
|
|
|
|
display_class("table-debug", false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
document.getElementById('enable_filter_warning').addEventListener('click', () => {
|
|
|
|
if (document.getElementById('enable_filter_warning').checked){
|
|
|
|
display_class("table-warning", true)
|
|
|
|
} else {
|
|
|
|
display_class("table-warning", false)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
document.getElementById('enable_filter_error').addEventListener('click', () => {
|
|
|
|
if (document.getElementById('enable_filter_error').checked){
|
2022-11-10 10:27:52 +00:00
|
|
|
display_class("table-danger", true)
|
2022-11-09 11:59:35 +00:00
|
|
|
} else {
|
2022-11-10 10:27:52 +00:00
|
|
|
display_class("table-danger", false)
|
2022-11-09 11:59:35 +00:00
|
|
|
}
|
|
|
|
})
|
2022-03-03 18:57:40 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2022-11-09 11:59:35 +00:00
|
|
|
function display_class(class_name, state){
|
2022-11-10 10:27:52 +00:00
|
|
|
var collection = document.getElementsByClassName(class_name);
|
|
|
|
console.log(collection)
|
2022-11-09 11:59:35 +00:00
|
|
|
for (let i = 0; i < collection.length; i++) {
|
2022-11-10 10:27:52 +00:00
|
|
|
if (state == true){
|
|
|
|
collection[i].style.display = "table-row";
|
2022-11-09 11:59:35 +00:00
|
|
|
} else {
|
|
|
|
collection[i].style.display = "None";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-03 18:57:40 +00:00
|
|
|
ipcRenderer.on('action-update-log', (event, arg) => {
|
|
|
|
|
|
|
|
var entry = arg.entry
|
|
|
|
|
|
|
|
// remove ANSI characters from string, caused by color logging
|
|
|
|
// https://stackoverflow.com/a/29497680
|
|
|
|
entry = entry.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,'')
|
|
|
|
|
2022-11-09 20:07:40 +00:00
|
|
|
|
2022-03-03 18:57:40 +00:00
|
|
|
var tbl = document.getElementById("log");
|
|
|
|
var row = document.createElement("tr");
|
|
|
|
|
|
|
|
var timestamp = document.createElement("td");
|
|
|
|
var timestampText = document.createElement('span');
|
2022-11-09 20:07:40 +00:00
|
|
|
|
|
|
|
//datetime = new Date();
|
|
|
|
//timestampText.innerText = datetime.toISOString();
|
|
|
|
timestampText.innerText = entry.slice(0, 19);
|
2022-03-03 18:57:40 +00:00
|
|
|
timestamp.appendChild(timestampText);
|
2022-11-09 20:07:40 +00:00
|
|
|
|
|
|
|
var type = document.createElement("td");
|
|
|
|
var typeText = document.createElement('span');
|
|
|
|
// typeText.innerText = entry.slice(10, 30).match(/[\[](.*)[^\]]/g);
|
2022-11-10 10:27:52 +00:00
|
|
|
console.log(entry.match(/\[[^\]]+\]/g))
|
2022-11-09 20:07:40 +00:00
|
|
|
|
2022-11-10 10:27:52 +00:00
|
|
|
try{
|
|
|
|
typeText.innerText = entry.match(/\[[^\]]+\]/g)[0];
|
|
|
|
} catch(e){
|
|
|
|
typeText.innerText = '-'
|
|
|
|
}
|
2022-11-09 20:07:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
// let res = str.match(/[\[](.*)[^\]]/g);
|
|
|
|
|
|
|
|
type.appendChild(typeText);
|
|
|
|
|
|
|
|
var area = document.createElement("td");
|
|
|
|
var areaText = document.createElement('span');
|
|
|
|
//areaText.innerText = entry.slice(10, 50).match(/[\] \[](.*)[^\]]/g);
|
2022-11-10 10:27:52 +00:00
|
|
|
//areaText.innerText = entry.match(/\[[^\]]+\]/g)[1];
|
|
|
|
|
|
|
|
try{
|
|
|
|
areaText.innerText = entry.match(/\[[^\]]+\]/g)[1];
|
|
|
|
} catch(e){
|
|
|
|
areaText.innerText = '-'
|
|
|
|
}
|
2022-11-09 20:07:40 +00:00
|
|
|
area.appendChild(areaText);
|
2022-03-03 18:57:40 +00:00
|
|
|
|
|
|
|
var logEntry = document.createElement("td");
|
|
|
|
var logEntryText = document.createElement('span');
|
2022-11-10 10:27:52 +00:00
|
|
|
try{logEntryText.innerText = entry.split("]")[2];
|
|
|
|
} catch(e){
|
|
|
|
logEntryText.innerText = "-";
|
|
|
|
}
|
2022-03-03 18:57:40 +00:00
|
|
|
logEntry.appendChild(logEntryText);
|
|
|
|
|
|
|
|
row.appendChild(timestamp);
|
2022-11-09 20:07:40 +00:00
|
|
|
row.appendChild(type);
|
|
|
|
row.appendChild(area);
|
2022-03-03 18:57:40 +00:00
|
|
|
row.appendChild(logEntry);
|
|
|
|
|
2022-11-10 10:27:52 +00:00
|
|
|
//row.classList.add("table-blablubb");
|
|
|
|
/*
|
2022-03-03 18:57:40 +00:00
|
|
|
if (logEntryText.innerText.includes('ALSA lib pcm')) {
|
|
|
|
row.classList.add("table-secondary");
|
|
|
|
}
|
2022-11-10 10:27:52 +00:00
|
|
|
*/
|
|
|
|
if (typeText.innerText.includes('info')) {
|
2022-03-03 18:57:40 +00:00
|
|
|
row.classList.add("table-info");
|
|
|
|
}
|
2022-11-10 10:27:52 +00:00
|
|
|
if (typeText.innerText.includes('debug')) {
|
2022-03-03 18:57:40 +00:00
|
|
|
row.classList.add("table-secondary");
|
|
|
|
}
|
|
|
|
|
2022-11-10 10:27:52 +00:00
|
|
|
if (typeText.innerText.includes('warning')) {
|
2022-03-03 18:57:40 +00:00
|
|
|
row.classList.add("table-warning");
|
|
|
|
}
|
|
|
|
|
2022-11-10 10:27:52 +00:00
|
|
|
if (typeText.innerText.includes('error')) {
|
2022-03-03 18:57:40 +00:00
|
|
|
row.classList.add("table-danger");
|
2022-11-10 10:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (document.getElementById('enable_filter_info').checked) {
|
|
|
|
row.style.display = "table-row"
|
|
|
|
display_class("table-info", true)
|
|
|
|
} else {
|
|
|
|
row.style.display = "None"
|
|
|
|
display_class("table-info", false)
|
|
|
|
|
|
|
|
}
|
|
|
|
if (document.getElementById('enable_filter_debug').checked) {
|
|
|
|
row.style.display = "table-row"
|
|
|
|
display_class("table-secondary", true)
|
|
|
|
} else {
|
|
|
|
row.style.display = "None"
|
|
|
|
display_class("table-secondary", false)
|
|
|
|
|
|
|
|
}
|
|
|
|
if (document.getElementById('enable_filter_warning').checked) {
|
|
|
|
row.style.display = "table-row"
|
|
|
|
display_class("table-warning", true)
|
|
|
|
} else {
|
|
|
|
row.style.display = "None"
|
|
|
|
display_class("table-warning", false)
|
|
|
|
|
|
|
|
}
|
|
|
|
if (document.getElementById('enable_filter_error').checked) {
|
|
|
|
row.style.display = "table-row"
|
|
|
|
display_class("table-danger", true)
|
|
|
|
} else {
|
|
|
|
row.style.display = "None"
|
|
|
|
display_class("table-danger", false)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tbl.appendChild(row);
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-09 11:59:35 +00:00
|
|
|
|
2022-03-03 18:57:40 +00:00
|
|
|
|
|
|
|
// scroll to bottom of page
|
|
|
|
// https://stackoverflow.com/a/11715670
|
|
|
|
window.scrollTo(0,document.body.scrollHeight);
|
|
|
|
|
|
|
|
|
|
|
|
})
|