feat: watcher util

This commit is contained in:
hesam-init 2024-04-04 04:00:58 +03:30
parent 24badb6a3b
commit bfc579c07e
7 changed files with 141 additions and 41 deletions

View file

@ -7,7 +7,9 @@ exec-once = dbus-update-activation-environment --all &
exec-once = ~/.config/scripts/pipewire.sh &
exec-once = ~/.config/hypr/scripts/keyring-launch.sh &
exec-once = wl-paste --watch cliphist store &
exec-once = avizo-service &
exec-once = swayosd-server &
# exec-once = avizo-service &
# wallpaper :
exec-once = ~/.config/hypr/scripts/wallpaper-daemon.sh &

View file

@ -44,9 +44,9 @@ bind = $mainMod, Y, exec, $random_wallpaper
bind = $mainMod, I, exec, $kill_wallpaper_daemon
# Audio control
binde=, XF86AudioRaiseVolume, exec, volumectl -u up
binde=, XF86AudioLowerVolume, exec, volumectl -u down
bind=, XF86AudioMute, exec, volumectl toggle-mute
binde=, XF86AudioRaiseVolume, exec, swayosd-client --output-volume raise
binde=, XF86AudioLowerVolume, exec, swayosd-client --output-volume lower
bind=, XF86AudioMute, exec, swayosd-client --output-volume mute-toggle
bind=, XF86AudioPlay, exec, playerctl play-pause
bind=, XF86AudioPrev, exec, playerctl previous
bind=, XF86AudioNext, exec, playerctl next

View file

@ -0,0 +1,41 @@
#!/usr/bin/env bash
source ~/.config/scripts/env.sh
if [[ ! -d "$WAYBAR_DIR" ]]; then
echo "Error: Configuration directory or files missing!"
exit 1
fi
pkill waybar
sleep 1
while true; do
logger -i "$0: Starting waybar in the background..."
exec $WAYBAR_LAUNCHER &
waybar_pid=$!
logger -i "$0: Started waybar PID=$waybar_pid. Waiting for modifications..."
inotifywait $WAYBAR_INOTIFY_EVENTS "$WAYBAR_DIR" 2>&1 | logger -i
if [[ $? -ne 0 ]]; then
echo "Error: inotifywait failed!"
exit 1
fi
logger -i "$0: inotifywait returned $?. Killing all waybar processes..."
pkill waybar 2>&1 | logger -i
if [[ $? -ne 0 ]]; then
echo "Error: Killing waybar failed!"
exit 1
fi
wait $waybar_pid
if [[ $? -ne 0 ]]; then
echo "Warning: Waybar process exited unexpectedly!"
fi
logger -i "$0: killall waybar returned $?. Wait a sec..."
done

View file

@ -2,39 +2,4 @@
source ~/.config/scripts/env.sh
if [[ ! -d "$WAYBAR_DIR" ]]; then
echo "Error: Configuration directory or files missing!"
exit 1
fi
pkill waybar
sleep 1
while true; do
logger -i "$0: Starting waybar in the background..."
exec $WAYBAR_LAUNCHER &
waybar_pid=$!
logger -i "$0: Started waybar PID=$waybar_pid. Waiting for modifications..."
inotifywait $WAYBAR_INOTIFY_EVENTS "$WAYBAR_DIR" 2>&1 | logger -i
if [[ $? -ne 0 ]]; then
echo "Error: inotifywait failed!"
exit 1
fi
logger -i "$0: inotifywait returned $?. Killing all waybar processes..."
pkill waybar 2>&1 | logger -i
if [[ $? -ne 0 ]]; then
echo "Error: Killing waybar failed!"
exit 1
fi
wait $waybar_pid
if [[ $? -ne 0 ]]; then
echo "Warning: Waybar process exited unexpectedly!"
fi
logger -i "$0: killall waybar returned $?. Wait a sec..."
done
exec $WATCHER -a "$WAYBAR_LAUNCHER" -d "$WAYBAR_DIR" -p "waybar"

View file

@ -1,11 +1,13 @@
#!/usr/bin/env bash
# utils shell :
export WATCHER="$HOME/.config/scripts/utils/watcher/main.sh"
# waybar env :
export WAYBAR_DEV_MODE=false
export WAYBAR_THEME="river"
export WAYBAR_DIR="$HOME/.config/waybar/$WAYBAR_THEME"
export WAYBAR_LAUNCHER="waybar -c $WAYBAR_DIR/config.jsonc -s $WAYBAR_DIR/style.css"
export WAYBAR_INOTIFY_EVENTS="-e close_write,move,create"
# wallpaper configs - swaybg, swww, mpvpaper :
export WALLPAPER_DAEMON="swaybg"

View file

@ -0,0 +1,48 @@
#!/usr/bin/env bash
usage() {
echo "Usage: $0 -a <application_name> -d <directory_to_watch> -p <process_name>"
exit 1
}
while getopts ":a:d:p:" opt; do
case $opt in
p) process_name="$OPTARG" ;;
a) app_name="$OPTARG" ;;
d) watch_dir="$OPTARG" ;;
*) usage ;;
esac
done
if [[ -z $app_name || -z $watch_dir || -z $process_name ]]; then
usage
fi
if [[ ! -d $watch_dir ]]; then
echo "Error: Directory $watch_dir does not exist!"
exit 1
fi
start_application() {
echo "Starting $process_name..."
pkill $process_name
sleep 1
exec $app_name
}
restart_application() {
if pgrep -x "$process_name" >/dev/null; then
echo "Restarting $process_name..."
pkill $process_name
sleep 1
$app_name &
else
echo "$app_name is not currently running."
fi
}
start_application &
inotifywait -q -m -r -e modify,delete,create "$watch_dir" | while read DIRECTORY EVENT FILE; do
restart_application
done

View file

@ -0,0 +1,42 @@
window#osd {
padding: 12px 20px;
border-radius: 120px;
border: none;
background: alpha(@theme_bg_color, 0.8);
}
window#osd #container {
margin: 16px;
}
window#osd image,
window#osd label {
color: @theme_fg_color;
}
window#osd progressbar:disabled,
window#osd image:disabled {
opacity: 0.5;
}
window#osd progressbar {
transition: all ease-in-out 0.5s;
min-height: 6px;
border-radius: 999px;
background: transparent;
border: none;
}
window#osd trough {
min-height: inherit;
border-radius: inherit;
border: none;
background: alpha(@theme_fg_color, 0.5);
}
window#osd progress {
min-height: inherit;
border-radius: inherit;
border: none;
background: @theme_fg_color;
}