diff --git a/bin/omarchy-icon-dl b/bin/omarchy-icon-dl new file mode 100755 index 0000000000..f1a7c0f532 --- /dev/null +++ b/bin/omarchy-icon-dl @@ -0,0 +1,38 @@ +#!/bin/bash + +ICON_URL="$1" +OUTPUT_PATH="$2" + +if [[ -z "$ICON_URL" || -z "$OUTPUT_PATH" ]]; then + echo "Usage: omarchy-icon-dl " + exit 1 +fi + +ICON_DIR="$(dirname "$OUTPUT_PATH")" +mkdir -p "$ICON_DIR" + +# Extract extension from URL +EXT=$(echo "${ICON_URL##*.}" | sed 's/\?.*//' | tr '[:upper:]' '[:lower:]') +SOURCE_ICON="/tmp/icon_download_$$_${RANDOM}.${EXT}" + +# Download icon +if curl -sL -o "$SOURCE_ICON" "$ICON_URL" 2>/dev/null; then + if [[ "$EXT" == "png" ]]; then + mv "$SOURCE_ICON" "$OUTPUT_PATH" + else + # Find largest resolution index for multi-resolution formats + LARGEST_IDX=$(magick identify "$SOURCE_ICON" 2>/dev/null | awk '{split($3, a, "x"); size=a[1]*a[2]; if(size>max){max=size; idx=NR-1}} END{print idx}') + + # Convert to PNG + magick "$SOURCE_ICON[${LARGEST_IDX:-0}]" "$OUTPUT_PATH" 2>/dev/null || \ + magick "$SOURCE_ICON[${LARGEST_IDX:-0}]" -flatten "$OUTPUT_PATH" 2>/dev/null || { + echo "Error: Could not convert icon to PNG." + rm -f "$SOURCE_ICON" + exit 1 + } + rm -f "$SOURCE_ICON" + fi +else + echo "Error: Failed to download icon from $ICON_URL" + exit 1 +fi diff --git a/bin/omarchy-tui-install b/bin/omarchy-tui-install index 916db6545b..fef34c6c31 100755 --- a/bin/omarchy-tui-install +++ b/bin/omarchy-tui-install @@ -5,7 +5,7 @@ if [ "$#" -ne 4 ]; then APP_NAME=$(gum input --prompt "Name> " --placeholder "My TUI") APP_EXEC=$(gum input --prompt "Launch Command> " --placeholder "lazydocker or bash -c 'dust; read -n 1 -s'") WINDOW_STYLE=$(gum choose --header "Window style" float tile) - ICON_URL=$(gum input --prompt "Icon URL> " --placeholder "See https://dashboardicons.com (must use PNG!)") + ICON_URL=$(gum input --prompt "Icon URL> " --placeholder "See https://dashboardicons.com") else APP_NAME="$1" APP_EXEC="$2" @@ -23,13 +23,9 @@ DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop" if [[ ! "$ICON_URL" =~ ^https?:// ]] && [ -f "$ICON_URL" ]; then ICON_PATH="$ICON_URL" -else +elif [[ "$ICON_URL" =~ ^https?:// ]]; then ICON_PATH="$ICON_DIR/$APP_NAME.png" - mkdir -p "$ICON_DIR" - if ! curl -sL -o "$ICON_PATH" "$ICON_URL"; then - echo "Error: Failed to download icon." - exit 1 - fi + omarchy-icon-dl "$ICON_URL" "$ICON_PATH" || exit 1 fi if [[ $WINDOW_STYLE == "float" ]]; then diff --git a/bin/omarchy-webapp-install b/bin/omarchy-webapp-install index e954e842c7..a7e147ec43 100755 --- a/bin/omarchy-webapp-install +++ b/bin/omarchy-webapp-install @@ -1,10 +1,10 @@ #!/bin/bash -if [ "$#" -lt 3 ]; then +if [ "$#" -lt 2 ]; then echo -e "\e[32mLet's create a new web app you can start with the app launcher.\n\e[0m" APP_NAME=$(gum input --prompt "Name> " --placeholder "My favorite web app") APP_URL=$(gum input --prompt "URL> " --placeholder "https://example.com") - ICON_REF=$(gum input --prompt "Icon URL> " --placeholder "See https://dashboardicons.com (must use PNG!)") + ICON_REF=$(gum input --prompt "Icon URL> " --placeholder "URL or leave blank for auto-detection") CUSTOM_EXEC="" MIME_TYPES="" INTERACTIVE_MODE=true @@ -18,21 +18,28 @@ else fi # Ensure valid execution -if [[ -z "$APP_NAME" || -z "$APP_URL" || -z "$ICON_REF" ]]; then - echo "You must set app name, app URL, and icon URL!" +if [[ -z "$APP_NAME" || -z "$APP_URL" ]]; then + echo "You must set app name and app URL!" exit 1 fi -# Refer to local icon or fetch remotely from URL +# Normalize APP_URL - add https:// if no protocol specified +if [[ ! "$APP_URL" =~ ^https?:// ]]; then + APP_URL="https://$APP_URL" +fi + +# Auto-detect icon from google favicons if ICON_REF is empty +if [[ -z "$ICON_REF" ]]; then + DOMAIN=$(echo "$APP_URL" | sed -E 's#^https?://([^/]+).*#\1#') + ICON_REF="https://www.google.com/s2/favicons?domain=${DOMAIN}&sz=128" +fi + +# Download and convert icon ICON_DIR="$HOME/.local/share/applications/icons" + if [[ $ICON_REF =~ ^https?:// ]]; then ICON_PATH="$ICON_DIR/$APP_NAME.png" - if curl -sL -o "$ICON_PATH" "$ICON_REF"; then - ICON_PATH="$ICON_DIR/$APP_NAME.png" - else - echo "Error: Failed to download icon." - exit 1 - fi + omarchy-icon-dl "$ICON_REF" "$ICON_PATH" || exit 1 else ICON_PATH="$ICON_DIR/$ICON_REF" fi