ref: code cleanup
This commit is contained in:
@@ -36,8 +36,7 @@ app.whenReady().then(async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show used arguments
|
// Show used arguments
|
||||||
const json = JSON.stringify(args, null, 2);
|
console.log(`Arguments: ${JSON.stringify(args, null, 2)}`);
|
||||||
console.log(`Arguments: ${json}`);
|
|
||||||
|
|
||||||
// Chained init functions
|
// Chained init functions
|
||||||
const chained = [webview.init, hardware.init, integration.init];
|
const chained = [webview.init, hardware.init, integration.init];
|
||||||
|
|||||||
+12
-3
@@ -3,6 +3,7 @@
|
|||||||
# Determine system architecture
|
# Determine system architecture
|
||||||
echo -e "Determining system architecture..."
|
echo -e "Determining system architecture..."
|
||||||
|
|
||||||
|
BITS=$(getconf LONG_BIT)
|
||||||
case "$(uname -m)" in
|
case "$(uname -m)" in
|
||||||
aarch64)
|
aarch64)
|
||||||
ARCH="arm64"
|
ARCH="arm64"
|
||||||
@@ -11,11 +12,17 @@ case "$(uname -m)" in
|
|||||||
ARCH="x64"
|
ARCH="x64"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "System architecture $(uname -m) not supported."
|
echo "Architecture $(uname -m) running $BITS-bit operating system is not supported."
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
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
|
# Download the latest .deb package
|
||||||
echo -e "\nDownloading the latest release..."
|
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 | \
|
DEB_URL=$(wget -qO- https://api.github.com/repos/leukipp/touchkio/releases/latest | \
|
||||||
grep -o "\"browser_download_url\": \"[^\"]*_${ARCH}\.deb\"" | \
|
grep -o "\"browser_download_url\": \"[^\"]*_${ARCH}\.deb\"" | \
|
||||||
sed 's/"browser_download_url": "//;s/"//g')
|
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
|
if [ -z "$DEB_URL" ]; then
|
||||||
echo "Download url for .deb file not found."
|
echo "Download url for .deb file not found."
|
||||||
|
|||||||
+31
-14
@@ -6,6 +6,7 @@ const process = require("child_process");
|
|||||||
global.HARDWARE = global.HARDWARE || {
|
global.HARDWARE = global.HARDWARE || {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
status: "invalid",
|
status: "invalid",
|
||||||
|
session: {},
|
||||||
support: {},
|
support: {},
|
||||||
display: {
|
display: {
|
||||||
status: {
|
status: {
|
||||||
@@ -32,29 +33,29 @@ global.HARDWARE = global.HARDWARE || {
|
|||||||
* @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 (args) => {
|
||||||
if (!args.mqtt_url) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check device support
|
|
||||||
if (!compatibleDevice()) {
|
if (!compatibleDevice()) {
|
||||||
console.warn("Device not supported");
|
console.warn("Device not supported");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init globals
|
// Init globals
|
||||||
HARDWARE.support.session = sessionType();
|
HARDWARE.session.user = sessionUser();
|
||||||
|
HARDWARE.session.type = sessionType();
|
||||||
HARDWARE.display.status.path = getDisplayStatusPath();
|
HARDWARE.display.status.path = getDisplayStatusPath();
|
||||||
HARDWARE.support.displayStatus = HARDWARE.display.status.path !== null;
|
HARDWARE.support.displayStatus = HARDWARE.display.status.path !== null;
|
||||||
HARDWARE.display.brightness.path = getDisplayBrightnessPath();
|
HARDWARE.display.brightness.path = getDisplayBrightnessPath();
|
||||||
HARDWARE.support.displayBrightness = HARDWARE.display.brightness.path !== null;
|
HARDWARE.support.displayBrightness = HARDWARE.display.brightness.path !== null;
|
||||||
HARDWARE.display.brightness.max = getDisplayBrightnessMax();
|
HARDWARE.display.brightness.max = getDisplayBrightnessMax();
|
||||||
|
HARDWARE.support.keyboardVisibility = processRuns("squeekboard");
|
||||||
HARDWARE.initialized = true;
|
HARDWARE.initialized = true;
|
||||||
HARDWARE.status = "valid";
|
HARDWARE.status = "valid";
|
||||||
|
|
||||||
|
// Show supported features
|
||||||
|
console.log(`Supported: ${JSON.stringify(HARDWARE.support, null, 2)}`);
|
||||||
|
|
||||||
// Show session infos
|
// Show session infos
|
||||||
console.log("\nUser:", os.userInfo().username);
|
console.log("\nUser:", HARDWARE.session.user);
|
||||||
console.log("Session:", HARDWARE.support.session);
|
console.log("Session:", HARDWARE.session.type);
|
||||||
|
|
||||||
// Show device infos
|
// Show device infos
|
||||||
console.log("\nModel:", getModel());
|
console.log("\nModel:", getModel());
|
||||||
@@ -73,8 +74,7 @@ const init = async (args) => {
|
|||||||
console.log(`\nDisplay Status [${HARDWARE.display.status.path}]:`, getDisplayStatus());
|
console.log(`\nDisplay Status [${HARDWARE.display.status.path}]:`, getDisplayStatus());
|
||||||
console.log(`Display Brightness [${HARDWARE.display.brightness.path}]:`, getDisplayBrightness(), "\n");
|
console.log(`Display Brightness [${HARDWARE.display.brightness.path}]:`, getDisplayBrightness(), "\n");
|
||||||
|
|
||||||
// Check for keyboard visibility changes
|
// Check for keyboard visibility
|
||||||
HARDWARE.support.keyboardVisibility = processRuns("squeekboard");
|
|
||||||
setKeyboardVisibility("OFF", (reply, error) => {
|
setKeyboardVisibility("OFF", (reply, error) => {
|
||||||
if (!reply || error) {
|
if (!reply || error) {
|
||||||
return;
|
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 = () => {
|
const sessionType = () => {
|
||||||
if (!commandExists("loginctl")) {
|
if (!commandExists("loginctl")) {
|
||||||
@@ -164,7 +176,7 @@ const sessionType = () => {
|
|||||||
* @returns {bool} Returns true if the session matches the type.
|
* @returns {bool} Returns true if the session matches the type.
|
||||||
*/
|
*/
|
||||||
const session = (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");
|
if (typeof callback === "function") callback(null, "Not supported");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (status !== "ON" && status !== "OFF") {
|
if (!["ON", "OFF"].includes(status)) {
|
||||||
console.error("Status must be 'ON' or 'OFF'");
|
console.error("Status must be 'ON' or 'OFF'");
|
||||||
if (typeof callback === "function") callback(null, "Invalid status");
|
if (typeof callback === "function") callback(null, "Invalid status");
|
||||||
return;
|
return;
|
||||||
@@ -464,6 +476,11 @@ const setKeyboardVisibility = (visibility, callback = null) => {
|
|||||||
if (typeof callback === "function") callback(null, "Not supported");
|
if (typeof callback === "function") callback(null, "Not supported");
|
||||||
return;
|
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";
|
const visible = visibility === "ON";
|
||||||
HARDWARE.keyboard.visibility = visible;
|
HARDWARE.keyboard.visibility = visible;
|
||||||
dbusCall("/sm/puri/OSK0", "SetVisible", [`boolean:${visible}`], callback);
|
dbusCall("/sm/puri/OSK0", "SetVisible", [`boolean:${visible}`], callback);
|
||||||
|
|||||||
+5
-1
@@ -17,6 +17,10 @@ const init = async (args) => {
|
|||||||
if (!args.mqtt_url) {
|
if (!args.mqtt_url) {
|
||||||
return false;
|
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 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;
|
||||||
@@ -347,7 +351,7 @@ const initKeyboard = (client) => {
|
|||||||
unique_id: `${INTEGRATION.node}_keyboard`,
|
unique_id: `${INTEGRATION.node}_keyboard`,
|
||||||
command_topic: `${root}/set`,
|
command_topic: `${root}/set`,
|
||||||
state_topic: `${root}/status`,
|
state_topic: `${root}/status`,
|
||||||
icon: "mdi:keyboard-close",
|
icon: "mdi:keyboard-close-outline",
|
||||||
device: INTEGRATION.device,
|
device: INTEGRATION.device,
|
||||||
};
|
};
|
||||||
client
|
client
|
||||||
|
|||||||
Reference in New Issue
Block a user