Skip to content

Commit b222662

Browse files
committed
Update script pour web-app
1 parent 4ab6cf2 commit b222662

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

common/bin/omarchy-launch-webapp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
browser=$(xdg-settings get default-web-browser)
4+
5+
case $browser in
6+
google-chrome* | brave-browser* | microsoft-edge* | opera* | vivaldi*) ;;
7+
*) browser="chromium.desktop" ;;
8+
esac
9+
10+
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}"

common/bin/omarchy-webapp-install

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,69 @@
11
#!/bin/bash
22

3-
if [ "$#" -ne 3 ]; then
3+
if [ "$#" -lt 3 ]; then
44
echo -e "\e[32mLet's create a new web app you can start with the app launcher.\n\e[0m"
55
APP_NAME=$(gum input --prompt "Name> " --placeholder "My favorite web app")
66
APP_URL=$(gum input --prompt "URL> " --placeholder "https://example.com")
7-
ICON_URL=$(gum input --prompt "Icon URL> " --placeholder "See https://dashboardicons.com (must use PNG!)")
7+
ICON_REF=$(gum input --prompt "Icon URL> " --placeholder "See https://dashboardicons.com (must use PNG!)")
8+
CUSTOM_EXEC=""
9+
MIME_TYPES=""
10+
INTERACTIVE_MODE=true
811
else
912
APP_NAME="$1"
1013
APP_URL="$2"
11-
ICON_URL="$3"
14+
ICON_REF="$3"
15+
CUSTOM_EXEC="$4" # Optional custom exec command
16+
MIME_TYPES="$5" # Optional mime types
17+
INTERACTIVE_MODE=false
1218
fi
1319

14-
if [[ -z "$APP_NAME" || -z "$APP_URL" || -z "$ICON_URL" ]]; then
20+
# Ensure valid execution
21+
if [[ -z "$APP_NAME" || -z "$APP_URL" || -z "$ICON_REF" ]]; then
1522
echo "You must set app name, app URL, and icon URL!"
1623
exit 1
1724
fi
1825

19-
ICON_DIR="$HOME/.local/share/applications/icons"
20-
DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop"
21-
ICON_PATH="$ICON_DIR/$APP_NAME.png"
22-
23-
mkdir -p "$ICON_DIR"
26+
# Refer to local icon or fetch remotely from URL
27+
if [[ $ICON_REF =~ ^https?:// ]]; then
28+
if curl -sL -o "$ICON_PATH" "$ICON_REF"; then
29+
ICON_PATH="$ICON_DIR/$APP_NAME.png"
30+
else
31+
echo "Error: Failed to download icon."
32+
exit 1
33+
fi
34+
else
35+
ICON_PATH="$HOME/.local/share/applications/icons/$ICON_REF"
36+
fi
2437

25-
if ! curl -sL -o "$ICON_PATH" "$ICON_URL"; then
26-
echo "Error: Failed to download icon."
27-
return 1
38+
# Use custom exec if provided, otherwise default behavior
39+
if [[ -n $CUSTOM_EXEC ]]; then
40+
EXEC_COMMAND="$CUSTOM_EXEC"
41+
else
42+
EXEC_COMMAND="google-chrome-stable --new-window --ozone-platform=wayland --app=$APP_URL --name=$APP_NAME --class=$APP_NAME"
2843
fi
2944

45+
# Create application .desktop file
46+
DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop"
47+
3048
cat >"$DESKTOP_FILE" <<EOF
3149
[Desktop Entry]
3250
Version=1.0
3351
Name=$APP_NAME
3452
Comment=$APP_NAME
35-
Exec=google-chrome-stable --new-window --ozone-platform=wayland --app="$APP_URL" --name="$APP_NAME" --class="$APP_NAME"
53+
Exec=$EXEC_COMMAND
3654
Terminal=false
3755
Type=Application
3856
Icon=$ICON_PATH
3957
StartupNotify=true
4058
EOF
4159

60+
# Add mime types if provided
61+
if [[ -n $MIME_TYPES ]]; then
62+
echo "MimeType=$MIME_TYPES" >>"$DESKTOP_FILE"
63+
fi
64+
4265
chmod +x "$DESKTOP_FILE"
4366

44-
if [ "$#" -ne 3 ]; then
67+
if [[ $INTERACTIVE_MODE == true ]]; then
4568
echo -e "You can now find $APP_NAME using the app launcher (SUPER + SPACE)\n"
4669
fi

0 commit comments

Comments
 (0)