ref: add debug arguments

This commit is contained in:
leukipp
2025-02-23 13:01:14 +01:00
parent a37226fd39
commit 6d23efd713
4 changed files with 28 additions and 22 deletions
+5 -2
View File
@@ -7,6 +7,8 @@ const hardware = require("./src/hardware");
const webview = require("./src/webview"); const webview = require("./src/webview");
const { app } = require("electron"); const { app } = require("electron");
global.ARGS = global.ARGS || {};
/** /**
* This promise resolves when the app has finished initializing, * This promise resolves when the app has finished initializing,
* allowing to safely create browser windows and perform other * allowing to safely create browser windows and perform other
@@ -34,14 +36,15 @@ app.whenReady().then(async () => {
} else if (!argsProvided && argsFileExists) { } else if (!argsProvided && argsFileExists) {
args = readArgs(argsFilePath); args = readArgs(argsFilePath);
} }
global.ARGS = args;
// Show used arguments // Show used arguments
console.log(`Arguments: ${JSON.stringify(args, null, 2)}`); console.log(`Arguments: ${JSON.stringify(global.ARGS, null, 2)}`);
// Chained init functions // Chained init functions
const chained = [webview.init, hardware.init, integration.init]; const chained = [webview.init, hardware.init, integration.init];
for (const init of chained) { for (const init of chained) {
if (!(await init(args))) { if (!(await init())) {
break; break;
} }
} }
+1 -2
View File
@@ -29,10 +29,9 @@ global.HARDWARE = global.HARDWARE || {
/** /**
* Initializes the hardware with the provided arguments. * Initializes the hardware with the provided arguments.
* *
* @param {Object} args - The command-line arguments to customize the initialization process.
* @returns {boolean} Returns true if the initialization was successful. * @returns {boolean} Returns true if the initialization was successful.
*/ */
const init = async (args) => { const init = async () => {
if (!compatibleDevice()) { if (!compatibleDevice()) {
console.warn("Device not supported"); console.warn("Device not supported");
return false; return false;
+7 -8
View File
@@ -10,21 +10,20 @@ global.INTEGRATION = global.INTEGRATION || {
/** /**
* Initializes the integration with the provided arguments. * Initializes the integration with the provided arguments.
* *
* @param {Object} args - The command-line arguments to customize the initialization process.
* @returns {boolean} Returns true if the initialization was successful. * @returns {boolean} Returns true if the initialization was successful.
*/ */
const init = async (args) => { const init = async () => {
if (!args.mqtt_url) { if (!ARGS.mqtt_url) {
return false; return false;
} }
if (!/^mqtts?:\/\//.test(args.mqtt_url)) { if (!/^mqtts?:\/\//.test(ARGS.mqtt_url)) {
console.error("Please provide the '--mqtt-url' parameter with mqtt(s)"); console.error("Please provide the '--mqtt-url' parameter with mqtt(s)");
return app.quit(); return app.quit();
} }
const url = new URL(args.mqtt_url); const url = new URL(ARGS.mqtt_url);
const user = args.mqtt_user ? args.mqtt_user : null; const user = ARGS.mqtt_user ? ARGS.mqtt_user : null;
const password = args.mqtt_password ? args.mqtt_password : null; const password = ARGS.mqtt_password ? ARGS.mqtt_password : null;
const discovery = args.mqtt_discovery ? args.mqtt_discovery : "homeassistant"; const discovery = ARGS.mqtt_discovery ? ARGS.mqtt_discovery : "homeassistant";
const model = hardware.getModel(); const model = hardware.getModel();
const vendor = hardware.getVendor(); const vendor = hardware.getVendor();
+15 -10
View File
@@ -16,22 +16,22 @@ global.WEBVIEW = global.WEBVIEW || {
/** /**
* Initializes the webview with the provided arguments. * Initializes the webview with the provided arguments.
* *
* @param {Object} args - The command-line arguments to customize the initialization process.
* @returns {boolean} Returns true if the initialization was successful. * @returns {boolean} Returns true if the initialization was successful.
*/ */
const init = async (args) => { const init = async () => {
if (!args.web_url) { if (!ARGS.web_url) {
console.error("Please provide the '--web-url' parameter"); console.error("Please provide the '--web-url' parameter");
return app.quit(); return app.quit();
} }
if (!/^https?:\/\//.test(args.web_url)) { if (!/^https?:\/\//.test(ARGS.web_url)) {
console.error("Please provide the '--web-url' parameter with http(s)"); console.error("Please provide the '--web-url' parameter with http(s)");
return app.quit(); return app.quit();
} }
const url = new URL(args.web_url); const url = new URL(ARGS.web_url);
const theme = ["light", "dark"].includes(args.web_theme) ? args.web_theme : "dark"; const theme = ["light", "dark"].includes(ARGS.web_theme) ? ARGS.web_theme : "dark";
const zoom = !isNaN(parseFloat(args.web_zoom)) ? parseFloat(args.web_zoom) : 1.25; const zoom = !isNaN(parseFloat(ARGS.web_zoom)) ? parseFloat(ARGS.web_zoom) : 1.25;
const widget = args.web_widget ? args.web_widget === "true" : true; const widget = ARGS.web_widget ? ARGS.web_widget === "true" : true;
const fullscreen = ARGS.app_debug !== "true";
// Init global layout // Init global layout
WEBVIEW.viewZoom = zoom; WEBVIEW.viewZoom = zoom;
@@ -46,7 +46,10 @@ const init = async (args) => {
icon: path.join(__dirname, "..", "img", "icon.png"), icon: path.join(__dirname, "..", "img", "icon.png"),
}); });
WEBVIEW.window.setMenuBarVisibility(false); WEBVIEW.window.setMenuBarVisibility(false);
WEBVIEW.window.setFullScreen(true); WEBVIEW.window.setFullScreen(fullscreen);
if (!fullscreen) {
WEBVIEW.window.maximize();
}
// Init global webview // Init global webview
WEBVIEW.view = new WebContentsView({ WEBVIEW.view = new WebContentsView({
@@ -288,7 +291,9 @@ const domEvents = () => {
// Webview fully loaded // Webview fully loaded
WEBVIEW.view.webContents.on("did-finish-load", () => { WEBVIEW.view.webContents.on("did-finish-load", () => {
// view.webContents.openDevTools(); if (ARGS.app_debug === "true") {
WEBVIEW.view.webContents.openDevTools();
}
WEBVIEW.initialized = true; WEBVIEW.initialized = true;
update(); update();
}); });