feat: extended logging #73
This commit is contained in:
@@ -5,6 +5,7 @@ const readline = require("readline/promises");
|
|||||||
const integration = require("./js/integration");
|
const integration = require("./js/integration");
|
||||||
const hardware = require("./js/hardware");
|
const hardware = require("./js/hardware");
|
||||||
const webview = require("./js/webview");
|
const webview = require("./js/webview");
|
||||||
|
const log = require("electron-log");
|
||||||
const { app } = require("electron");
|
const { app } = require("electron");
|
||||||
const Events = require("events");
|
const Events = require("events");
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ if (!process.env.DISPLAY) {
|
|||||||
* initialization tasks.
|
* initialization tasks.
|
||||||
*/
|
*/
|
||||||
app.whenReady().then(async () => {
|
app.whenReady().then(async () => {
|
||||||
if (!(await initApp()) || !(await initArgs())) {
|
if (!(await initApp()) || !(await initArgs()) || !(await initLog())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ const initApp = async () => {
|
|||||||
APP.version = app.getVersion();
|
APP.version = app.getVersion();
|
||||||
APP.path = app.getAppPath();
|
APP.path = app.getAppPath();
|
||||||
APP.config = app.getPath("userData");
|
APP.config = app.getPath("userData");
|
||||||
|
APP.log = path.join(app.getPath("logs"), "main.log");
|
||||||
|
|
||||||
// Set additional update infos
|
// Set additional update infos
|
||||||
APP.homepage = `https://github.com/${packageJson.author}/${packageJson.name}`;
|
APP.homepage = `https://github.com/${packageJson.author}/${packageJson.name}`;
|
||||||
@@ -135,6 +137,29 @@ const initArgs = async () => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the global log object.
|
||||||
|
*
|
||||||
|
* @returns {bool} Returns true if the initialization was successful.
|
||||||
|
*/
|
||||||
|
const initLog = async () => {
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(APP.log)) {
|
||||||
|
fs.unlinkSync(APP.log);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to delete log file:", error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overwrite console log settings
|
||||||
|
log.transports.file.resolvePathFn = () => {
|
||||||
|
return APP.log;
|
||||||
|
};
|
||||||
|
Object.assign(console, log.functions);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses command-line arguments from the given process object.
|
* Parses command-line arguments from the given process object.
|
||||||
*
|
*
|
||||||
|
|||||||
+13
-10
@@ -37,7 +37,7 @@ global.HARDWARE = global.HARDWARE || {
|
|||||||
*/
|
*/
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
if (!compatibleSystem()) {
|
if (!compatibleSystem()) {
|
||||||
console.warn("Operating system is not supported\n");
|
console.error("Operating system is not supported");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,33 +54,35 @@ const init = async () => {
|
|||||||
HARDWARE.initialized = true;
|
HARDWARE.initialized = true;
|
||||||
|
|
||||||
// Show supported features
|
// Show supported features
|
||||||
console.log(`\nSupported: ${JSON.stringify(HARDWARE.support, null, 2)}`);
|
process.stdout.write("\n");
|
||||||
|
console.log(`Supported: ${JSON.stringify(HARDWARE.support, null, 2)}`);
|
||||||
|
|
||||||
// Show session infos
|
// Show session infos
|
||||||
console.log("\nUser:", HARDWARE.session.user);
|
process.stdout.write("\n");
|
||||||
|
console.log("User:", HARDWARE.session.user);
|
||||||
console.log("Session:", HARDWARE.session.type);
|
console.log("Session:", HARDWARE.session.type);
|
||||||
console.log("Desktop:", HARDWARE.session.desktop);
|
console.log("Desktop:", HARDWARE.session.desktop);
|
||||||
|
|
||||||
// Show device infos
|
// Show device infos
|
||||||
console.log("\nModel:", getModel());
|
process.stdout.write("\n");
|
||||||
|
console.log("Model:", getModel());
|
||||||
console.log("Vendor:", getVendor());
|
console.log("Vendor:", getVendor());
|
||||||
console.log("Serial Number:", getSerialNumber());
|
console.log("Serial Number:", getSerialNumber());
|
||||||
console.log("Network Addresses:", getNetworkAddresses());
|
console.log("Network Addresses:", getNetworkAddresses());
|
||||||
console.log("Host Name:", getHostName());
|
console.log("Host Name:", getHostName());
|
||||||
|
|
||||||
// Show system infos
|
// Show system infos
|
||||||
console.log("\nUp Time:", getUpTime());
|
process.stdout.write("\n");
|
||||||
|
console.log("Up Time:", getUpTime());
|
||||||
console.log("Memory Size:", getMemorySize());
|
console.log("Memory Size:", getMemorySize());
|
||||||
console.log("Memory Usage:", getMemoryUsage());
|
console.log("Memory Usage:", getMemoryUsage());
|
||||||
console.log("Processor Usage:", getProcessorUsage());
|
console.log("Processor Usage:", getProcessorUsage());
|
||||||
console.log("Processor Temperature:", getProcessorTemperature());
|
console.log("Processor Temperature:", getProcessorTemperature());
|
||||||
|
|
||||||
// Show hardware infos
|
// Show hardware infos
|
||||||
|
process.stdout.write("\n");
|
||||||
const unsupported = "unsupported";
|
const unsupported = "unsupported";
|
||||||
console.log(
|
console.log(`Battery Level [${HARDWARE.battery.level.path || unsupported}]:`, `${getBatteryLevel() || unsupported}`);
|
||||||
`\nBattery Level [${HARDWARE.battery.level.path || unsupported}]:`,
|
|
||||||
`${getBatteryLevel() || unsupported}`,
|
|
||||||
);
|
|
||||||
console.log(
|
console.log(
|
||||||
`Display Status [${HARDWARE.display.status.path || unsupported}]:`,
|
`Display Status [${HARDWARE.display.status.path || unsupported}]:`,
|
||||||
`${getDisplayStatus() || unsupported} (${HARDWARE.display.status.command || unsupported})`,
|
`${getDisplayStatus() || unsupported} (${HARDWARE.display.status.command || unsupported})`,
|
||||||
@@ -91,10 +93,11 @@ const init = async () => {
|
|||||||
);
|
);
|
||||||
console.log(
|
console.log(
|
||||||
`Keyboard Visibility [${HARDWARE.support.keyboardVisibility ? "squeekboard" : unsupported}]:`,
|
`Keyboard Visibility [${HARDWARE.support.keyboardVisibility ? "squeekboard" : unsupported}]:`,
|
||||||
`${getKeyboardVisibility() || unsupported}\n`,
|
`${getKeyboardVisibility() || unsupported}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check for keyboard visibility
|
// Check for keyboard visibility
|
||||||
|
process.stdout.write("\n");
|
||||||
setKeyboardVisibility("OFF", (reply, error) => {
|
setKeyboardVisibility("OFF", (reply, error) => {
|
||||||
if (!reply || error) {
|
if (!reply || error) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+2
-1
@@ -57,7 +57,8 @@ const init = async () => {
|
|||||||
// Client connected
|
// Client connected
|
||||||
INTEGRATION.client
|
INTEGRATION.client
|
||||||
.once("connect", () => {
|
.once("connect", () => {
|
||||||
console.log(`MQTT Connected: ${url.toString()}\n`);
|
console.log(`MQTT Connected: ${url.toString()}`);
|
||||||
|
process.stdout.write("\n");
|
||||||
|
|
||||||
// Init client controls
|
// Init client controls
|
||||||
initApp();
|
initApp();
|
||||||
|
|||||||
Reference in New Issue
Block a user