feat: early app updates #96

This commit is contained in:
leukipp
2025-10-08 20:47:59 +02:00
parent f666ed57ab
commit ad7d3fd3ff
3 changed files with 34 additions and 32 deletions
+19 -18
View File
@@ -1,11 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Read arguments # Read arguments
ARG_EARLY=false
ARG_UPDATE=false ARG_UPDATE=false
for arg in "$@"; do for arg in "$@"; do
if [ "$arg" = "update" ]; then case "$arg" in
ARG_UPDATE=true early) ARG_EARLY=true ;;
fi update) ARG_UPDATE=true ;;
esac
done done
# Determine system architecture # Determine system architecture
@@ -13,15 +15,9 @@ echo -e "Determining system architecture..."
BITS=$(getconf LONG_BIT) BITS=$(getconf LONG_BIT)
case "$(uname -m)" in case "$(uname -m)" in
aarch64) x86_64) ARCH="x64" ;;
ARCH="arm64" aarch64) ARCH="arm64" ;;
;; *) { echo "Architecture $(uname -m) running $BITS-bit operating system is not supported."; exit 1; } ;;
x86_64)
ARCH="x64"
;;
*)
{ echo "Architecture $(uname -m) running $BITS-bit operating system is not supported."; exit 1; }
;;
esac esac
[ "$BITS" -eq 64 ] || { echo "Architecture $ARCH running $BITS-bit operating system is not supported."; exit 1; } [ "$BITS" -eq 64 ] || { echo "Architecture $ARCH running $BITS-bit operating system is not supported."; exit 1; }
@@ -31,12 +27,18 @@ echo "Architecture $ARCH running $BITS-bit operating system is supported."
echo -e "\nDownloading the latest release..." echo -e "\nDownloading the latest release..."
TMP_DIR=$(mktemp -d) 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')
DEB_PATH="${TMP_DIR}/$(basename "$DEB_URL")"
chmod 755 "$TMP_DIR" chmod 755 "$TMP_DIR"
JSON=$(wget -qO- "https://api.github.com/repos/leukipp/touchkio/releases" | tr -d '\r\n')
if $ARG_EARLY; then
DEB_REG='"prerelease":\s*(true|false).*?"browser_download_url":\s*"\K[^\"]*_'$ARCH'\.deb'
else
DEB_REG='"prerelease":\s*false.*?"browser_download_url":\s*"\K[^\"]*_'$ARCH'\.deb'
fi
DEB_URL=$(echo "$JSON" | grep -oP "$DEB_REG" | head -n 1)
DEB_PATH="${TMP_DIR}/$(basename "$DEB_URL")"
[ -z "$DEB_URL" ] && { echo "Download url for .deb file not found."; exit 1; } [ -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; } wget --show-progress -q -O "$DEB_PATH" "$DEB_URL" || { echo "Failed to download the .deb file."; exit 1; }
@@ -108,8 +110,7 @@ else
fi fi
# Start the setup mode # Start the setup mode
echo "" read -p $'\nStart touchkio setup? (Y/n) ' setup
read -p "Start touchkio setup? (Y/n) " setup
if [[ ${setup:-y} == [Yy]* ]]; then if [[ ${setup:-y} == [Yy]* ]]; then
echo "/usr/bin/touchkio --setup" echo "/usr/bin/touchkio --setup"
+2 -2
View File
@@ -235,7 +235,7 @@ const initApp = () => {
unique_id: `${INTEGRATION.node}_app`, unique_id: `${INTEGRATION.node}_app`,
command_topic: `${root}/install`, command_topic: `${root}/install`,
state_topic: `${root}/version/state`, state_topic: `${root}/version/state`,
payload_install: "update", payload_install: "app_early" in ARGS ? "update early" : "update",
device: INTEGRATION.device, device: INTEGRATION.device,
}; };
if (!HARDWARE.support.appUpdate) { if (!HARDWARE.support.appUpdate) {
@@ -247,7 +247,7 @@ const initApp = () => {
if (topic === config.command_topic) { if (topic === config.command_topic) {
console.info("Update App..."); console.info("Update App...");
hardware.setDisplayStatus("ON", () => { hardware.setDisplayStatus("ON", () => {
const args = ["-c", `bash <(wget -qO- ${APP.scripts.install}) update`]; const args = ["-c", `bash <(wget -qO- ${APP.scripts.install}) ${message.toString()}`];
hardware.execScriptCommand("bash", args, (progress, error) => { hardware.execScriptCommand("bash", args, (progress, error) => {
if (progress) { if (progress) {
console.info(`Progress: ${progress}%`); console.info(`Progress: ${progress}%`);
+11 -10
View File
@@ -49,7 +49,7 @@ const init = async () => {
session.defaultSession.clearCache(); session.defaultSession.clearCache();
// Parse arguments // Parse arguments
const debug = ARGS.app_debug === "true"; const debug = "app_debug" in ARGS;
const widget = ARGS.web_widget ? ARGS.web_widget === "true" : true; const widget = ARGS.web_widget ? ARGS.web_widget === "true" : true;
const zoom = !isNaN(parseFloat(ARGS.web_zoom)) ? parseFloat(ARGS.web_zoom) : 1.25; const zoom = !isNaN(parseFloat(ARGS.web_zoom)) ? parseFloat(ARGS.web_zoom) : 1.25;
const theme = ["light", "dark"].includes(ARGS.web_theme) ? ARGS.web_theme : "dark"; const theme = ["light", "dark"].includes(ARGS.web_theme) ? ARGS.web_theme : "dark";
@@ -905,7 +905,7 @@ const viewEvents = async () => {
if (WEBVIEW.viewActive === 0 && ready.length === WEBVIEW.views.length) { if (WEBVIEW.viewActive === 0 && ready.length === WEBVIEW.views.length) {
nextView(); nextView();
} }
if (ARGS.app_debug === "true") { if ("app_debug" in ARGS) {
setTimeout(() => { setTimeout(() => {
view.webContents.openDevTools(); view.webContents.openDevTools();
}, 2000); }, 2000);
@@ -1051,17 +1051,18 @@ const appEvents = async () => {
*/ */
const latestRelease = async () => { const latestRelease = async () => {
try { try {
const response = await axios.get(`${APP.releases.url}/latest`, { timeout: 10000 }); const response = await axios.get(APP.releases.url, { timeout: 10000 });
const data = response ? response.data : null; const release = response?.data?.find((item) => {
if (!data || data.draft || data.prerelease) { return !item.draft && (!item.prerelease || "app_early" in ARGS);
return; });
} if (release) {
APP.releases.latest = { APP.releases.latest = {
title: APP.title, title: APP.title,
version: (data.tag_name || data.name || " ").replace(/^v/i, ""), version: (release.tag_name || " ").replace(/^v/i, ""),
summary: data.body || " ", summary: release.body || " ",
url: data.html_url || " ", url: release.html_url || " ",
}; };
}
} catch (error) { } catch (error) {
console.warn("Github Error:", error.message); console.warn("Github Error:", error.message);
} }