aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-05-26 17:06:19 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2024-05-26 17:06:19 +0200
commite1a41976707e7173c41822ab12be343e5763a514 (patch)
treea230e2ebafc3f1e96c4d24096f95c17f545ae930
parentfc90e6f2d49a807f4c869100b18e1e8202c639e9 (diff)
add webtrayctl
-rw-r--r--Makefile1
-rwxr-xr-xwebtrayctl57
2 files changed, 58 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 358472e..2c984e1 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,7 @@ clean:
install:
install ./target/webtray ${DESTDIR}/usr/bin/webtray
+ install ./webtrayctl ${DESTDIR}/usr/bin/webtrayctl
.PHONY: build install
diff --git a/webtrayctl b/webtrayctl
new file mode 100755
index 0000000..3e94be2
--- /dev/null
+++ b/webtrayctl
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+help() {
+ echo webtrayctl - install and remove webtray applications
+ echo
+ echo " install <url> <name> [--open-at-startup]"
+ echo " uninstall <name>"
+ echo
+ exit
+}
+
+install_webapp() {
+ mkdir -p ~/.local/share/webtray/icons
+ mkdir -p ~/.local/share/webtray/applications/
+
+ url="$1"
+ name="$2"
+ extra="$3"
+
+ tmp_icon_name="$name-$$.ico"
+
+ curl -s "$url/$(curl -s "$url" | grep 'rel="[^"]*icon.*\.ico' | sed 's/^.*href="\([^"]*\)".*/\1/g')" --output "/tmp/$tmp_icon_name"
+
+ magick "/tmp/${tmp_icon_name}[0]" -flatten "$HOME/.local/share/webtray/icons/$name.png"
+
+ echo "[Desktop Entry]
+Type=Application
+Name=$name
+Exec=$(which webtray) '$url' $extra
+Icon=$HOME/.local/share/webtray/icons/$name.png
+Terminal=false
+Categories=WebApp
+" > "$HOME/.local/share/webtray/applications/webtray-$name.desktop"
+
+ xdg-desktop-menu install "$HOME/.local/share/webtray/applications/webtray-$name.desktop"
+
+ rm "/tmp/$tmp_icon_name"
+}
+
+remove_webapp() {
+ name="$1"
+ xdg-desktop-menu uninstall "$HOME/.local/share/webtray/applications/webtray-$name.desktop"
+ rm "$HOME/.local/share/webtray/applications/$name.desktop" "$HOME/.local/share/webtray/icons/$name.png"
+}
+
+
+case "$1" in
+ install)
+ [ -z "$2" -o -z "$3" ] && help
+ install_webapp "$2" "$3"
+ ;;
+ uninstall)
+ [ -z "$2" ] && help
+ remove_webapp "$2"
+ ;;
+ *)help;;
+esac