From 6d23efd713ad573ae6afae271dfcf146de9f5e06 Mon Sep 17 00:00:00 2001 From: leukipp Date: Sun, 23 Feb 2025 13:01:14 +0100 Subject: [PATCH] ref: add debug arguments --- index.js | 7 +++++-- src/hardware.js | 3 +-- src/integration.js | 15 +++++++-------- src/webview.js | 25 +++++++++++++++---------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index f4cf7e4..8476c09 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,8 @@ const hardware = require("./src/hardware"); const webview = require("./src/webview"); const { app } = require("electron"); +global.ARGS = global.ARGS || {}; + /** * This promise resolves when the app has finished initializing, * allowing to safely create browser windows and perform other @@ -34,14 +36,15 @@ app.whenReady().then(async () => { } else if (!argsProvided && argsFileExists) { args = readArgs(argsFilePath); } + global.ARGS = args; // Show used arguments - console.log(`Arguments: ${JSON.stringify(args, null, 2)}`); + console.log(`Arguments: ${JSON.stringify(global.ARGS, null, 2)}`); // Chained init functions const chained = [webview.init, hardware.init, integration.init]; for (const init of chained) { - if (!(await init(args))) { + if (!(await init())) { break; } } diff --git a/src/hardware.js b/src/hardware.js index 0d4a147..499444e 100644 --- a/src/hardware.js +++ b/src/hardware.js @@ -29,10 +29,9 @@ global.HARDWARE = global.HARDWARE || { /** * 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. */ -const init = async (args) => { +const init = async () => { if (!compatibleDevice()) { console.warn("Device not supported"); return false; diff --git a/src/integration.js b/src/integration.js index 43173fa..81011cb 100644 --- a/src/integration.js +++ b/src/integration.js @@ -10,21 +10,20 @@ global.INTEGRATION = global.INTEGRATION || { /** * 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. */ -const init = async (args) => { - if (!args.mqtt_url) { +const init = async () => { + if (!ARGS.mqtt_url) { 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)"); return app.quit(); } - const url = new URL(args.mqtt_url); - const user = args.mqtt_user ? args.mqtt_user : null; - const password = args.mqtt_password ? args.mqtt_password : null; - const discovery = args.mqtt_discovery ? args.mqtt_discovery : "homeassistant"; + const url = new URL(ARGS.mqtt_url); + const user = ARGS.mqtt_user ? ARGS.mqtt_user : null; + const password = ARGS.mqtt_password ? ARGS.mqtt_password : null; + const discovery = ARGS.mqtt_discovery ? ARGS.mqtt_discovery : "homeassistant"; const model = hardware.getModel(); const vendor = hardware.getVendor(); diff --git a/src/webview.js b/src/webview.js index 67d79d9..63d4185 100644 --- a/src/webview.js +++ b/src/webview.js @@ -16,22 +16,22 @@ global.WEBVIEW = global.WEBVIEW || { /** * 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. */ -const init = async (args) => { - if (!args.web_url) { +const init = async () => { + if (!ARGS.web_url) { console.error("Please provide the '--web-url' parameter"); 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)"); return app.quit(); } - const url = new URL(args.web_url); - 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 widget = args.web_widget ? args.web_widget === "true" : true; + const url = new URL(ARGS.web_url); + 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 widget = ARGS.web_widget ? ARGS.web_widget === "true" : true; + const fullscreen = ARGS.app_debug !== "true"; // Init global layout WEBVIEW.viewZoom = zoom; @@ -46,7 +46,10 @@ const init = async (args) => { icon: path.join(__dirname, "..", "img", "icon.png"), }); WEBVIEW.window.setMenuBarVisibility(false); - WEBVIEW.window.setFullScreen(true); + WEBVIEW.window.setFullScreen(fullscreen); + if (!fullscreen) { + WEBVIEW.window.maximize(); + } // Init global webview WEBVIEW.view = new WebContentsView({ @@ -288,7 +291,9 @@ const domEvents = () => { // Webview fully loaded WEBVIEW.view.webContents.on("did-finish-load", () => { - // view.webContents.openDevTools(); + if (ARGS.app_debug === "true") { + WEBVIEW.view.webContents.openDevTools(); + } WEBVIEW.initialized = true; update(); });