#!/bin/bash

DoNotify() {
    local -r msg="Reboot is recommended due to the upgrade of core system package(s)."
    local icon=/usr/share/icons/Qogir/scalable/apps/system-reboot.svg
    [ -e $icon ] || icon=system-reboot

    local cmd=(
        eos_notification_all           # function to notify all users
        $icon                          # icon
        critical                       # urgency
        0                              # expire time (not used!)
        "'EndeavourOS notification'"   # appname
        "Reboot recommended!"          # title
        "$msg"                         # message
        RED                            # message color on TTY
    )
    "${cmd[@]}"
}

Wait-for-some-processes() {
    # Wait for all pacman-like processes to finish.

    systemctl disable --now eos-reboot-required.timer
    sleep 1
    source /usr/share/endeavouros/scripts/eos-script-lib-yad --limit-icons || return
    while ps -C pacman,yay,paru,makepkg >/dev/null ; do
        sleep 1
    done
    DoNotify
}

Wait-for-some-processes "$@"
