diff --git a/index.js b/index.js index 579a738..964c304 100644 --- a/index.js +++ b/index.js @@ -36,8 +36,7 @@ app.whenReady().then(async () => { } // Show used arguments - const json = JSON.stringify(args, null, 2); - console.log(`Arguments: ${json}`); + console.log(`Arguments: ${JSON.stringify(args, null, 2)}`); // Chained init functions const chained = [webview.init, hardware.init, integration.init]; diff --git a/install.sh b/install.sh index fc86d9c..58e0dde 100755 --- a/install.sh +++ b/install.sh @@ -3,6 +3,7 @@ # Determine system architecture echo -e "Determining system architecture..." +BITS=$(getconf LONG_BIT) case "$(uname -m)" in aarch64) ARCH="arm64" @@ -11,11 +12,17 @@ case "$(uname -m)" in ARCH="x64" ;; *) - echo "System architecture $(uname -m) not supported." + echo "Architecture $(uname -m) running $BITS-bit operating system is not supported." exit 1 ;; esac -echo "System architecture $ARCH is supported." + +if [ "$BITS" -ne 64 ]; then + echo "Architecture $ARCH running $BITS-bit operating system is not supported." + exit 1 +fi + +echo "Architecture $ARCH running $BITS-bit operating system is supported." # Download the latest .deb package echo -e "\nDownloading the latest release..." @@ -23,7 +30,9 @@ echo -e "\nDownloading the latest release..." DEB_URL=$(wget -qO- https://api.github.com/repos/leukipp/touchkio/releases/latest | \ grep -o "\"browser_download_url\": \"[^\"]*_${ARCH}\.deb\"" | \ sed 's/"browser_download_url": "//;s/"//g') -DEB_PATH="/tmp/$(basename "$DEB_URL")" + +TMP_DIR=$(mktemp -d) +DEB_PATH="${TMP_DIR}/$(basename "$DEB_URL")" if [ -z "$DEB_URL" ]; then echo "Download url for .deb file not found." diff --git a/src/hardware.js b/src/hardware.js index 3bcef1a..0d4a147 100644 --- a/src/hardware.js +++ b/src/hardware.js @@ -6,6 +6,7 @@ const process = require("child_process"); global.HARDWARE = global.HARDWARE || { initialized: false, status: "invalid", + session: {}, support: {}, display: { status: { @@ -32,29 +33,29 @@ global.HARDWARE = global.HARDWARE || { * @returns {boolean} Returns true if the initialization was successful. */ const init = async (args) => { - if (!args.mqtt_url) { - return false; - } - - // Check device support if (!compatibleDevice()) { console.warn("Device not supported"); return false; } // Init globals - HARDWARE.support.session = sessionType(); + HARDWARE.session.user = sessionUser(); + HARDWARE.session.type = sessionType(); HARDWARE.display.status.path = getDisplayStatusPath(); HARDWARE.support.displayStatus = HARDWARE.display.status.path !== null; HARDWARE.display.brightness.path = getDisplayBrightnessPath(); HARDWARE.support.displayBrightness = HARDWARE.display.brightness.path !== null; HARDWARE.display.brightness.max = getDisplayBrightnessMax(); + HARDWARE.support.keyboardVisibility = processRuns("squeekboard"); HARDWARE.initialized = true; HARDWARE.status = "valid"; + // Show supported features + console.log(`Supported: ${JSON.stringify(HARDWARE.support, null, 2)}`); + // Show session infos - console.log("\nUser:", os.userInfo().username); - console.log("Session:", HARDWARE.support.session); + console.log("\nUser:", HARDWARE.session.user); + console.log("Session:", HARDWARE.session.type); // Show device infos console.log("\nModel:", getModel()); @@ -73,8 +74,7 @@ const init = async (args) => { console.log(`\nDisplay Status [${HARDWARE.display.status.path}]:`, getDisplayStatus()); console.log(`Display Brightness [${HARDWARE.display.brightness.path}]:`, getDisplayBrightness(), "\n"); - // Check for keyboard visibility changes - HARDWARE.support.keyboardVisibility = processRuns("squeekboard"); + // Check for keyboard visibility setKeyboardVisibility("OFF", (reply, error) => { if (!reply || error) { return; @@ -143,9 +143,21 @@ const compatibleDevice = () => { }; /** - * Queries the session type for the logged in user. + * Gets the session user name using `os.userInfo()`. * - * @returns {string} Returns session type 'x11'/'wayland' or null if an error occurs. + * @returns {string|null} Returns session user name or null if an error occurs. + */ +const sessionUser = () => { + try { + return os.userInfo().username; + } catch {} + return null; +}; + +/** + * Gets the session type for the user using `loginctl`. + * + * @returns {string|null} Returns session type 'x11'/'wayland' or null if an error occurs. */ const sessionType = () => { if (!commandExists("loginctl")) { @@ -164,7 +176,7 @@ const sessionType = () => { * @returns {bool} Returns true if the session matches the type. */ const session = (type) => { - return HARDWARE.support.session == type; + return HARDWARE.session.type == type; }; /** @@ -350,7 +362,7 @@ const setDisplayStatus = (status, callback = null) => { if (typeof callback === "function") callback(null, "Not supported"); return; } - if (status !== "ON" && status !== "OFF") { + if (!["ON", "OFF"].includes(status)) { console.error("Status must be 'ON' or 'OFF'"); if (typeof callback === "function") callback(null, "Invalid status"); return; @@ -464,6 +476,11 @@ const setKeyboardVisibility = (visibility, callback = null) => { if (typeof callback === "function") callback(null, "Not supported"); return; } + if (!["ON", "OFF"].includes(visibility)) { + console.error("Visibility must be 'ON' or 'OFF'"); + if (typeof callback === "function") callback(null, "Invalid visibility"); + return; + } const visible = visibility === "ON"; HARDWARE.keyboard.visibility = visible; dbusCall("/sm/puri/OSK0", "SetVisible", [`boolean:${visible}`], callback); diff --git a/src/integration.js b/src/integration.js index 0af36b1..43173fa 100644 --- a/src/integration.js +++ b/src/integration.js @@ -17,6 +17,10 @@ const init = async (args) => { if (!args.mqtt_url) { return false; } + 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; @@ -347,7 +351,7 @@ const initKeyboard = (client) => { unique_id: `${INTEGRATION.node}_keyboard`, command_topic: `${root}/set`, state_topic: `${root}/status`, - icon: "mdi:keyboard-close", + icon: "mdi:keyboard-close-outline", device: INTEGRATION.device, }; client