Skip to content
Closed
9 changes: 8 additions & 1 deletion bin/omarchy-launch-floating-terminal-with-presentation
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
# Used by actions such as Update System.

cmd="$*"
exec setsid uwsm-app -- xdg-terminal-exec --app-id=org.omarchy.terminal --title=Omarchy -e bash -c "omarchy-show-logo; $cmd; if (( \$? != 130 )); then omarchy-show-done; fi"

if [[ "$1" == "omarchy-webapp-install" ]]; then
presentation_part="omarchy-show-webapp-logo"
else
presentation_part="omarchy-show-logo"
fi

exec setsid uwsm-app -- xdg-terminal-exec --app-id=org.omarchy.terminal --title=Omarchy -e bash -c "$presentation_part; $cmd; if (( \$? != 130 )); then omarchy-show-done; fi"
68 changes: 57 additions & 11 deletions bin/omarchy-launch-or-focus
Original file line number Diff line number Diff line change
@@ -1,19 +1,65 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail

# Launch or focus on a given command identified by the passed in window-pattern.
# Use by some default bindings, like the one for Spotify, to ensure there is only one instance of the application open.
find_window_address() {
local pattern="$1"
hyprctl clients -j \
| jq -r --arg p "$pattern" '.[] | select((.class+" "+.title) | test($p;"i")) | .address' \
| head -n1
}

regex_escape() {
sed -e 's/[.[\*^$()+?{}|\\]/\\&/g' <<<"$1"
}

if (($# == 0)); then
echo "Usage: omarchy-launch-or-focus [window-pattern] [launch-command]"
echo "Usage:"
echo " omarchy-launch-or-focus <window-pattern> [launch-command]"
echo " omarchy-launch-or-focus <url> [profile] [extra browser flags...]"
exit 1
fi

WINDOW_PATTERN="$1"
LAUNCH_COMMAND="${2:-"uwsm-app -- $WINDOW_PATTERN"}"
WINDOW_ADDRESS=$(hyprctl clients -j | jq -r --arg p "$WINDOW_PATTERN" '.[]|select((.class|test("\\b" + $p + "\\b";"i")) or (.title|test("\\b" + $p + "\\b";"i")))|.address' | head -n1)
arg1="$1"

if [[ "$arg1" =~ ^https?:// ]]; then
APP_URL="$1"
PROFILE="${2-}"
shift || true
if [[ -n "${PROFILE:-}" ]]; then shift || true; fi
EXTRA_FLAGS=("$@")

host="${APP_URL#*://}"; host="${host%%/*}"
host_esc="$(regex_escape "$host")"

if [[ -n "${PROFILE:-}" ]]; then
prof_as_is="$(regex_escape "$PROFILE")"
prof_uscore="$(regex_escape "${PROFILE// /_}")"
WINDOW_PATTERN="(^| )(chrome|chromium|brave|vivaldi|microsoft-edge|google-chrome)-${host_esc}(__[^ ]*-)(${prof_as_is}|${prof_uscore})( |$)"
else
WINDOW_PATTERN="(^| )(chrome|chromium|brave|vivaldi|microsoft-edge|google-chrome)-${host_esc}(__[^ ]*)?( |$)"
fi

[[ "${DEBUG:-0}" = "1" ]] && echo "Pattern: $WINDOW_PATTERN" >&2

if WINDOW_ADDRESS="$(find_window_address "$WINDOW_PATTERN")" && [[ -n "$WINDOW_ADDRESS" ]]; then
hyprctl dispatch focuswindow "address:$WINDOW_ADDRESS"
exit 0
fi

if [[ -n "${PROFILE:-}" ]]; then
exec omarchy-launch-webapp "$APP_URL" "$PROFILE" "${EXTRA_FLAGS[@]}"
else
exec omarchy-launch-webapp "$APP_URL" "${EXTRA_FLAGS[@]}"
fi

if [[ -n $WINDOW_ADDRESS ]]; then
hyprctl dispatch focuswindow "address:$WINDOW_ADDRESS"
else
eval exec setsid $LAUNCH_COMMAND
fi
WINDOW_PATTERN="$arg1"

LAUNCH_COMMAND="${2:-"uwsm-app --app-id=org.omarchy.terminal -- $WINDOW_PATTERN"}"

if WINDOW_ADDRESS="$(find_window_address "$WINDOW_PATTERN")" && [[ -n "$WINDOW_ADDRESS" ]]; then
hyprctl dispatch focuswindow "address:$WINDOW_ADDRESS"
else
eval exec "$LAUNCH_COMMAND"
fi
fi
16 changes: 11 additions & 5 deletions bin/omarchy-launch-webapp
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash

# Launch the passed in URL as a web app in the default browser (or chromium if the default doesn't support --app).

browser=$(xdg-settings get default-web-browser)

case $browser in
google-chrome* | brave-browser* | microsoft-edge* | opera* | vivaldi* | helium*) ;;
*) browser="chromium.desktop" ;;
google-chrome* | brave-browser* | microsoft-edge* | opera* | vivaldi* | helium-browser*) ;;
*) browser="chromium.desktop" ;;
esac

exec setsid uwsm-app -- $(sed -n 's/^Exec=\([^ ]*\).*/\1/p' {~/.local,~/.nix-profile,/usr}/share/applications/$browser 2>/dev/null | head -1) --app="$1" "${@:2}"
DEFAULT_BROWSER_BIN="$(sed -n 's/^Exec=\([^ ]*\).*/\1/p' {~/.local,~/.nix-profile,/usr}/share/applications/$browser 2>/dev/null | head -1)"

APP_URL="$1"
PROFILE="${2:-Default}"
BROWSER_BIN="${3:-$DEFAULT_BROWSER_BIN}"

shift 3 || true

exec setsid uwsm app -- "$BROWSER_BIN" --profile-directory="$PROFILE" --app="$APP_URL" "$@"
7 changes: 7 additions & 0 deletions bin/omarchy-show-webapp-logo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

clear
echo -e '\033[32m'
cat ~/.local/share/omarchy/webapp-logo.txt
echo -e '\033[0m'
echo
116 changes: 93 additions & 23 deletions bin/omarchy-webapp-install

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new names

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct profile names.

Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/bin/bash

set -e
set -euo pipefail

ICON_DIR="$HOME/.local/share/applications/icons"

if (( $# < 3 )); then
echo -e "\e[32mLet's create a new web app you can start with the app launcher.\n\e[0m"
echo -e "\e[32mCreate a shortcut for your web app.\n\e[0m"

APP_NAME=$(gum input --prompt "Name> " --placeholder "My favorite web app")
APP_URL=$(gum input --prompt "URL> " --placeholder "https://example.com")
if [[ ! $APP_URL =~ ^[a-zA-Z][a-zA-Z0-9+.-]*: ]]; then
APP_URL="https://$APP_URL"
fi

# Try to fetch favicon automatically first.
FAVICON_URL="https://www.google.com/s2/favicons?domain=${APP_URL}&sz=128"
mkdir -p "$ICON_DIR"
if curl -fsSL -o "$ICON_DIR/$APP_NAME.png" "$FAVICON_URL" && [[ -s $ICON_DIR/$APP_NAME.png ]]; then

if curl -fsSL -o "$ICON_DIR/$APP_NAME.png" "$FAVICON_URL" && [[ -s "$ICON_DIR/$APP_NAME.png" ]]; then
ICON_REF="$APP_NAME.png"
else
ICON_REF=$(gum input --prompt "Icon URL> " --placeholder "Could not fetch favicon automatically. Enter PNG icon URL (see https://dashboardicons.com)")
ICON_REF=$(gum input --prompt "Icon URL> " --placeholder "Could not fetch favicon automatically. Enter PNG icon URL")
fi

CUSTOM_EXEC=""
Expand All @@ -31,59 +31,129 @@ else
APP_URL="https://$APP_URL"
fi
ICON_REF="$3"
CUSTOM_EXEC="$4" # Optional custom exec command
MIME_TYPES="$5" # Optional mime types
CUSTOM_EXEC="${4:-}"
MIME_TYPES="${5:-}"
INTERACTIVE_MODE=false
fi

# Ensure valid execution
if [[ -z $APP_NAME || -z $APP_URL ]]; then
echo "You must set app name and app URL!"
exit 1
fi

# Resolve icon from URL or from a local icon name.
mkdir -p "$ICON_DIR"
declare -A BROWSER_BINARIES=(
[Chromium]=chromium
[Google Chrome]=google-chrome-stable
[Brave]=brave
[Microsoft Edge]=microsoft-edge-stable
[Vivaldi]=vivaldi
[Helium]=helium-browser
[Opera]=opera
)

BROWSERS=()
for name in "${!BROWSER_BINARIES[@]}"; do
if command -v "${BROWSER_BINARIES[$name]}" >/dev/null 2>&1; then
BROWSERS+=("$name")
fi
done

if [ ${#BROWSERS[@]} -eq 0 ]; then
echo "No supported browsers found! Install Chrome, Brave, or Chromium."
exit 1
fi

BROWSER_CHOICE=$(gum choose --header "Which browser?" "${BROWSERS[@]}")
BROWSER_BIN="${BROWSER_BINARIES[$BROWSER_CHOICE]}"

declare -A BROWSER_CONFIG_DIRS=(
[Chromium]="$HOME/.config/chromium"
[Google Chrome]="$HOME/.config/google-chrome"
[Brave]="$HOME/.config/BraveSoftware/Brave-Browser"
[Microsoft Edge]="$HOME/.config/microsoft-edge"
[Vivaldi]="$HOME/.config/vivaldi"
[Helium]="$HOME/.config/net.imput.helium"
[Opera]="$HOME/.config/opera"
)

if [[ -z $ICON_REF ]]; then
ICON_REF="https://www.google.com/s2/favicons?domain=${APP_URL}&sz=128"
PROFILE_DIR="${BROWSER_CONFIG_DIRS[$BROWSER_CHOICE]:-$HOME/.config/$BROWSER_CHOICE}"

declare -A PROFILE_MAP
PROFILES=()

if [ -f "$PROFILE_DIR/Local State" ]; then
mapfile -t profile_data < <(jq -r '.profile.info_cache | to_entries[] | "\(.key)|\(.value.name)"' \
"$PROFILE_DIR/Local State" 2>/dev/null || true)
for line in "${profile_data[@]}"; do
IFS='|' read -r folder name <<<"$line"
name="${name:-$folder}"
[ -z "$name" ] && name="Default"
PROFILES+=("$name")
PROFILE_MAP["$name"]="$folder"
done
elif [ -d "$PROFILE_DIR" ]; then
for d in "$PROFILE_DIR"/Profile*; do
[[ -d "$d" ]] || continue
bn=$(basename "$d")
PROFILES+=("$bn")
PROFILE_MAP["$bn"]="$bn"
done
fi

if [ ${#PROFILES[@]} -eq 0 ]; then
PROFILES=("Default")
PROFILE_MAP["Default"]="Default"
fi

if [ ${#PROFILES[@]} -eq 1 ]; then
APP_PROFILE_NAME="${PROFILES[0]}"
else
APP_PROFILE_NAME=$(gum choose --header "Select browser profile for this WebApp" "${PROFILES[@]}")
fi

mkdir -p "$ICON_DIR"

if [[ $ICON_REF =~ ^https?:// ]]; then
ICON_PATH="$ICON_DIR/$APP_NAME.png"
if ! curl -fsSL -o "$ICON_PATH" "$ICON_REF" || [[ ! -s $ICON_PATH ]]; then
if ! curl -fsSL -o "$ICON_PATH" "$ICON_REF" || [[ ! -s "$ICON_PATH" ]]; then
echo "Error: Failed to download icon."
exit 1
fi
else
ICON_PATH="$ICON_DIR/$ICON_REF"
if [[ -f "$ICON_DIR/$ICON_REF" ]]; then
ICON_PATH="$ICON_DIR/$ICON_REF"
else
ICON_PATH="$ICON_REF"
fi
fi

# Use custom exec if provided, otherwise default behavior
EXEC_COMMAND="${CUSTOM_EXEC:-omarchy-launch-webapp $APP_URL}"
if [[ -n $CUSTOM_EXEC ]]; then
EXEC_COMMAND="$CUSTOM_EXEC"
else
EXEC_COMMAND="omarchy-launch-webapp \"$APP_URL\" \"${PROFILE_MAP[$APP_PROFILE_NAME]}\" \"$BROWSER_BIN\""
fi

# Create application .desktop file
DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop"

cat >"$DESKTOP_FILE" <<EOF
[Desktop Entry]
Version=1.0
Name=$APP_NAME
Comment=$APP_NAME
Comment=Web App: $APP_NAME
Exec=$EXEC_COMMAND
Terminal=false
Type=Application
Icon=$ICON_PATH
StartupNotify=true
Categories=Network;WebBrowser;
EOF

# Add mime types if provided
if [[ -n $MIME_TYPES ]]; then
echo "MimeType=$MIME_TYPES" >>"$DESKTOP_FILE"
fi

chmod +x "$DESKTOP_FILE"

if [[ $INTERACTIVE_MODE == "true" ]]; then
echo -e "You can now find $APP_NAME using the app launcher (SUPER + SPACE)\n"
fi
if [[ "$INTERACTIVE_MODE" == "true" ]]; then
echo -e "\n\e[32mSuccess!\e[0m You can now find \e[1m$APP_NAME\e[0m in your app launcher."
fi
9 changes: 9 additions & 0 deletions webapp-logo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
▄████████ ▄█ █▄ ▄████████ ▄██████▄ ▄▄▄▄███▄▄▄▄ ▄█ ███ █▄ ▄▄▄▄███▄▄▄▄
███ ███ ███ ███ ███ ███ ███ ███ ▄██▀▀▀███▀▀▀██▄ ███ ███ ███ ▄██▀▀▀███▀▀▀██▄
███ █▀ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███▌ ███ ███ ███ ███ ███
███ ▄███▄▄▄▄███▄▄ ▄███▄▄▄▄██▀ ███ ███ ███ ███ ███ ███▌ ███ ███ ███ ███ ███
███ ▀▀███▀▀▀▀███▀ ▀▀███▀▀▀▀▀ ███ ███ ███ ███ ███ ███▌ ███ ███ ███ ███ ███
███ █▄ ███ ███ ▀███████████ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ███
████████▀ ███ █▀ ███ ███ ▀██████▀ ▀█ ███ █▀ █▀ ████████▀ ▀█ ███ █▀
███ ███