From adf8b7d9ba1ecda4cc32d387274ca3b7ac5b0f9c Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Sat, 7 Dec 2024 16:42:49 -0300 Subject: [PATCH] :sparkles: eww(bar,cc): add a lot of scripts and modify existing --- eww/scripts/get-volume-watch.sh | 25 ++++++++++++ eww/scripts/mediaplayer.py | 3 +- eww/scripts/notification-history.sh | 10 +++++ eww/scripts/notification-watcher.py | 61 +++++++++++++++++++++++++++++ eww/scripts/volume.sh | 39 ------------------ 5 files changed, 98 insertions(+), 40 deletions(-) create mode 100644 eww/scripts/get-volume-watch.sh create mode 100644 eww/scripts/notification-history.sh create mode 100644 eww/scripts/notification-watcher.py delete mode 100644 eww/scripts/volume.sh diff --git a/eww/scripts/get-volume-watch.sh b/eww/scripts/get-volume-watch.sh new file mode 100644 index 0000000..aec5618 --- /dev/null +++ b/eww/scripts/get-volume-watch.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +sink_="@DEFAULT_AUDIO_SINK@" +source_="@DEFAULT_AUDIO_SOURCE@" + +print_json() { + echo "{ \"output\": $output_vol, \"source\": $source_vol }" +} + +get_vol() { + echo $(wpctl get-volume $1 | awk "{print int(\$2*100)}") +} + +output_vol=$(get_vol $sink_) +source_vol=$(get_vol $source_) + +print_json + +pactl subscribe | grep --line-buffered -e "on sink" -e "on source" | while read -r; do + + output_vol=$(get_vol $sink_) + source_vol=$(get_vol $source_) + + print_json +done diff --git a/eww/scripts/mediaplayer.py b/eww/scripts/mediaplayer.py index 13137f7..fea40b8 100755 --- a/eww/scripts/mediaplayer.py +++ b/eww/scripts/mediaplayer.py @@ -133,7 +133,8 @@ class PlayerManager: "status": player.props.status.lower(), "title": player.get_title(), "artist": player.get_artist(), - "player": player.props.player_name.lower() + "player": player.props.player_name.lower(), + "artUrl": player.print_metadata_prop("mpris:artUrl") } sys.stdout.write(json.dumps(output) + "\n") diff --git a/eww/scripts/notification-history.sh b/eww/scripts/notification-history.sh new file mode 100644 index 0000000..e75ce41 --- /dev/null +++ b/eww/scripts/notification-history.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +prev_history=$(dunstctl history) + +while true; do + if ! [[ $prev_history == $(dunstctl history) ]]; then + prev_history=$(dunstctl history) + echo "$(echo $prev_history | jq -c '.data.[]')" + fi +done diff --git a/eww/scripts/notification-watcher.py b/eww/scripts/notification-watcher.py new file mode 100644 index 0000000..69566e3 --- /dev/null +++ b/eww/scripts/notification-watcher.py @@ -0,0 +1,61 @@ +# Original Script by vimjoyer, modified by retrozinndev +# Licensed under the MIT License, as in vimjoyer's repository and also in retrozinndev's Hyprland Dots. + +import dbus +import dbus.service +from dbus.mainloop.glib import DBusGMainLoop +from gi.repository import GLib +import threading +import time + +class Notification: + def __init__(self, app_name, summary, body, icon): + self.app_name = app_name + self.summary = summary + self.body = body + self.icon = icon + +notifications = [] + +def remove_notification(notification): + time.sleep(10) + notifications.remove(notification) + reload_output() + +def add_notification(notification): + notifications.insert(0, notification) + reload_output() + timer_thread = threading.Thread(target=remove_notification, args=(notification,)) + timer_thread.start() + +def reload_output(): + + output = "" + for notification in notifications: + output = "aaaaaaaa" + + output.replace('\n', ' ') + print(f"{ output }", flush=True) + + +class NotificationServer(dbus.service.Object): + def __init__(self): + bus_name = dbus.service.BusName("org.freedesktop.Notifications", bus=dbus.SessionBus()) + dbus.service.Object.__init__(self, bus_name, "/org/freedesktop/Notifications") + + @dbus.service.method("org.freedesktop.Notifications", in_signature="susssasa{ss}i", out_signature="u") + def Notify(self, app_name, replaces_id, app_icon, summary, body, actions, hints, timeout): + add_notification(Notification(app_name, summary, body, app_icon)) + return 0 + + @dbus.service.method("org.freedesktop.Notifications", out_signature="ssss") + def GetServerInformation(self): + return ("Custom Notification Server", "ExampleNS", "1.0", "1.2") + + +DBusGMainLoop(set_as_default=True) + +if __name__ == "__main__": + server = NotificationServer() + mainloop = GLib.MainLoop() + mainloop.run() diff --git a/eww/scripts/volume.sh b/eww/scripts/volume.sh deleted file mode 100644 index 192d94c..0000000 --- a/eww/scripts/volume.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -default_value="5" -audio_sink="@DEFAULT_AUDIO_SINK@" -current_volume=$(wpctl get-volume $audio_sink) - - -get_volume() { - echo $(wpctl get-volume $audio_sink) -} - -get_json_loop() { - while true; do - if ! [[ $current_volume == get_volume ]]; then - echo "{ \"volume\": $(translate_volume $current_volume) }" - current_volume=$(get_volume) - fi - done -} - -set_volume() { - wpctl set-volume $audio_sink $1 -} - -translate_volume() { - echo "$($1 | sed -e 's/Volume: //' -e 's/^1\./1/' -e 's/^0.//' -e 's/^00/0/')" -} - -increase_vol() { - if (($(translate_volume $current_volume)+$default_value >= 100)); then - set_volume "1.00" - else - set_volume "$default_value%+" - fi -} - -decrease_vol() { - set_volume "$default_value%-" -}