From 47c12a688881edd1e56c7ff6a88a71586e879ec2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 21 Feb 2026 09:14:48 +0100 Subject: [PATCH] Only ask for icon URL if we can't get a favicon --- bin/omarchy-webapp-install | 42 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/bin/omarchy-webapp-install b/bin/omarchy-webapp-install index 85c8bc81..3b649ca2 100755 --- a/bin/omarchy-webapp-install +++ b/bin/omarchy-webapp-install @@ -2,11 +2,22 @@ set -e -if [ "$#" -lt 3 ]; then +ICON_DIR="$HOME/.local/share/applications/icons" + +if [[ $# -lt 3 ]]; 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 "Leave blank to use favicon or see https://dashboardicons.com (must be PNG!)") + + # 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 + 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)") + fi + CUSTOM_EXEC="" MIME_TYPES="" INTERACTIVE_MODE=true @@ -19,23 +30,22 @@ else INTERACTIVE_MODE=false fi -if [[ -z "$ICON_REF" ]]; then - ICON_REF="https://www.google.com/s2/favicons?domain=${APP_URL}&sz=128" -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 -ICON_DIR="$HOME/.local/share/applications/icons" +# Resolve icon from URL or from a local icon name. +mkdir -p "$ICON_DIR" + +if [[ -z $ICON_REF ]]; then + ICON_REF="https://www.google.com/s2/favicons?domain=${APP_URL}&sz=128" +fi + 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 + if ! curl -fsSL -o "$ICON_PATH" "$ICON_REF" || [[ ! -s $ICON_PATH ]]; then echo "Error: Failed to download icon." exit 1 fi @@ -44,11 +54,7 @@ else fi # Use custom exec if provided, otherwise default behavior -if [[ -n $CUSTOM_EXEC ]]; then - EXEC_COMMAND="$CUSTOM_EXEC" -else - EXEC_COMMAND="omarchy-launch-webapp $APP_URL" -fi +EXEC_COMMAND="${CUSTOM_EXEC:-omarchy-launch-webapp $APP_URL}" # Create application .desktop file DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop"