From 96a81d7e5beda77f5c0df243aabbf83405d88a3d Mon Sep 17 00:00:00 2001 From: matt1432 Date: Wed, 9 Aug 2023 22:11:09 -0400 Subject: [PATCH] feat(eww): make some scripts always run at start. make bluetooth state persistent --- config/eww/scripts/bluetooth.sh | 7 ++-- config/eww/scripts/heart.sh | 44 ++++++++++++++++++------- config/eww/traybuttons/traybuttons.yuck | 4 +-- config/eww/variables.yuck | 4 ++- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/config/eww/scripts/bluetooth.sh b/config/eww/scripts/bluetooth.sh index b000c9bb..6a50e292 100755 --- a/config/eww/scripts/bluetooth.sh +++ b/config/eww/scripts/bluetooth.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +FILE="$HOME/.config/.bluetooth" + get_device() { if [[ $(bluetoothctl devices Connected) != "" ]]; then bluetoothctl devices Connected | awk '{ for (i = 3; i <= NF; i++) { printf("%s ", $i) } printf("\n") }' @@ -10,9 +12,9 @@ get_device() { get_state() { if [[ "$(rfkill list | grep -A 1 hci0 | grep -o no)" == "no" ]]; then - echo " 󰂯 " + echo " 󰂯 " > "$FILE" else - echo " 󰂲 " + echo " 󰂲 " > "$FILE" fi } @@ -23,5 +25,6 @@ if [[ $1 == "icon" ]]; then while true; do sleep 0.1 get_state + tail "$FILE" done fi diff --git a/config/eww/scripts/heart.sh b/config/eww/scripts/heart.sh index c39f790f..3cdb2084 100755 --- a/config/eww/scripts/heart.sh +++ b/config/eww/scripts/heart.sh @@ -1,16 +1,36 @@ #!/usr/bin/env bash FILE="$HOME/.config/.heart" -if [[ ! -f "$FILE" ]]; then - echo 󰣐 > "$FILE" -fi -if grep -q 󰣐 "$FILE"; then - eww close heart - eww update heart-ts=false - echo  > "$FILE" -else - eww open heart - eww update heart-ts=true - echo 󰣐 >> "$FILE" -fi +toggle() { + if grep -q 󰣐 "$FILE"; then + eww close heart + eww update heart-ts=false + echo  > "$FILE" + else + eww open heart + eww update heart-ts=true + echo 󰣐 >> "$FILE" + fi +} + +[[ "$1" == "toggle" ]] && toggle + + +startup() { + if [[ ! -f "$FILE" ]]; then + echo 󰣐 > "$FILE" + fi + + if [[ ! -f "$HOME/.config/.bluetooth" ]]; then + echo 󰂲 > "$FILE" + fi + + if grep -q 󰂲 "$HOME/.config/.bluetooth"; then + rfkill block bluetooth + fi + + tail -f "$FILE" +} + +[[ "$1" == "startup" ]] && startup diff --git a/config/eww/traybuttons/traybuttons.yuck b/config/eww/traybuttons/traybuttons.yuck index ff741fe0..4972c196 100644 --- a/config/eww/traybuttons/traybuttons.yuck +++ b/config/eww/traybuttons/traybuttons.yuck @@ -92,7 +92,7 @@ (defvar heart-ts "default") (defwidget heart-toggle-on [] (eventbox :class "toggle-on" - :onclick "$EWW_PATH/heart.sh" + :onclick "$EWW_PATH/heart.sh toggle" :cursor "pointer" (box :class "heart-toggle" @@ -103,7 +103,7 @@ ) (defwidget heart-toggle-off [] (eventbox :class "toggle-off" - :onclick "$EWW_PATH/heart.sh" + :onclick "$EWW_PATH/heart.sh toggle" :cursor "pointer" (box :class "heart-toggle" diff --git a/config/eww/variables.yuck b/config/eww/variables.yuck index b5e22df8..ef211919 100644 --- a/config/eww/variables.yuck +++ b/config/eww/variables.yuck @@ -1,5 +1,7 @@ +; this var starts all scripts needed when eww boots +(deflisten heart_icon "$EWW_PATH/heart.sh startup") + (deflisten notif_icon "$EWW_PATH/notif.sh icon") -(deflisten heart_icon "tail -f $HOME/.config/.heart") (deflisten mic_icon "$EWW_PATH/mic.sh icon") (deflisten network_ssid "zscroll -d 0.7 -l 12 -p '. ' -u true \"$EWW_PATH/network.sh ssid\"")