From e1a41976707e7173c41822ab12be343e5763a514 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sun, 26 May 2024 17:06:19 +0200 Subject: add webtrayctl --- Makefile | 1 + webtrayctl | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 webtrayctl 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 [--open-at-startup]" + echo " uninstall " + 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 -- cgit v1.2.3-70-g09d2