|
| 1 | +#!/bin/bash |
| 2 | +if [[ -z "$BROWSER" ]]; then |
| 3 | + DEFAULT_BROWSER_DESKTOP=$(xdg-settings get default-web-browser 2>/dev/null) |
| 4 | + |
| 5 | + if [[ -n "$DEFAULT_BROWSER_DESKTOP" ]]; then |
| 6 | + # Extract the Exec line from the .desktop file |
| 7 | + if [[ -f "/usr/share/applications/$DEFAULT_BROWSER_DESKTOP" ]]; then |
| 8 | + BROWSER_EXEC=$(grep -m1 '^Exec=' "/usr/share/applications/$DEFAULT_BROWSER_DESKTOP") |
| 9 | + elif [[ -f "$HOME/.local/share/applications/$DEFAULT_BROWSER_DESKTOP" ]]; then |
| 10 | + BROWSER_EXEC=$(grep -m1 '^Exec=' "$HOME/.local/share/applications/$DEFAULT_BROWSER_DESKTOP") |
| 11 | + fi |
| 12 | + |
| 13 | + # Clean up the Exec command (strip placeholders like %u, %U) |
| 14 | + BROWSER=$(echo "$BROWSER_EXEC" | sed -E 's/^Exec=//' | sed -E 's/ ?%[a-zA-Z]//g') |
| 15 | + fi |
| 16 | + |
| 17 | + # If we couldn't detect it from .desktop, try common fallbacks |
| 18 | + for candidate in brave chromium google-chrome firefox; do |
| 19 | + if command -v $candidate >/dev/null && [[ -z "$BROWSER" ]]; then |
| 20 | + BROWSER=$candidate |
| 21 | + fi |
| 22 | + done |
| 23 | + |
| 24 | + # Final fallback |
| 25 | + export BROWSER="${BROWSER:-xdg-open}" |
| 26 | +fi |
| 27 | + |
| 28 | +# Create a desktop launcher for a web app |
| 29 | +web2app() { |
| 30 | + if [ "$#" -ne 3 ]; then |
| 31 | + echo "Usage: web2app <AppName> <AppURL> <IconURL> (IconURL must be in PNG -- use https://dashboardicons.com)" |
| 32 | + return 1 |
| 33 | + fi |
| 34 | + |
| 35 | + local APP_NAME="$1" |
| 36 | + local APP_URL="$2" |
| 37 | + local ICON_URL="$3" |
| 38 | + local ICON_DIR="$HOME/.local/share/applications/icons" |
| 39 | + local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop" |
| 40 | + local ICON_PATH="${ICON_DIR}/${APP_NAME}.png" |
| 41 | + |
| 42 | + mkdir -p "$ICON_DIR" |
| 43 | + |
| 44 | + if ! curl -sL -o "$ICON_PATH" "$ICON_URL"; then |
| 45 | + echo "Error: Failed to download icon." |
| 46 | + return 1 |
| 47 | + fi |
| 48 | + |
| 49 | + cat >"$DESKTOP_FILE" <<EOF |
| 50 | +[Desktop Entry] |
| 51 | +Version=1.0 |
| 52 | +Name=$APP_NAME |
| 53 | +Comment=$APP_NAME |
| 54 | +Exec=$BROWSER --new-window --ozone-platform=wayland --app="$APP_URL" --name="$APP_NAME" --class="$APP_NAME" |
| 55 | +Terminal=false |
| 56 | +Type=Application |
| 57 | +Icon=$ICON_PATH |
| 58 | +StartupNotify=true |
| 59 | +EOF |
| 60 | + |
| 61 | + chmod +x "$DESKTOP_FILE" |
| 62 | +} |
| 63 | + |
| 64 | +web2app-remove() { |
| 65 | + if [ "$#" -ne 1 ]; then |
| 66 | + echo "Usage: web2app-remove <AppName>" |
| 67 | + return 1 |
| 68 | + fi |
| 69 | + |
| 70 | + local APP_NAME="$1" |
| 71 | + local ICON_DIR="$HOME/.local/share/applications/icons" |
| 72 | + local DESKTOP_FILE="$HOME/.local/share/applications/${APP_NAME}.desktop" |
| 73 | + local ICON_PATH="${ICON_DIR}/${APP_NAME}.png" |
| 74 | + |
| 75 | + rm "$DESKTOP_FILE" |
| 76 | + rm "$ICON_PATH" |
| 77 | +} |
| 78 | + |
| 79 | +web2app "Twitter" https://x.com/ https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/x-light.png |
| 80 | +web2app "ChatGPT" https://chatgpt.com/ https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/chatgpt.png |
| 81 | +web2app "Google Messages" https://messages.google.com/web/conversations https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/google-messages.png |
| 82 | +web2app "Frigate" https://frigate.wayl.one/ https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/frigate.png |
| 83 | +web2app "reader" https://reader.waylonwalker.com/ https://waylonwalker.com/8bitcc.png |
0 commit comments