ref: add debug arguments
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -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;
|
||||
|
||||
+7
-8
@@ -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();
|
||||
|
||||
+15
-10
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user