Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only send desktop notification if the list of available updates differs from the last check #61

Merged
merged 5 commits into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions src/script/arch-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://github.com/Antiz96/arch-update
# Licensed under the GPL-3.0 license

# Variables definition
# General variables
name="arch-update"
version="1.6.2"
option="${1}"
Expand Down Expand Up @@ -298,22 +298,39 @@ check() {
icon_checking

if [ -n "${aur_helper}" ] && [ -n "${flatpak}" ]; then
update_number=$( (checkupdates ; "${aur_helper}" -Qua ; flatpak update | awk '{print $2}' | grep -v '^$' | sed '1d;$d') | wc -l )
update_available=$(checkupdates ; "${aur_helper}" -Qua ; flatpak update | awk '{print $2}' | grep -v '^$' | sed '1d;$d')
elif [ -n "${aur_helper}" ] && [ -z "${flatpak}" ]; then
update_number=$( (checkupdates ; "${aur_helper}" -Qua) | wc -l )
update_available=$(checkupdates ; "${aur_helper}" -Qua)
elif [ -z "${aur_helper}" ] && [ -n "${flatpak}" ]; then
update_number=$( (checkupdates ; flatpak update | awk '{print $2}' | grep -v '^$' | sed '1d;$d') | wc -l )
update_available=$(checkupdates ; flatpak update | awk '{print $2}' | grep -v '^$' | sed '1d;$d')
else
update_number=$(checkupdates | wc -l)
update_available=$(checkupdates)
fi

if [ -n "${notif}" ]; then
statedir="${XDG_STATE_HOME:-${HOME}/.local/state}/${name}"
mkdir -p "${statedir}"

if [ -f "${statedir}/current_check" ]; then
mv -f "${statedir}/current_check" "${statedir}/last_check"
fi

if [ "${update_number}" -ne 0 ]; then
echo "${update_available}" > "${statedir}/current_check"
sed -i '/^\s*$/d' "${statedir}/current_check"
fi

if [ -n "${update_available}" ]; then
icon_updates_available

if [ -n "${notif}" ]; then
if [ "${update_number}" -eq 1 ]; then
notify-send -i /usr/share/icons/arch-update/arch-update_updates-available.svg "Arch Update" "${update_number} update available"
else
notify-send -i /usr/share/icons/arch-update/arch-update_updates-available.svg "Arch Update" "${update_number} updates available"
if ! diff "${statedir}/current_check" "${statedir}/last_check" &>/dev/null; then
update_number=$(wc -l "${statedir}/current_check" | awk '{print $1}')

if [ "${update_number}" -eq 1 ]; then
notify-send -i /usr/share/icons/arch-update/arch-update_updates-available.svg "Arch Update" "${update_number} update available"
else
notify-send -i /usr/share/icons/arch-update/arch-update_updates-available.svg "Arch Update" "${update_number} updates available"
fi
fi
fi
else
Expand Down