From b30758dd2d7f2d531072f4e3bc7cbc2974398616 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 23 Jun 2026 16:22:27 +0200 Subject: [PATCH] Add optional service widgets on shell refresh --- bin/omarchy | 1 + bin/omarchy-installed-service-dropbox | 12 +++ bin/omarchy-installed-service-tailscale | 12 +++ bin/omarchy-refresh-shell | 11 +++ test/shell.d/config-test.sh | 60 ++++++++++++++ test/shell.d/installed-service-test.sh | 101 ++++++++++++++++++++++++ 6 files changed, 197 insertions(+) create mode 100755 bin/omarchy-installed-service-dropbox create mode 100755 bin/omarchy-installed-service-tailscale create mode 100755 test/shell.d/installed-service-test.sh diff --git a/bin/omarchy b/bin/omarchy index 2c8433f9..a6341e7b 100755 --- a/bin/omarchy +++ b/bin/omarchy @@ -51,6 +51,7 @@ GROUP_DESCRIPTIONS[hook]="User hook runner" GROUP_DESCRIPTIONS[hw]="Hardware detection and controls" GROUP_DESCRIPTIONS[hyprland]="Hyprland window, monitor, and toggle controls" GROUP_DESCRIPTIONS[install]="Optional software installers" +GROUP_DESCRIPTIONS[installed]="Installed optional service checks" GROUP_DESCRIPTIONS[launch]="Application launchers" GROUP_DESCRIPTIONS[menu]="Omarchy menu commands" GROUP_DESCRIPTIONS[migrate]="Migration runner" diff --git a/bin/omarchy-installed-service-dropbox b/bin/omarchy-installed-service-dropbox new file mode 100755 index 00000000..84b91a61 --- /dev/null +++ b/bin/omarchy-installed-service-dropbox @@ -0,0 +1,12 @@ +#!/bin/bash + +# omarchy:summary=Check whether Dropbox is installed and running +# omarchy:hidden=true + +set -euo pipefail + +if omarchy-cmd-present dropbox-cli && dropbox-cli running >/dev/null 2>&1; then + exit 0 +fi + +pgrep -x dropbox >/dev/null 2>&1 diff --git a/bin/omarchy-installed-service-tailscale b/bin/omarchy-installed-service-tailscale new file mode 100755 index 00000000..44effe90 --- /dev/null +++ b/bin/omarchy-installed-service-tailscale @@ -0,0 +1,12 @@ +#!/bin/bash + +# omarchy:summary=Check whether Tailscale is installed and running +# omarchy:hidden=true + +set -euo pipefail + +if omarchy-cmd-present tailscale && tailscale status --json >/dev/null 2>&1; then + exit 0 +fi + +systemctl is-active --quiet tailscaled.service >/dev/null 2>&1 || pgrep -x tailscaled >/dev/null 2>&1 diff --git a/bin/omarchy-refresh-shell b/bin/omarchy-refresh-shell index c76ed96a..ae5611c5 100755 --- a/bin/omarchy-refresh-shell +++ b/bin/omarchy-refresh-shell @@ -3,5 +3,16 @@ # omarchy:summary=Reset shell.json to Omarchy defaults # omarchy:examples=omarchy refresh shell +set -euo pipefail + omarchy-refresh-config omarchy/shell.json + +if omarchy-installed-service-dropbox; then + omarchy-config-shell-bar add omarchy.dropbox +fi + +if omarchy-installed-service-tailscale; then + omarchy-config-shell-bar add omarchy.tailscale +fi + omarchy-restart-shell diff --git a/test/shell.d/config-test.sh b/test/shell.d/config-test.sh index bda8ab55..5ec6228c 100755 --- a/test/shell.d/config-test.sh +++ b/test/shell.d/config-test.sh @@ -300,6 +300,66 @@ jq -e ' ' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null pass "shell config removes widgets with remove alias" +mock_bin="$TMPDIR/mock-bin" +mkdir -p "$mock_bin" + +cat >"$mock_bin/omarchy-refresh-config" <<'SH' +#!/bin/bash +set -euo pipefail + +relative_path="${1:-}" +[[ -n $relative_path ]] || exit 1 +mkdir -p "$HOME/.config/$(dirname "$relative_path")" +cp "$OMARCHY_PATH/config/$relative_path" "$HOME/.config/$relative_path" +SH + +cat >"$mock_bin/omarchy-restart-shell" <<'SH' +#!/bin/bash +set -euo pipefail + +mkdir -p "$HOME/.local/state/omarchy" +touch "$HOME/.local/state/omarchy/restart-shell-called" +SH + +cat >"$mock_bin/omarchy-shell" <<'SH' +#!/bin/bash +exit 0 +SH + +cat >"$mock_bin/omarchy-installed-service-dropbox" <<'SH' +#!/bin/bash +set -euo pipefail + +[[ ${OMARCHY_TEST_DROPBOX:-0} == "1" ]] +SH + +cat >"$mock_bin/omarchy-installed-service-tailscale" <<'SH' +#!/bin/bash +set -euo pipefail + +[[ ${OMARCHY_TEST_TAILSCALE:-0} == "1" ]] +SH + +chmod +x "$mock_bin"/* +mock_path="$mock_bin:$ROOT/bin:$PATH" + +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" PATH="$mock_path" OMARCHY_TEST_DROPBOX=0 OMARCHY_TEST_TAILSCALE=0 omarchy-refresh-shell +jq -e ' + def ids: map(.id // .); + (.bar.layout.right | ids | index("omarchy.dropbox") == null) and + (.bar.layout.right | ids | index("omarchy.tailscale") == null) +' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null +pass "shell refresh keeps optional service widgets absent when services are unavailable" + +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" PATH="$mock_path" OMARCHY_TEST_DROPBOX=1 OMARCHY_TEST_TAILSCALE=1 omarchy-refresh-shell +jq -e ' + def ids: map(.id // .); + (.bar.layout.right | ids | index("omarchy.dropbox") != null) and + (.bar.layout.right | ids | index("omarchy.tailscale") != null) +' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null +[[ -f $TMPDIR/home/.local/state/omarchy/restart-shell-called ]] || fail "shell refresh restarts shell" +pass "shell refresh adds optional service widgets when services are available" + if grep -RIl 'upgrade-to-quattro\|Omarchy 4\.0 is upgraded' "$ROOT/migrations" >/dev/null; then fail "4.0 upgrade is not modeled as a migration" fi diff --git a/test/shell.d/installed-service-test.sh b/test/shell.d/installed-service-test.sh new file mode 100755 index 00000000..428d5d98 --- /dev/null +++ b/test/shell.d/installed-service-test.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +export PATH="$ROOT/bin:$PATH" + +TMPDIR=$(mktemp -d) +trap 'rm -rf "$TMPDIR"' EXIT + +mock_bin="$TMPDIR/bin" +mkdir -p "$mock_bin" + +cat >"$mock_bin/omarchy-cmd-present" <<'SH' +#!/bin/bash +set -euo pipefail + +case "${1:-}" in + dropbox-cli) + [[ ${OMARCHY_TEST_DROPBOX_CLI:-0} == "1" ]] + ;; + tailscale) + [[ ${OMARCHY_TEST_TAILSCALE_CLI:-0} == "1" ]] + ;; + *) + command -v "${1:-}" >/dev/null 2>&1 + ;; +esac +SH + +cat >"$mock_bin/dropbox-cli" <<'SH' +#!/bin/bash +set -euo pipefail + +[[ ${OMARCHY_TEST_DROPBOX_RUNNING:-0} == "1" && ${1:-} == "running" ]] +SH + +cat >"$mock_bin/tailscale" <<'SH' +#!/bin/bash +set -euo pipefail + +[[ ${OMARCHY_TEST_TAILSCALE_STATUS:-0} == "1" && ${1:-} == "status" && ${2:-} == "--json" ]] +SH + +cat >"$mock_bin/systemctl" <<'SH' +#!/bin/bash +set -euo pipefail + +[[ ${OMARCHY_TEST_TAILSCALE_SYSTEMD:-0} == "1" ]] +SH + +cat >"$mock_bin/pgrep" <<'SH' +#!/bin/bash +set -euo pipefail + +if (( $# == 0 )); then + exit 1 +fi + +name="${!#}" +case "$name" in + dropbox) + [[ ${OMARCHY_TEST_DROPBOX_PROCESS:-0} == "1" ]] + ;; + tailscaled) + [[ ${OMARCHY_TEST_TAILSCALE_PROCESS:-0} == "1" ]] + ;; + *) + exit 1 + ;; +esac +SH + +chmod +x "$mock_bin"/* +mock_path="$mock_bin:$ROOT/bin:$PATH" + +PATH="$mock_path" OMARCHY_TEST_DROPBOX_CLI=1 OMARCHY_TEST_DROPBOX_RUNNING=1 omarchy-installed-service-dropbox +pass "installed Dropbox service check accepts running CLI" + +PATH="$mock_path" OMARCHY_TEST_DROPBOX_PROCESS=1 omarchy-installed-service-dropbox +pass "installed Dropbox service check accepts running process" + +if PATH="$mock_path" omarchy-installed-service-dropbox; then + fail "installed Dropbox service check rejects unavailable service" +fi +pass "installed Dropbox service check rejects unavailable service" + +PATH="$mock_path" OMARCHY_TEST_TAILSCALE_CLI=1 OMARCHY_TEST_TAILSCALE_STATUS=1 omarchy-installed-service-tailscale +pass "installed Tailscale service check accepts status JSON" + +PATH="$mock_path" OMARCHY_TEST_TAILSCALE_SYSTEMD=1 omarchy-installed-service-tailscale +pass "installed Tailscale service check accepts active systemd service" + +PATH="$mock_path" OMARCHY_TEST_TAILSCALE_PROCESS=1 omarchy-installed-service-tailscale +pass "installed Tailscale service check accepts running daemon" + +if PATH="$mock_path" omarchy-installed-service-tailscale; then + fail "installed Tailscale service check rejects unavailable service" +fi +pass "installed Tailscale service check rejects unavailable service"