Zren / plasma-applet-commandoutput

https://store.kde.org/p/1166510/
GNU General Public License v2.0
87 stars 18 forks source link

Cannot run script #17

Closed Th3Whit3Wolf closed 4 years ago

Th3Whit3Wolf commented 4 years ago

OS: Arch Linux Plasmashell: 5.18.4

I made a script to check for updates with to rust toolchain and notify me.

The command the applet runs is

bash ~/.config/scripts/rust_check.sh

Source code for script

#!/usr/bin/env bash

BAR_ICON=""
NOTIFY_ICON=//home/doc/Pics/Assets/rust-logo.svg

get_total_updates() { UPDATES=$(rustup check 2>/dev/null | grep -v "Up to date" | wc -l); }

while true; do
    get_total_updates

    # notify user of updates
    if hash notify-send &>/dev/null; then
        if (( UPDATES > 0 )); then
            notify-send -u normal -i $NOTIFY_ICON \
            "New rust toolchain available!" 
        fi
    fi

    # when there are updates available
    # every 30 seconds another check for updates is done
    while (( UPDATES > 0 )); do
        echo " $UPDATES"
        sleep 30
        get_total_updates
    done

    # when no updates are available, use a longer loop, this saves on CPU
    # and network uptime, only checking once every 30 min for new updates
    while (( UPDATES == 0 )); do
        echo "$BAR_ICON"
        sleep 36000
        get_total_updates
    done
done

I have tested the script and it runs as I would expect but I get no output in the applet.

It should be noted that I am using BSPWM as the window manger rather than kwin. The default command echo "Test $(date +%S)" works fine. Is their anything kwin specific in the code, maybe to get file paths?

Zren commented 4 years ago

It only prints when the command finishes. It will not "stream" the stdout while the process runs.

If you change the script to only call get_total_updates then notify-send then exit the script, then it should work.

I can't think of an easy way to change the "interval" based on the output though unfortunately.

You could modify the widget (or fork it if you have another instance of the widget) with https://zren.github.io/kde/docs/widget/.

First change interval to:

property bool hasUpdates: false
readonly property int interval: hasUpdates ? 30 * 1000 : 1000 * 60 * 30

Then add extra logic in onExited to parse formattedText, setting config.hasUpdates = true or false depending on the text.

Th3Whit3Wolf commented 4 years ago

Wow thank you for the detailed response. I have changed my script and it now works!