12 Commits
Author SHA1 Message Date
leukipp 19348b4b60 build: disable zip update 2025-09-06 20:27:01 +02:00
leukipp ce1eed391d build: update version 2025-09-06 20:08:16 +02:00
leukipp fe6fe92656 docs: update readme 2025-09-06 20:07:41 +02:00
leukipp 3aea938cfb fix: validate arguments file #69 2025-09-06 20:03:49 +02:00
leukipp c39428fa42 build: update build.json 2025-09-06 19:48:02 +02:00
leukipp 7caa5bfc8a ref: update images 2025-09-06 19:22:19 +02:00
leukipp 5f69961a9f feat: mqtt app update #70 2025-09-06 19:21:51 +02:00
leukipp f44d998016 build: improve update logic 2025-09-06 19:07:57 +02:00
leukipp 3ea65a4af8 build: update dependencies 2025-09-06 19:04:16 +02:00
leukipp 2ad49c3167 feat: add network address mqtt sensor #66 2025-09-03 22:13:45 +02:00
leukipp ef2093a25e feat: check sudo rights for mqtt #62 2025-09-03 16:01:47 +02:00
leukipp 2737eabd8a fix: mqtt keyboard state #65 2025-09-01 17:22:26 +02:00
11 changed files with 639 additions and 232 deletions
+1
View File
@@ -1,3 +1,4 @@
node_modules/
docs/
out/
build.json
+23 -13
View File
@@ -43,7 +43,7 @@ For a comprehensive guide on setting up MQTT with Home Assistant, please refer t
## Installation
On the first run of the application, you may encounter a **setup procedure** and the Home Assistant **login screen**.
It's recommended to create a **dedicated user** (local access only) for your kiosk device.
It's recommended to create a dedicated Home Assistant user (local access only) for your kiosk device.
You might also need a physical keyboard or remote VNC access to input these credentials once.
If your hardware is [supported](https://github.com/leukipp/touchkio/blob/main/HARDWARE.md) you may be able to activate the on-screen keyboard using the side [widget](https://github.com/leukipp/touchkio/issues/16).
@@ -56,7 +56,6 @@ bash <(wget -qO- https://raw.githubusercontent.com/leukipp/touchkio/main/install
```
Make sure that you run this with your **standard user** and not with root (sudo).
If you are paranoid, or smart, or both, have a look into the [install.sh](https://github.com/leukipp/touchkio/blob/main/install.sh) script before executing external code on your machine.
This command can also be re-run to **update** an existing installation to the latest version.
The systemd **user service** is enabled by default and the kiosk application should start automatically the next time you boot.
If you need manual control use:
@@ -89,6 +88,14 @@ yarn build
</div></details>
#### Update
If you have already installed TouchKio and want to upgrade to the latest version, simply install the newer version over the existing one.
The [install.sh](https://github.com/leukipp/touchkio/blob/main/install.sh) script can also be run to update an existing installation to the **latest version**. The setup procedure can be skipped to use the existing default arguments from the configuration file:
```bash
bash <(wget -qO- https://raw.githubusercontent.com/leukipp/touchkio/main/install.sh) update
```
## Configuration
Running `touchkio --setup` will prompt you to enter arguments that will be used when the application starts without any specified arguments.
These default arguments are stored in `~/.config/touchkio/Arguments.json`, where they can also be modified.
@@ -143,7 +150,7 @@ touchkio --web-url=http://192.168.1.42:8123 --mqtt-url=mqtt://192.168.1.42:1883
## User Interface
TouchKio provides a simple webview window designed specifically for Touch Displays. Electron apps are known to be resource intensive due to their architecture and the inclusion of a full web browser environment. If you just run the kiosk application without other heavy loads, everything should run smoothly.
### Controls
### Touch Controls
Additional controls can be found along the right edge of the kiosk application. For more details, you may want to have a closer look here:
| Name | Description |
| ------------ | -------------------------------------------------------- |
@@ -154,14 +161,14 @@ Additional controls can be found along the right edge of the kiosk application.
### Keyboard Shortcuts
The application also supports basic shortcuts to enhance navigation and usability for users who prefer or require non-touch input methods:
| Name | Description |
| --------------------------- | --------------------------- |
| `Control+Left` | Navigate to previous page |
| `Control+Right` | Navigate to next page |
| `Control+Num_Subtract` | Decrease the page zoom |
| `Control+Num_Add` | Increase the page zoom |
| `Alt+Left`/`Mouse+Back` | Navigate back in history |
| `Alt+Right`/`Mouse+Forward` | Navigate forward in history |
| Name | Description |
| --------------------------- | ---------------------------- |
| `Control+Left` | Navigate to previous page |
| `Control+Right` | Navigate to next page |
| `Control+Num_Subtract` | Decrease the page zoom |
| `Control+Num_Add` | Increase the page zoom |
| `Alt+Left`/`Mouse+Back` | Navigate backward in history |
| `Alt+Right`/`Mouse+Forward` | Navigate forward in history |
## Development
To create your own local build, you first need to install [Node.js](https://pimylifeup.com/raspberry-pi-nodejs) and [Yarn](https://classic.yarnpkg.com/lang/en/docs/install).
@@ -268,13 +275,16 @@ Please have a look into the [hardware](https://github.com/leukipp/touchkio/blob/
**Known Issues** that are by-design or for which there isn't a solution so far:
- You can use Raspberry Pi's build-in [screen blanking](https://www.raspberrypi.com/documentation/computers/configuration.html#screen-blanking-3) functionality, however, if the screen is turned on through Home Assistant after being automatically turned off, it will remain on indefinitely.
- It's recommended to either use the built-in screen blanking feature or implement a Home Assistant automation (e.g. presence detection) to manage the screen status.
- When using a Raspberry Pi, the on-screen keyboard doesn't automatically pop-out when entering a text field inside the webview.
- As a current [workaround](https://github.com/leukipp/touchkio/issues/4) you can use the side [widget](https://github.com/leukipp/touchkio/issues/16) to toggle the keyboard visibility.
- When using a Raspberry Pi, the on-screen keyboard doesn't [automatically pop-out](https://github.com/leukipp/touchkio/issues/4) when entering a text field inside the webview.
- As a current workaround you can use the side [widget](https://github.com/leukipp/touchkio/issues/16) to toggle the keyboard visibility.
- Certain commands from the MQTT integration may require elevated privileges to work correctly.
- Ensure that your local user has the [necessary permissions](https://github.com/leukipp/touchkio/issues/39) to run `sudo` without being prompted for a password.
- On the terminal you may see some *ERROR:gbm_wrapper.cc* messages.
- This appears to be a [known issue](https://github.com/electron/electron/issues/42322) that currently lacks a fix, but the webview still works.
For debugging, stop the service and run `touchkio` directly on the terminal to view the log outputs.
If you encounter any problems, please [create an issue](https://github.com/leukipp/touchkio/issues) and include the output of `touchkio --version` along with your system setup and any additional terminal logs.
## Credits
Thanks to Sebastian ([@pdsccode](https://github.com/pdsccode)) for his contributions on issues and [community](https://community.home-assistant.io/t/kiosk-mode-for-raspberry-pi-with-touch-display/821196) discussions.
+35 -2
View File
@@ -1,4 +1,22 @@
const fs = require("fs");
const jszip = require("jszip");
const crypto = require("crypto");
const path = require("path");
const date = new Date().toISOString();
const generateBuildFile = (platform, arch, maker) => {
const package = fs.readFileSync(path.join(__dirname, "package.json"), "utf8");
const hash = crypto.createHash("sha256").update(package);
const data = {
id: hash.digest("hex").slice(-6),
platform: platform,
arch: arch,
maker: maker,
date: date,
};
return JSON.stringify(data, null, 2);
};
module.exports = {
packagerConfig: {
@@ -33,10 +51,25 @@ module.exports = {
},
],
hooks: {
postPackage: async (config, results) => {
for (const outputPath of results.outputPaths) {
const [name, platform, arch] = path.basename(outputPath).split("-");
const buildFile = path.join(outputPath, "resources", "app", "build.json");
fs.writeFileSync(buildFile, generateBuildFile(platform, arch, "deb"), { encoding: "utf8" });
}
},
postMake: async (config, results) => {
for (const result of results) {
const artifacts = [];
result.artifacts.forEach((artifact) => {
for (const artifact of result.artifacts) {
// Currently disabled for zip files as it seems to corrupt them
if (artifact.includes(".zip") && false) {
const [name, platform, arch] = path.basename(artifact).split("-");
const buildFile = path.join(`${name}-${platform}-${arch}`, "resources", "app", "build.json");
const zip = await jszip.loadAsync(fs.readFileSync(artifact, "utf8"));
zip.file(buildFile, generateBuildFile(platform, arch, "zip"));
fs.writeFileSync(artifact, await zip.generateAsync({ type: "nodebuffer" }));
}
if (artifact.includes("amd64")) {
const renamed = artifact.replace("amd64", "x64");
fs.renameSync(artifact, renamed);
@@ -44,7 +77,7 @@ module.exports = {
} else {
artifacts.push(artifact);
}
});
}
result.artifacts = artifacts;
}
},
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 78 KiB

+131 -52
View File
@@ -7,6 +7,7 @@ const hardware = require("./js/hardware");
const webview = require("./js/webview");
const { app } = require("electron");
global.APP = global.APP || {};
global.ARGS = global.ARGS || {};
if (!process.env.DISPLAY) {
@@ -23,20 +24,85 @@ if (!process.env.DISPLAY) {
* initialization tasks.
*/
app.whenReady().then(async () => {
const lock = app.requestSingleInstanceLock();
if (!lock) {
console.error("TouchKio is already running");
if (!(await initApp()) || !(await initArgs())) {
return;
}
// Show used arguments
console.log(`Arguments: ${JSON.stringify(ARGS, null, 2)}`);
// Chained init functions
const chained = [webview.init, hardware.init, integration.init];
for (const init of chained) {
if (!(await init())) {
break;
}
}
});
/**
* Initializes the global app object.
*
* @returns {bool} Returns true if the initialization was successful.
*/
const initApp = async () => {
const packageJsonPath = path.join(app.getAppPath(), "package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
const buildJsonPath = path.join(app.getAppPath(), "build.json");
const buildFileExists = fs.existsSync(buildJsonPath);
// Set required app infos
APP.name = app.getName();
APP.title = packageJson.title;
APP.version = app.getVersion();
APP.path = app.getAppPath();
APP.config = app.getPath("userData");
// Set additional update infos
APP.homepage = `https://github.com/${packageJson.author}/${packageJson.name}`;
APP.releases = {
url: `https://api.github.com/repos/${packageJson.author}/${packageJson.name}/releases`,
latest: null,
};
APP.scripts = {
install: `https://raw.githubusercontent.com/${packageJson.author}/${packageJson.name}/main/install.sh`,
};
// Set additional build infos
APP.build = {};
if (buildFileExists) {
APP.build = JSON.parse(fs.readFileSync(buildJsonPath, "utf8"));
}
// Request single app instance lock
if (!app.requestSingleInstanceLock()) {
console.error(`${APP.title} is already running`);
return app.quit();
}
return true;
};
/**
* Initializes the global args object.
*
* @returns {bool} Returns true if the initialization was successful.
*/
const initArgs = async () => {
let args = parseArgs(process);
let argsProvided = !!Object.keys(args).length;
let argsFilePath = path.join(app.getPath("userData"), "Arguments.json");
let argsFilePath = path.join(APP.config, "Arguments.json");
let argsFileExists = fs.existsSync(argsFilePath);
// Show version and release info
if ("help" in args || "version" in args) {
console.log(`${app.getName()}-v${app.getVersion()}, https://github.com/leukipp/touchkio`);
let build = "";
if (APP.build.id) {
build = ` (${APP.build.id}), built on ${APP.build.date} (${APP.build.platform}-${APP.build.arch}-${APP.build.maker})`;
}
console.log(`${APP.name}-v${APP.version}${build}\n${APP.homepage}`);
return app.quit();
}
@@ -51,24 +117,21 @@ app.whenReady().then(async () => {
args = readArgs(argsFilePath);
}
// Check arguments object
if (!Object.keys(args).length) {
console.error(`No arguments provided`);
return app.quit();
}
// Split url arguments
args.web_url = args.web_url || [];
if (!Array.isArray(args.web_url)) {
args.web_url = args.web_url.split(",").map((url) => url.trim());
}
global.ARGS = args;
ARGS = args;
// Show used arguments
console.log(`Arguments: ${JSON.stringify(global.ARGS, null, 2)}\n`);
// Chained init functions
const chained = [webview.init, hardware.init, integration.init];
for (const init of chained) {
if (!(await init())) {
break;
}
}
});
return true;
};
/**
* Parses command-line arguments from the given process object.
@@ -155,34 +218,41 @@ const promptArgs = async (proc) => {
// Prompt questions and wait for the answers
let args = {};
let ignore = [];
for (const { key, question, fallback } of prompts) {
if (key === "mqtt") {
const prompt = `${question} (${fallback}): `;
const answer = await read.question(prompt);
const value = (answer.trim() || fallback.match(/[YN]/)[0]).toLowerCase();
if (!["y", "yes"].includes(value)) {
ignore = ignore.concat(["mqtt_url", "mqtt_user", "mqtt_password", "mqtt_discovery"]);
}
} else if (key === "check") {
const json = JSON.stringify(args, null, 2);
const prompt = `${question}\n${json}\n(${fallback}): `;
const answer = await read.question(prompt);
const value = (answer.trim() || fallback.match(/[YN]/)[0]).toLowerCase();
if (!["y", "yes"].includes(value)) {
args = {};
}
} else if (!ignore.includes(key)) {
const prompt = `${question} (${fallback}): `;
const answer = await read.question(prompt);
const value = answer.trim() || fallback;
if (key === "web_url") {
args[key] = value.split(",").map((v) => v.trim());
} else {
args[key] = value;
try {
for (const { key, question, fallback } of prompts) {
if (key === "mqtt") {
const prompt = `${question} (${fallback}): `;
const answer = await read.question(prompt);
const value = (answer.trim() || fallback.match(/[YN]/)[0]).toLowerCase();
if (!["y", "yes"].includes(value)) {
ignore = ignore.concat(["mqtt_url", "mqtt_user", "mqtt_password", "mqtt_discovery"]);
}
} else if (key === "check") {
const json = JSON.stringify(args, null, 2);
const prompt = `${question}\n${json}\n(${fallback}): `;
const answer = await read.question(prompt);
const value = (answer.trim() || fallback.match(/[YN]/)[0]).toLowerCase();
if (!["y", "yes"].includes(value)) {
args = {};
}
} else if (!ignore.includes(key)) {
const prompt = `${question} (${fallback}): `;
const answer = await read.question(prompt);
const value = answer.trim() || fallback;
if (key === "web_url") {
args[key] = value.split(",").map((v) => v.trim());
} else {
args[key] = value;
}
}
}
} catch (error) {
console.error(`\n${error.message}`);
args = {};
app.quit();
} finally {
read.close();
}
read.close();
return args;
};
@@ -194,11 +264,15 @@ const promptArgs = async (proc) => {
* @param {Object} args - The arguments object.
*/
const writeArgs = (path, args) => {
const argc = Object.assign({}, args);
if ("mqtt_password" in argc) {
argc.mqtt_password = encrypt(argc.mqtt_password);
try {
const argc = Object.assign({}, args);
if ("mqtt_password" in argc) {
argc.mqtt_password = encrypt(argc.mqtt_password);
}
fs.writeFileSync(path, JSON.stringify(argc, null, 2));
} catch (error) {
console.error(`Failed to write ${path}:`, error.message);
}
fs.writeFileSync(path, JSON.stringify(argc, null, 2));
};
/**
@@ -208,11 +282,16 @@ const writeArgs = (path, args) => {
* @returns {Object} The arguments object.
*/
const readArgs = (path) => {
const args = JSON.parse(fs.readFileSync(path));
if ("mqtt_password" in args) {
args.mqtt_password = decrypt(args.mqtt_password);
try {
const args = JSON.parse(fs.readFileSync(path, "utf8"));
if ("mqtt_password" in args) {
args.mqtt_password = decrypt(args.mqtt_password);
}
return args;
} catch (error) {
console.error(`Failed to parse ${path}:`, error.message);
}
return args;
return {};
};
/**
@@ -223,7 +302,7 @@ const readArgs = (path) => {
*/
const encrypt = (value) => {
const iv = crypto.randomBytes(16);
const key = crypto.scryptSync(hardware.getMachineId(), app.getName(), 32);
const key = crypto.scryptSync(hardware.getMachineId(), APP.name, 32);
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
let encrypted = cipher.update(value, "utf8", "hex");
encrypted += cipher.final("hex");
@@ -239,7 +318,7 @@ const encrypt = (value) => {
const decrypt = (value) => {
const p = Buffer.from(value, "base64").toString("utf8").split(":");
const iv = Buffer.from(p.shift(), "hex");
const key = crypto.scryptSync(hardware.getMachineId(), app.getName(), 32);
const key = crypto.scryptSync(hardware.getMachineId(), APP.name, 32);
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
const buffer = Buffer.from(p.join(":"), "hex");
let decrypted = decipher.update(buffer, "binary", "utf8");
+43 -41
View File
@@ -1,5 +1,13 @@
#!/usr/bin/env bash
# Read arguments
ARG_UPDATE=false
for arg in "$@"; do
if [ "$arg" = "update" ]; then
ARG_UPDATE=true
fi
done
# Determine system architecture
echo -e "Determining system architecture..."
@@ -12,57 +20,39 @@ case "$(uname -m)" in
ARCH="x64"
;;
*)
echo "Architecture $(uname -m) running $BITS-bit operating system is not supported."
exit 1
{ echo "Architecture $(uname -m) running $BITS-bit operating system is not supported."; exit 1; }
;;
esac
if [ "$BITS" -ne 64 ]; then
echo "Architecture $ARCH running $BITS-bit operating system is not supported."
exit 1
fi
[ "$BITS" -eq 64 ] || { echo "Architecture $ARCH running $BITS-bit operating system is not supported."; exit 1; }
echo "Architecture $ARCH running $BITS-bit operating system is supported."
# Download the latest .deb package
echo -e "\nDownloading the latest release..."
TMP_DIR=$(mktemp -d)
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')
TMP_DIR=$(mktemp -d)
DEB_PATH="${TMP_DIR}/$(basename "$DEB_URL")"
chmod 755 "$TMP_DIR"
if [ -z "$DEB_URL" ]; then
echo "Download url for .deb file not found."
exit 1
fi
if ! wget --show-progress -q -O "$DEB_PATH" "$DEB_URL"; then
echo "Failed to download the .deb file."
exit 1
fi
[ -z "$DEB_URL" ] && { echo "Download url for .deb file not found."; exit 1; }
wget --show-progress -q -O "$DEB_PATH" "$DEB_URL" || { echo "Failed to download the .deb file."; exit 1; }
# Install the latest .deb package
echo -e "\nInstalling the latest release..."
if ! command -v apt &> /dev/null; then
echo "Package manager apt was not found."
exit 1
fi
if ! sudo apt install "$DEB_PATH"; then
echo "Installation of .deb file failed."
exit 1
fi
command -v apt &> /dev/null || { echo "Package manager apt was not found."; exit 1; }
sudo apt install -y "$DEB_PATH" || { echo "Installation of .deb file failed."; exit 1; }
# Create the systemd user service
echo -e "\nCreating systemd user service..."
SERVICE_FILE="$HOME/.config/systemd/user/touchkio.service"
mkdir -p "$(dirname "$SERVICE_FILE")" || { echo "Failed to create directory for $SERVICE_FILE"; exit 1; }
SERVICE_NAME="touchkio.service"
SERVICE_FILE="$HOME/.config/systemd/user/$SERVICE_NAME"
mkdir -p "$(dirname "$SERVICE_FILE")" || { echo "Failed to create directory for $SERVICE_FILE."; exit 1; }
SERVICE_CONTENT="[Unit]
Description=TouchKio
After=graphical.target
@@ -76,20 +66,28 @@ RestartSec=5s
[Install]
WantedBy=default.target"
if $ARG_UPDATE; then
if systemctl --user --quiet is-active "${SERVICE_NAME}"; then
systemctl --user restart "${SERVICE_NAME}"
echo "Existing $SERVICE_NAME restarted."
else
echo "Existing $SERVICE_NAME not running, start touchkio manually."
fi
exit 0
fi
SERVICE_CREATE=true
if [ -f "$SERVICE_FILE" ]; then
read -p "Service $SERVICE_FILE exists, overwrite? (y/N) " overwrite
if [[ ! ${overwrite:-n} == [Yy]* ]]; then
SERVICE_CREATE=false
fi
[[ ${overwrite:-n} == [Yy]* ]] || SERVICE_CREATE=false
fi
if [ "$SERVICE_CREATE" = true ]; then
echo "$SERVICE_CONTENT" > "$SERVICE_FILE" || { echo "Failed to write to $SERVICE_FILE"; exit 1; }
systemctl --user enable "$(basename "$SERVICE_FILE")" || { echo "Failed to enable service $SERVICE_FILE"; exit 1; }
echo "Service $SERVICE_FILE enabled"
if $SERVICE_CREATE; then
echo "$SERVICE_CONTENT" > "$SERVICE_FILE" || { echo "Failed to write to $SERVICE_FILE."; exit 1; }
systemctl --user enable "$(basename "$SERVICE_FILE")" || { echo "Failed to enable service $SERVICE_FILE."; exit 1; }
echo "Service $SERVICE_FILE enabled."
else
echo "Service $SERVICE_FILE not created"
echo "Service $SERVICE_FILE not created."
fi
# Export display variables
@@ -97,20 +95,22 @@ echo -e "\nExporting display variables..."
if [ -z "$DISPLAY" ]; then
export DISPLAY=":0"
echo "DISPLAY was not set, defaulting to \"$DISPLAY\""
echo "DISPLAY was not set, defaulting to \"$DISPLAY\"."
else
echo "DISPLAY is set to \"$DISPLAY\""
echo "DISPLAY is set to \"$DISPLAY\"."
fi
if [ -z "$WAYLAND_DISPLAY" ]; then
export WAYLAND_DISPLAY="wayland-0"
echo "WAYLAND_DISPLAY was not set, defaulting to \"$WAYLAND_DISPLAY\""
echo "WAYLAND_DISPLAY was not set, defaulting to \"$WAYLAND_DISPLAY\"."
else
echo "WAYLAND_DISPLAY is set to \"$WAYLAND_DISPLAY\""
echo "WAYLAND_DISPLAY is set to \"$WAYLAND_DISPLAY\"."
fi
# Start the setup mode
echo ""
read -p "Start touchkio setup? (Y/n) " setup
if [[ ${setup:-y} == [Yy]* ]]; then
echo "/usr/bin/touchkio --setup"
/usr/bin/touchkio --setup
@@ -118,3 +118,5 @@ else
echo "/usr/bin/touchkio"
/usr/bin/touchkio
fi
exit 0
+145 -53
View File
@@ -42,10 +42,6 @@ const init = async () => {
console.warn("Operating system is not supported\n");
return false;
}
if (!sessionRights()) {
console.warn(`User "${sessionUser()}" is missing password-less sudo rights\n`);
return false;
}
// Init globals
HARDWARE.session.user = sessionUser();
@@ -60,7 +56,7 @@ const init = async () => {
HARDWARE.initialized = true;
// Show supported features
console.log(`Supported: ${JSON.stringify(HARDWARE.support, null, 2)}`);
console.log(`\nSupported: ${JSON.stringify(HARDWARE.support, null, 2)}`);
// Show session infos
console.log("\nUser:", HARDWARE.session.user);
@@ -71,6 +67,7 @@ const init = async () => {
console.log("\nModel:", getModel());
console.log("Vendor:", getVendor());
console.log("Serial Number:", getSerialNumber());
console.log("Network Addresses:", getNetworkAddresses());
console.log("Host Name:", getHostName());
// Show system infos
@@ -161,19 +158,6 @@ const compatibleSystem = () => {
return paths.every((path) => fs.existsSync(path));
};
/**
* Verifies user rights to run sudo commands without a password.
*
* @returns {bool} Returns true if password-less sudo rights exists.
*/
const sessionRights = () => {
if (!commandExists("sudo")) {
return false;
}
const result = execSyncCommand("sudo", ["-n", "true"]);
return result !== null && !result.includes("password is required");
};
/**
* Gets the session user name using `os.userInfo()`.
*
@@ -214,7 +198,7 @@ const sessionDesktop = () => {
};
/**
* Checks supported features based on global properties.
* Checks supported features based on hardware and software.
*
* @returns {Object} Returns support object with boolean values.
*/
@@ -223,11 +207,16 @@ const checkSupport = () => {
const status = HARDWARE.display.status;
const brightness = HARDWARE.display.brightness;
const keyboard = processRuns("squeekboard");
const service = serviceRuns(APP.name);
const sudo = sudoRights();
const deb = APP.build.maker === "deb";
return {
batteryLevel: battery.path !== null,
displayStatus: status.path !== null && status.command !== null,
displayBrightness: brightness.path !== null && brightness.max !== null,
keyboardVisibility: keyboard === true,
batteryLevel: !!battery.path,
displayStatus: !!status.path && !!status.command,
displayBrightness: sudo && !!brightness.path && !!brightness.max,
keyboardVisibility: keyboard,
sudoRights: sudo,
appUpdate: sudo && service && deb,
};
};
@@ -240,7 +229,7 @@ const getModel = () => {
const paths = ["/sys/firmware/devicetree/base/model", "/sys/class/dmi/id/product_name"];
for (const path of paths) {
if (fs.existsSync(path)) {
return execSyncCommand("sudo", ["cat", path]) || "Generic";
return execSyncCommand("cat", [path]) || "Generic";
}
}
return "Generic";
@@ -255,7 +244,7 @@ const getVendor = () => {
const paths = ["/sys/class/dmi/id/board_vendor"];
for (const path of paths) {
if (fs.existsSync(path)) {
return execSyncCommand("sudo", ["cat", path]) || "Generic";
return execSyncCommand("cat", [path]) || "Generic";
}
}
const model = getModel();
@@ -266,22 +255,22 @@ const getVendor = () => {
};
/**
* Gets the serial number using `/sys/firmware/devicetree/base/serial-number` or `/sys/class/dmi/id/product_serial`.
* Gets the serial number using `/sys/firmware/devicetree/base/serial-number`.
*
* @returns {string} The serial number of the device or '123456' if not found.
* @returns {string} The serial number or machine id parts of the device or '123456' if not found.
*/
const getSerialNumber = () => {
const paths = ["/sys/firmware/devicetree/base/serial-number", "/sys/class/dmi/id/product_serial"];
const paths = ["/sys/firmware/devicetree/base/serial-number"];
for (const path of paths) {
if (fs.existsSync(path)) {
return execSyncCommand("sudo", ["cat", path]) || "123456";
return execSyncCommand("cat", [path]) || "123456";
}
}
return "123456";
return getMachineId().slice(-6);
};
/**
* Gets the host machine id using `/etc/machine-id`.
* Gets the machine id using `/etc/machine-id`.
*
* @returns {string} The machine id of the system or '123456' if not found.
*/
@@ -289,12 +278,38 @@ const getMachineId = () => {
const paths = ["/etc/machine-id"];
for (const path of paths) {
if (fs.existsSync(path)) {
return execSyncCommand("sudo", ["cat", path]) || "123456";
return execSyncCommand("cat", [path]) || "123456";
}
}
return "123456";
};
/**
* Gets the network interfaces addresses using `os.networkInterfaces()`.
*
* @returns {Object} The network addresses of all interfaces.
*/
const getNetworkAddresses = () => {
const addresses = {};
for (const [key, interfaces] of Object.entries(os.networkInterfaces())) {
for (const interface of interfaces) {
if (interface.internal || !interface.family || !interface.address) {
continue;
}
const name = key.charAt(0).toUpperCase() + key.slice(1);
if (!addresses[name]) {
addresses[name] = {};
}
const family = interface.family;
if (!addresses[name][family]) {
addresses[name][family] = [];
}
addresses[name][family].push(interface.address);
}
}
return addresses;
};
/**
* Gets the host name of the current system using `os.hostname()`.
*
@@ -451,22 +466,22 @@ const getDisplayStatus = () => {
case "wlopm":
const wlopm = execSyncCommand("wlopm", []);
if (wlopm !== null) {
const out = wlopm.split("\n")[0].split(" ");
return out.pop().toUpperCase();
const output = wlopm.split("\n")[0].split(" ");
return output.pop().toUpperCase();
}
break;
case "kscreen-doctor":
const kdoc = execSyncCommand("kscreen-doctor", ["--dpms", "show"]);
if (kdoc !== null) {
const out = kdoc.split("\n")[0].split(" ");
return out.pop().toUpperCase();
const output = kdoc.split("\n")[0].split(" ");
return output.pop().toUpperCase();
}
break;
case "xset":
const xset = execSyncCommand("xset", ["-q"]);
if (xset !== null) {
const on = /Monitor is On/.test(xset);
return on ? "ON" : "OFF";
const output = /Monitor is On/.test(xset);
return output ? "ON" : "OFF";
}
break;
}
@@ -641,6 +656,10 @@ const checkPackageUpgrades = () => {
* @param {Function} callback - A callback function that receives the output or error.
*/
const shutdownSystem = (callback = null) => {
if (!HARDWARE.support.sudoRights) {
if (typeof callback === "function") callback(null, "Not supported");
return;
}
execAsyncCommand("sudo", ["shutdown", "-h", "now"], callback);
};
@@ -653,9 +672,39 @@ const shutdownSystem = (callback = null) => {
* @param {Function} callback - A callback function that receives the output or error.
*/
const rebootSystem = (callback = null) => {
if (!HARDWARE.support.sudoRights) {
if (typeof callback === "function") callback(null, "Not supported");
return;
}
execAsyncCommand("sudo", ["reboot"], callback);
};
/**
* Checks if sudo commands can run without a password.
*
* @returns {bool} Returns true if password-less sudo rights exists.
*/
const sudoRights = () => {
try {
const output = cpr.execSync(`sudo -n true`, { encoding: "utf8" });
return output !== null && !output.includes("password is required");
} catch {}
return false;
};
/**
* Checks if a service is running using `systemctl`.
*
* @param {string} name - The service name to check.
* @returns {bool} Returns true if the service runs.
*/
const serviceRuns = (name) => {
try {
return !!cpr.execSync(`systemctl --user is-active ${name}`, { encoding: "utf8" });
} catch {}
return false;
};
/**
* Checks if a process is running using `pidof`.
*
@@ -732,14 +781,61 @@ const execAsyncCommand = (cmd, args = [], callback = null) => {
}
} catch (error) {
console.error("Execute Async:", error.message);
if (typeof callback === "function") {
callback(null, error.message);
}
if (typeof callback === "function") callback(null, error.message);
}
});
return proc;
};
/**
* Executes a script command asynchronously.
*
* @param {string} cmd - The script to execute.
* @param {Array<string>} args - The arguments for the command.
* @param {Function} callback - A callback function that receives the progress or error.
* @returns {Object} The spawned process object.
*/
const execScriptCommand = (cmd, args = [], callback = null) => {
let progress = 10;
let proc = cpr.spawn(cmd, args);
if (typeof callback === "function") callback(progress, null);
proc.stdout.on("data", (data) => {
if (data) {
const lines = data.toString().trim();
const output = lines.replace(/\n+/g, "\n").replace(/^\n+|\n+$|\0/g, "");
if (output) {
console.log(output);
}
}
});
proc.stderr.on("data", (data) => {
if (data) {
const lines = data.toString().trim();
const output = lines.replace(/\n+/g, "\n").replace(/^\n+|\n+$|\0/g, "");
if (output) {
const matches = output.match(/(\d{1,3})%/g);
if (matches) {
const match = Math.max(...matches.map((p) => parseInt(p)));
const percent = Math.floor(match / 10) * 10;
if (percent > 10 && percent > progress) {
progress = percent;
if (typeof callback === "function") callback(progress - 10, null);
}
}
}
}
});
proc.on("close", (code) => {
if (code !== 0) {
console.log(`Script exited with error code ${code}.`);
if (typeof callback === "function") callback(null, code);
} else {
console.log("Script exited successfully.");
if (typeof callback === "function") callback(100, null);
}
});
};
/**
* Executes a D-Bus method call synchronously using `dbus-send`.
*
@@ -755,14 +851,10 @@ const dbusCall = (path, method, values, callback = null) => {
const args = ["--print-reply", "--type=method_call", `--dest=${dest}`];
try {
const output = cpr.execSync([cmd, ...args].join(" ").trim(), { encoding: "utf8" });
if (typeof callback === "function") {
callback(output.trim().replace(/\0/g, "").split("\n").slice(1).join("\n").trim(), null);
}
if (typeof callback === "function") callback(output.trim().replace(/\0/g, ""), null);
} catch (error) {
console.error("Call D-Bus:", error.message);
if (typeof callback === "function") {
callback(null, error.message);
}
if (typeof callback === "function") callback(null, error.message);
}
};
@@ -796,17 +888,13 @@ const dbusMonitor = (path, callback) => {
}
} catch (error) {
console.error("Monitor D-Bus:", error.message);
if (typeof callback === "function") {
callback(null, error.message);
}
if (typeof callback === "function") callback(null, error.message);
}
});
proc.stderr.on("data", (data) => {
if (data) {
console.error("Monitor D-Bus:", data.toString());
if (typeof callback === "function") {
callback(null, data.toString());
}
if (typeof callback === "function") callback(null, data.toString());
}
});
return proc;
@@ -839,6 +927,7 @@ module.exports = {
getVendor,
getSerialNumber,
getMachineId,
getNetworkAddresses,
getHostName,
getUpTime,
getMemorySize,
@@ -855,4 +944,7 @@ module.exports = {
checkPackageUpgrades,
shutdownSystem,
rebootSystem,
execSyncCommand,
execAsyncCommand,
execScriptCommand,
};
+118 -24
View File
@@ -39,14 +39,15 @@ const init = async () => {
// Init globals
INTEGRATION.discovery = discovery;
INTEGRATION.node = `rpi_${deviceId}`;
INTEGRATION.root = `${app.getName()}/${INTEGRATION.node}`;
INTEGRATION.root = `${APP.name}/${INTEGRATION.node}`;
INTEGRATION.device = {
name: `TouchKio ${deviceName}`,
name: `${APP.title} ${deviceName}`,
model: model,
manufacturer: vendor,
serial_number: serialNumber,
identifiers: [INTEGRATION.node],
sw_version: `${app.getName()}-v${app.getVersion()}`,
sw_version: `${APP.name}-v${APP.version}`,
configuration_url: APP.homepage,
};
// Connection settings
@@ -61,6 +62,7 @@ const init = async () => {
console.log(`MQTT Connected: ${url.toString()}\n`);
// Init client controls
initApp();
initShutdown();
initReboot();
initRefresh();
@@ -75,6 +77,7 @@ const init = async () => {
initModel();
initSerialNumber();
initHostName();
initNetworkAddress();
initUpTime();
initMemorySize();
initMemoryUsage();
@@ -107,8 +110,9 @@ const init = async () => {
update();
}, 60 * 1000);
// Update package sensors periodically (60min)
// Update upgrade sensors periodically (1h)
setInterval(() => {
updateApp();
updatePackageUpgrades();
}, 3600 * 1000);
@@ -128,6 +132,7 @@ const update = async () => {
updatePageNumber();
updatePageZoom();
updatePageUrl();
updateNetworkAddress();
updateUpTime();
updateLastActive();
updateMemoryUsage();
@@ -182,10 +187,64 @@ const publishState = (path, state) => {
return INTEGRATION.client.publish(root, `${state}`, { qos: 1, retain: true });
};
/**
* Initializes the app update entity and handles the execute logic.
*/
const initApp = () => {
if (!HARDWARE.support.appUpdate) {
return;
}
const root = `${INTEGRATION.root}/app`;
const config = {
name: "App",
unique_id: `${INTEGRATION.node}_app`,
command_topic: `${root}/install`,
state_topic: `${root}/version/state`,
payload_install: "update",
device: INTEGRATION.device,
};
publishConfig("update", config)
.on("message", (topic, message) => {
if (topic === config.command_topic) {
console.log("Update App...");
hardware.setDisplayStatus("ON");
const args = ["-c", `bash <(wget -qO- ${APP.scripts.install}) update`];
hardware.execScriptCommand("bash", args, (progress, error) => {
updateApp(progress);
});
}
})
.subscribe(config.command_topic);
updateApp();
};
/**
* Updates the app update entity via the mqtt connection.
*/
const updateApp = async (progress = 0) => {
const latest = APP.releases.latest;
if (!latest) {
return;
}
const version = {
title: latest.title,
latest_version: latest.version,
installed_version: APP.version,
release_summary: latest.summary.slice(0, 250) + "...",
release_url: latest.url,
update_percentage: progress || null,
in_progress: progress && progress > 0 && progress < 100,
};
publishState("app/version", JSON.stringify(version));
};
/**
* Initializes the shutdown button and handles the execute logic.
*/
const initShutdown = () => {
if (!HARDWARE.support.sudoRights) {
return;
}
const root = `${INTEGRATION.root}/shutdown`;
const config = {
name: "Shutdown",
@@ -209,6 +268,9 @@ const initShutdown = () => {
* Initializes the reboot button and handles the execute logic.
*/
const initReboot = () => {
if (!HARDWARE.support.sudoRights) {
return;
}
const root = `${INTEGRATION.root}/reboot`;
const config = {
name: "Reboot",
@@ -305,7 +367,7 @@ const initKiosk = () => {
/**
* Updates the kiosk status via the mqtt connection.
*/
const updateKiosk = () => {
const updateKiosk = async () => {
const kiosk = WEBVIEW.status;
publishState("kiosk", kiosk);
};
@@ -364,7 +426,7 @@ const initDisplay = () => {
/**
* Updates the display status, brightness via the mqtt connection.
*/
const updateDisplay = () => {
const updateDisplay = async () => {
const status = hardware.getDisplayStatus();
const brightness = hardware.getDisplayBrightness();
publishState("display/power", status);
@@ -414,7 +476,7 @@ const initKeyboard = () => {
/**
* Updates the keyboard visibility via the mqtt connection.
*/
const updateKeyboard = () => {
const updateKeyboard = async () => {
const visibility = hardware.getKeyboardVisibility();
publishState("keyboard", visibility);
};
@@ -423,7 +485,7 @@ const updateKeyboard = () => {
* Initializes the page number and handles the execute logic.
*/
const initPageNumber = () => {
if (WEBVIEW.viewUrls.length < 3) {
if (WEBVIEW.viewUrls.length <= 2) {
return;
}
const root = `${INTEGRATION.root}/page_number`;
@@ -456,7 +518,7 @@ const initPageNumber = () => {
/**
* Updates the page number via the mqtt connection.
*/
const updatePageNumber = () => {
const updatePageNumber = async () => {
const pageNumber = WEBVIEW.viewActive || 1;
publishState("page_number", pageNumber);
};
@@ -495,7 +557,7 @@ const initPageZoom = () => {
/**
* Updates the page zoom via the mqtt connection.
*/
const updatePageZoom = () => {
const updatePageZoom = async () => {
const pageZoom = Math.round(WEBVIEW.views[WEBVIEW.viewActive || 1].webContents.getZoomFactor() * 100.0);
publishState("page_zoom", pageZoom);
};
@@ -530,7 +592,7 @@ const initPageUrl = () => {
/**
* Updates the page url via the mqtt connection.
*/
const updatePageUrl = () => {
const updatePageUrl = async () => {
const defaultUrl = WEBVIEW.viewUrls[WEBVIEW.viewActive || 1];
const currentUrl = WEBVIEW.views[WEBVIEW.viewActive || 1].webContents.getURL();
const pageUrl = !currentUrl || currentUrl.startsWith("data:") ? defaultUrl : currentUrl;
@@ -546,6 +608,7 @@ const initModel = () => {
name: "Model",
unique_id: `${INTEGRATION.node}_model`,
state_topic: `${root}/state`,
json_attributes_topic: `${root}/attributes`,
value_template: "{{ value }}",
icon: "mdi:raspberry-pi",
device: INTEGRATION.device,
@@ -557,9 +620,10 @@ const initModel = () => {
/**
* Updates the model sensor via the mqtt connection.
*/
const updateModel = () => {
const updateModel = async () => {
const model = hardware.getModel();
publishState("model", model);
publishAttributes("model", HARDWARE.support);
};
/**
@@ -582,11 +646,41 @@ const initSerialNumber = () => {
/**
* Updates the serial number sensor via the mqtt connection.
*/
const updateSerialNumber = () => {
const updateSerialNumber = async () => {
const serialNumber = hardware.getSerialNumber();
publishState("serial_number", serialNumber);
};
/**
* Initializes the network address sensor.
*/
const initNetworkAddress = () => {
const root = `${INTEGRATION.root}/network_address`;
const config = {
name: "Network Address",
unique_id: `${INTEGRATION.node}_network_address`,
state_topic: `${root}/state`,
json_attributes_topic: `${root}/attributes`,
value_template: "{{ value }}",
icon: "mdi:ip-network",
device: INTEGRATION.device,
};
publishConfig("sensor", config);
updateNetworkAddress();
};
/**
* Updates the network address sensor via the mqtt connection.
*/
const updateNetworkAddress = async () => {
const networkAddresses = hardware.getNetworkAddresses();
const [name] = Object.keys(networkAddresses);
const [family] = name ? Object.keys(networkAddresses[name]) : [];
const networkAddress = networkAddresses[name]?.[family]?.[0] || null;
publishState("network_address", networkAddress);
publishAttributes("network_address", networkAddresses);
};
/**
* Initializes the host name sensor.
*/
@@ -607,7 +701,7 @@ const initHostName = () => {
/**
* Updates the host name sensor via the mqtt connection.
*/
const updateHostName = () => {
const updateHostName = async () => {
const hostName = hardware.getHostName();
publishState("host_name", hostName);
};
@@ -633,7 +727,7 @@ const initUpTime = () => {
/**
* Updates the up time sensor via the mqtt connection.
*/
const updateUpTime = () => {
const updateUpTime = async () => {
const upTime = hardware.getUpTime();
publishState("up_time", upTime);
};
@@ -659,7 +753,7 @@ const initMemorySize = () => {
/**
* Updates the memory size sensor via the mqtt connection.
*/
const updateMemorySize = () => {
const updateMemorySize = async () => {
const memorySize = hardware.getMemorySize();
publishState("memory_size", memorySize);
};
@@ -685,7 +779,7 @@ const initMemoryUsage = () => {
/**
* Updates the memory usage sensor via the mqtt connection.
*/
const updateMemoryUsage = () => {
const updateMemoryUsage = async () => {
const memoryUsage = hardware.getMemoryUsage();
publishState("memory_usage", memoryUsage);
};
@@ -711,7 +805,7 @@ const initProcessorUsage = () => {
/**
* Updates the processor usage sensor via the mqtt connection.
*/
const updateProcessorUsage = () => {
const updateProcessorUsage = async () => {
const processorUsage = hardware.getProcessorUsage();
publishState("processor_usage", processorUsage);
};
@@ -737,7 +831,7 @@ const initProcessorTemperature = () => {
/**
* Updates the processor temperature sensor via the mqtt connection.
*/
const updateProcessorTemperature = () => {
const updateProcessorTemperature = async () => {
const processorTemperature = hardware.getProcessorTemperature();
publishState("processor_temperature", processorTemperature);
};
@@ -766,7 +860,7 @@ const initBatteryLevel = () => {
/**
* Updates the battery level sensor via the mqtt connection.
*/
const updateBatteryLevel = () => {
const updateBatteryLevel = async () => {
const batteryLevel = hardware.getBatteryLevel();
publishState("battery_level", batteryLevel);
};
@@ -792,14 +886,14 @@ const initPackageUpgrades = () => {
/**
* Updates the package upgrades sensor via the mqtt connection.
*/
const updatePackageUpgrades = () => {
const updatePackageUpgrades = async () => {
const packages = hardware.checkPackageUpgrades();
const attributes = {
total: packages.length,
packages: packages.map((pkg) => pkg.replace(/\s*\[.*?\]\s*/g, "").trim()),
};
publishAttributes("package_upgrades", attributes);
publishState("package_upgrades", attributes.total);
publishAttributes("package_upgrades", attributes);
};
/**
@@ -822,7 +916,7 @@ const initHeartbeat = () => {
/**
* Updates the heartbeat sensor via the mqtt connection.
*/
const updateHeartbeat = () => {
const updateHeartbeat = async () => {
const now = new Date();
const local = new Date(now.getTime() - now.getTimezoneOffset() * 60 * 1000);
const heartbeat = local.toISOString().replace(/\.\d{3}Z$/, "");
@@ -850,7 +944,7 @@ const initLastActive = () => {
/**
* Updates the last active sensor via the mqtt connection.
*/
const updateLastActive = () => {
const updateLastActive = async () => {
const now = new Date();
const then = WEBVIEW.pointer.time;
const lastActive = Math.abs(now - then) / (1000 * 60);
+44 -17
View File
@@ -54,8 +54,8 @@ const init = async () => {
// Init global root window
WEBVIEW.window = new BaseWindow({
title: "TouchKio",
icon: path.join(__dirname, "..", "img", "icon.png"),
title: APP.title,
icon: path.join(APP.path, "img", "icon.png"),
});
WEBVIEW.window.setMenuBarVisibility(false);
WEBVIEW.window.setFullScreen(fullscreen);
@@ -91,7 +91,7 @@ const init = async () => {
});
WEBVIEW.pager.setBackgroundColor("#00000000");
WEBVIEW.window.contentView.addChildView(WEBVIEW.pager);
WEBVIEW.pager.webContents.loadFile(path.join(app.getAppPath(), "html", "pager.html"));
WEBVIEW.pager.webContents.loadFile(path.join(APP.path, "html", "pager.html"));
// Init global widget
WEBVIEW.widget = new WebContentsView({
@@ -103,7 +103,7 @@ const init = async () => {
});
WEBVIEW.widget.setBackgroundColor("#00000000");
WEBVIEW.window.contentView.addChildView(WEBVIEW.widget);
WEBVIEW.widget.webContents.loadFile(path.join(app.getAppPath(), "html", "widget.html"));
WEBVIEW.widget.webContents.loadFile(path.join(APP.path, "html", "widget.html"));
// Init global navigation
WEBVIEW.navigation = new WebContentsView({
@@ -115,14 +115,14 @@ const init = async () => {
});
WEBVIEW.navigation.setBackgroundColor("#00000000");
WEBVIEW.window.contentView.addChildView(WEBVIEW.navigation);
WEBVIEW.navigation.webContents.loadFile(path.join(app.getAppPath(), "html", "navigation.html"));
WEBVIEW.navigation.webContents.loadFile(path.join(APP.path, "html", "navigation.html"));
// Register events
windowEvents();
widgetEvents();
navigationEvents();
viewEvents();
appEvents();
await windowEvents();
await widgetEvents();
await navigationEvents();
await viewEvents();
await appEvents();
return true;
};
@@ -166,7 +166,7 @@ const updateView = () => {
}
const url = WEBVIEW.views[WEBVIEW.viewActive].webContents.getURL();
const host = url.startsWith("data:") ? "whoopsie" : new URL(url).host;
const title = `TouchKio - ${host} (${WEBVIEW.viewActive})`;
const title = `${APP.title} - ${host} (${WEBVIEW.viewActive})`;
// Update window title
console.log(`Update View: ${title}`);
@@ -427,7 +427,7 @@ const resizeView = () => {
/**
* Register window events and handler.
*/
const windowEvents = () => {
const windowEvents = async () => {
// Handle window resize events
WEBVIEW.window.on("ready-to-show", resizeView);
WEBVIEW.window.on("resize", resizeView);
@@ -476,7 +476,7 @@ const windowEvents = () => {
historyForward();
});
// Handle window touch events
// Check for window touch events (1s)
setInterval(() => {
const now = new Date();
const then = WEBVIEW.pointer.time;
@@ -495,7 +495,7 @@ const windowEvents = () => {
/**
* Register widget events and handler.
*/
const widgetEvents = () => {
const widgetEvents = async () => {
if (!WEBVIEW.widgetEnabled) {
return;
}
@@ -581,7 +581,7 @@ const widgetEvents = () => {
/**
* Register navigation events and handler.
*/
const navigationEvents = () => {
const navigationEvents = async () => {
if (!WEBVIEW.navigationEnabled) {
return;
}
@@ -680,7 +680,7 @@ const navigationEvents = () => {
/**
* Register view events and handler.
*/
const viewEvents = () => {
const viewEvents = async () => {
const ready = [];
WEBVIEW.views.forEach((view, i) => {
// Enable webview touch emulation
@@ -768,7 +768,7 @@ const viewEvents = () => {
/**
* Register app events and handler.
*/
const appEvents = () => {
const appEvents = async () => {
// Handle signal and exit events
process.on("SIGINT", app.quit);
app.on("before-quit", () => {
@@ -784,10 +784,37 @@ const appEvents = () => {
WEBVIEW.window.focus();
});
// Check for latest release infos (2h)
setInterval(() => {
latestRelease();
}, 7200 * 1000);
await latestRelease();
// Webview initialized
WEBVIEW.initialized = true;
};
/**
* Fetches the latest app release infos from github.
*/
const latestRelease = async () => {
try {
const response = await axios.get(`${APP.releases.url}/latest`);
const data = response ? response.data : null;
if (!data || data.draft || data.prerelease) {
return;
}
APP.releases.latest = {
title: APP.title,
version: (data.tag_name || data.name || "").replace(/^v/i, ""),
summary: data.body || "",
url: data.html_url || "",
};
} catch (error) {
console.warn("Github Error:", error.message);
}
};
/**
* Checks for network connectivity by requesting a known url.
*
+5 -3
View File
@@ -1,9 +1,10 @@
{
"name": "touchkio",
"title": "TouchKio",
"description": "Home Assistant Touch Kiosk",
"homepage": "https://github.com/leukipp/touchkio",
"author": "leukipp",
"version": "1.2.1",
"version": "1.3.0",
"license": "MIT",
"main": "index.js",
"scripts": {
@@ -18,11 +19,12 @@
"@electron-forge/maker-deb": "^7.8.3",
"@electron-forge/maker-zip": "^7.8.3",
"@electron-forge/publisher-github": "^7.8.3",
"electron": "^37.4.0",
"electron": "^38.0.0",
"jszip": "^3.10.1",
"prettier": "^3.6.2"
},
"dependencies": {
"axios": "^1.11.0",
"mqtt": "^5.14.0"
"mqtt": "^5.14.1"
}
}
+93 -26
View File
@@ -3,9 +3,9 @@
"@babel/runtime@^7.28.3":
version "7.28.3"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.28.3.tgz#75c5034b55ba868121668be5d5bb31cc64e6e61a"
integrity sha512-9uIQ10o0WGdpP6GDhXcdOJPJuDgFtIDtN/9+ArJQ2NAfAmiuhTQdzkaTGR33v43GYS2UrSA0eX2pPPHoFVvpxA==
version "7.28.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.28.4.tgz#a70226016fabe25c5783b2f22d3e1c9bc5ca3326"
integrity sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ==
"@electron-forge/cli@^7.8.3":
version "7.8.3"
@@ -571,16 +571,16 @@
"@types/node" "*"
"@types/node@*":
version "24.3.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-24.3.0.tgz#89b09f45cb9a8ee69466f18ee5864e4c3eb84dec"
integrity sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow==
version "24.3.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-24.3.1.tgz#b0a3fb2afed0ef98e8d7f06d46ef6349047709f3"
integrity sha512-3vXmQDXy+woz+gnrTvuvNrPzekOi+Ds0ReMxw0LzBiK3a+1k0kQn9f2NWk+lgD4rJehFUmYy2gMhJ2ZI+7YP9g==
dependencies:
undici-types "~7.10.0"
"@types/node@^22.7.7":
version "22.18.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.18.0.tgz#9e4709be4f104e3568f7dd1c71e2949bf147a47b"
integrity sha512-m5ObIqwsUp6BZzyiy4RdZpzWGub9bqLJMvZDD0QMXhxjqMHMENlj+SqF5QxoUwaQNFe+8kz8XM8ZQhqkQPTgMQ==
version "22.18.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.18.1.tgz#cc85ee6999b2a2928739281d2f56ff410a140c52"
integrity sha512-rzSDyhn4cYznVG+PCzGe1lwuMYJrcBS1fc3JqSa2PvtABwWo+dZ1ij5OVok3tqfpEBCBoaR4d7upFJk73HRJDw==
dependencies:
undici-types "~6.21.0"
@@ -729,9 +729,9 @@ bl@^4.1.0:
readable-stream "^3.4.0"
bl@^6.0.8:
version "6.1.2"
resolved "https://registry.yarnpkg.com/bl/-/bl-6.1.2.tgz#fd4274e73c24f4c34ada6d69a612ec924f3df345"
integrity sha512-6J3oG82fpJ71WF4l0W6XslkwAPMr+Zcp+AmdxJ0L8LsXNzFeO8GYesV2J9AzGArBjrsb2xR50Ocbn/CL1B44TA==
version "6.1.3"
resolved "https://registry.yarnpkg.com/bl/-/bl-6.1.3.tgz#158ac572ee2a3446884585ddd02d02b4c5d122bf"
integrity sha512-nHB8B5roHlGX5TFsWeiQJijdddZIOHuv1eL2cM2kHnG3qR91CYLsysGe+CvxQfEd23EKD0eJf4lto0frTbddKA==
dependencies:
"@types/readable-stream" "^4.0.0"
buffer "^6.0.3"
@@ -1005,6 +1005,11 @@ concat-stream@^2.0.0:
readable-stream "^3.0.2"
typedarray "^0.0.6"
core-util-is@~1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==
cross-dirname@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/cross-dirname/-/cross-dirname-0.1.0.tgz#b899599f30a5389f59e78c150e19f957ad16a37c"
@@ -1159,10 +1164,10 @@ electron-installer-debian@^3.2.0:
word-wrap "^1.2.3"
yargs "^16.0.2"
electron@^37.4.0:
version "37.4.0"
resolved "https://registry.yarnpkg.com/electron/-/electron-37.4.0.tgz#08b2eff9d6250fac7b298f17f93946ecd586f38e"
integrity sha512-HhsSdWowE5ODOeWNc/323Ug2C52mq/TqNBG+4uMeOA3G2dMXNc/nfyi0RYu1rJEgiaJLEjtHveeZZaYRYFsFCQ==
electron@^38.0.0:
version "38.0.0"
resolved "https://registry.yarnpkg.com/electron/-/electron-38.0.0.tgz#e51803f62c8d4c368f77642a1b1b05444c687fba"
integrity sha512-egljptiPJqbL/oamFCEY+g3RNeONWTVxZSGeyLqzK8xq106JhzuxnhJZ3sxt4DzJFaofbGyGJA37Oe9d+gVzYw==
dependencies:
"@electron/get" "^2.0.0"
"@types/node" "^22.7.7"
@@ -1696,6 +1701,11 @@ ieee754@^1.1.13, ieee754@^1.2.1:
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
integrity sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
@@ -1719,7 +1729,7 @@ inflight@^1.0.4:
once "^1.3.0"
wrappy "1"
inherits@2, inherits@^2.0.3, inherits@^2.0.4:
inherits@2, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.3:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
@@ -1798,6 +1808,11 @@ is-unicode-supported@^0.1.0:
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==
isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
integrity sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==
isbinaryfile@^4.0.8:
version "4.0.10"
resolved "https://registry.yarnpkg.com/isbinaryfile/-/isbinaryfile-4.0.10.tgz#0c5b5e30c2557a2f06febd37b7322946aaee42b3"
@@ -1844,6 +1859,16 @@ jsonfile@^6.0.1:
optionalDependencies:
graceful-fs "^4.1.6"
jszip@^3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/jszip/-/jszip-3.10.1.tgz#34aee70eb18ea1faec2f589208a157d1feb091c2"
integrity sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==
dependencies:
lie "~3.3.0"
pako "~1.0.2"
readable-stream "~2.3.6"
setimmediate "^1.0.5"
junk@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/junk/-/junk-3.1.0.tgz#31499098d902b7e98c5d9b9c80f43457a88abfa1"
@@ -1856,6 +1881,13 @@ keyv@^4.0.0:
dependencies:
json-buffer "3.0.1"
lie@~3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.3.0.tgz#dcf82dee545f46074daf200c7c1c5a08e0f40f6a"
integrity sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==
dependencies:
immediate "~3.0.5"
listr2@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/listr2/-/listr2-7.0.2.tgz#3aa3e1549dfaf3c57ab5eeaba754da3b87f33063"
@@ -2126,10 +2158,10 @@ mqtt-packet@^9.0.2:
debug "^4.3.4"
process-nextick-args "^2.0.1"
mqtt@^5.14.0:
version "5.14.0"
resolved "https://registry.yarnpkg.com/mqtt/-/mqtt-5.14.0.tgz#eeeb1563884f73cad4fb973449d3973666a4202f"
integrity sha512-H7EmeCJhbGblbWjm6APF5sAH3SkdI7lxHw/UkblZp8fjSNl8b2MsLcdAkIaQKxvZYmiORkdAjffvKjqQWPkd6w==
mqtt@^5.14.1:
version "5.14.1"
resolved "https://registry.yarnpkg.com/mqtt/-/mqtt-5.14.1.tgz#c65063b2cc9d9336430bde27a337ae98e5b4705a"
integrity sha512-NxkPxE70Uq3Ph7goefQa7ggSsVzHrayCD0OyxlJgITN/EbzlZN+JEPmaAZdxP1LsIT5FamDyILoQTF72W7Nnbw==
dependencies:
"@types/readable-stream" "^4.0.21"
"@types/ws" "^8.18.1"
@@ -2169,9 +2201,9 @@ nice-try@^1.0.4:
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
node-abi@^3.45.0:
version "3.75.0"
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-3.75.0.tgz#2f929a91a90a0d02b325c43731314802357ed764"
integrity sha512-OhYaY5sDsIka7H7AtijtI9jwGYLyl29eQn/W623DiN/MIv5sUqc4g7BIDThX+gb7di9f6xK02nkp8sdfFWZLTg==
version "3.77.0"
resolved "https://registry.yarnpkg.com/node-abi/-/node-abi-3.77.0.tgz#3ad90d5c9d45663420e5aa4ff58dbf4e3625419a"
integrity sha512-DSmt0OEcLoK4i3NuscSbGjOf3bqiDEutejqENSplMSFA/gmB8mkED9G4pKWnPl7MDU4rSHebKPHeitpDfyH0cQ==
dependencies:
semver "^7.3.5"
@@ -2320,6 +2352,11 @@ p-try@^1.0.0:
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
integrity sha512-U1etNYuMJoIz3ZXSrrySFjsXQTWOx2/jdi86L+2pRvph/qMKL6sbcCYdH23fqsbm8TH2Gn0OybpT4eSFlCVHww==
pako@~1.0.2:
version "1.0.11"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
parse-author@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/parse-author/-/parse-author-2.0.0.tgz#d3460bf1ddd0dfaeed42da754242e65fb684a81f"
@@ -2417,7 +2454,7 @@ proc-log@^2.0.1:
resolved "https://registry.yarnpkg.com/proc-log/-/proc-log-2.0.1.tgz#8f3f69a1f608de27878f91f5c688b225391cb685"
integrity sha512-Kcmo2FhfDTXdcbfDH76N7uBYHINxc/8GW7UAVuVP9I+Va3uHSerrnKV6dLooga/gh7GlgzuCCr/eoldnL1muGw==
process-nextick-args@^2.0.1:
process-nextick-args@^2.0.1, process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==
@@ -2512,6 +2549,19 @@ readable-stream@^4.2.0, readable-stream@^4.7.0:
process "^0.11.10"
string_decoder "^1.3.0"
readable-stream@~2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.8.tgz#91125e8042bba1b9887f49345f6277027ce8be9b"
integrity sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==
dependencies:
core-util-is "~1.0.0"
inherits "~2.0.3"
isarray "~1.0.0"
process-nextick-args "~2.0.0"
safe-buffer "~5.1.1"
string_decoder "~1.1.1"
util-deprecate "~1.0.1"
rechoir@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22"
@@ -2609,6 +2659,11 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"
safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
safe-buffer@~5.2.0:
version "5.2.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
@@ -2646,6 +2701,11 @@ serialize-error@^7.0.1:
dependencies:
type-fest "^0.13.1"
setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
integrity sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==
shebang-command@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
@@ -2786,6 +2846,13 @@ string_decoder@^1.1.1, string_decoder@^1.3.0:
dependencies:
safe-buffer "~5.2.0"
string_decoder@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8"
integrity sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==
dependencies:
safe-buffer "~5.1.0"
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
@@ -2956,7 +3023,7 @@ username@^5.1.0:
execa "^1.0.0"
mem "^4.3.0"
util-deprecate@^1.0.1:
util-deprecate@^1.0.1, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==