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

Write current state to a statefile (preparation for the future systray applet) #148

Merged
merged 6 commits into from
May 7, 2024
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
46 changes: 23 additions & 23 deletions src/script/arch-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,29 @@ invalid_option() {
icon_dir="/usr/share/icons/${name}"
[ -d "/usr/local/share/icons/${name}" ] && icon_dir="/usr/local/share/icons/${name}"

# Definition of the icon_checking function: Change icon to "checking"
icon_checking() {
cp -f "${icon_dir}/${name}_checking.svg" "${icon_dir}/${name}.svg" || exit 3
# Definition of the state_checking function: Change state to "checking"
state_checking() {
echo "${name}_checking" > "${statedir}/current_state"
}

# Definition of the icon_updates_available function: Change icon to "updates-available"
icon_updates_available() {
cp -f "${icon_dir}/${name}_updates-available.svg" "${icon_dir}/${name}.svg" || exit 3
# Definition of the state_updates_available function: Change state to "updates-available"
state_updates_available() {
echo "${name}_updates-available" > "${statedir}/current_state"
}

# Definition of the icon_installing function: Change icon to "installing"
icon_installing() {
cp -f "${icon_dir}/${name}_installing.svg" "${icon_dir}/${name}.svg" || exit 3
# Definition of the state_installing function: Change state to "installing"
state_installing() {
echo "${name}_installing" > "${statedir}/current_state"
}

# Definition of the icon_up_to_date function: Change icon to "up to date"
icon_up_to_date() {
cp -f "${icon_dir}/${name}_up-to-date.svg" "${icon_dir}/${name}.svg" || exit 3
# Definition of the state_up_to_date function: Change state to "up to date"
state_up_to_date() {
echo "${name}_up-to-date" > "${statedir}/current_state"
}

# Definition of the check function: Check for available updates, change the icon accordingly and send a desktop notification containing the number of available updates
check() {
icon_checking
state_checking

if [ -n "${aur_helper}" ] && [ -n "${flatpak}" ]; then
update_available=$(checkupdates ; "${aur_helper}" -Qua ; flatpak update | sed -n '/^ 1./,$p' | awk '{print $2}' | grep -v '^$' | sed '$d')
Expand All @@ -233,7 +233,7 @@ check() {
fi

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

if [ -n "${notif}" ]; then
if ! diff "${statedir}/current_updates_check" "${statedir}/last_updates_check" &> /dev/null; then
Expand All @@ -256,7 +256,7 @@ check() {
fi
fi
else
icon_up_to_date
state_up_to_date
fi

if [ -f "${statedir}/current_updates_check" ]; then
Expand All @@ -266,7 +266,7 @@ check() {

# Definition of the list_packages function: Display packages that are available for update and offer to apply them if there are
list_packages() {
icon_checking
state_checking
info_msg "$(eval_gettext "Looking for updates...\n")"

if [ -z "${no_version}" ]; then
Expand Down Expand Up @@ -303,14 +303,14 @@ list_packages() {
fi

if [ -z "${packages}" ] && [ -z "${aur_packages}" ] && [ -z "${flatpak_packages}" ]; then
icon_up_to_date
state_up_to_date
if [ -z "${list_option}" ]; then
info_msg "$(eval_gettext "No update available\n")"
else
exit 7
fi
else
icon_updates_available
state_updates_available
if [ -z "${list_option}" ]; then
ask_msg "$(eval_gettext "Proceed with update? [Y/n]")"

Expand Down Expand Up @@ -393,14 +393,14 @@ list_news() {

# Definition of the update function: Update packages
update() {
icon_installing
state_installing

if [ -n "${packages}" ]; then
echo
main_msg "$(eval_gettext "Updating Packages...\n")"

if ! "${su_cmd}" pacman --color "${pacman_color_opt}" -Syu; then
icon_updates_available
state_updates_available
echo
error_msg "$(eval_gettext "An error has occurred during the update process\nThe update has been aborted\n")" && quit_msg
exit 5
Expand All @@ -412,7 +412,7 @@ update() {
main_msg "$(eval_gettext "Updating AUR Packages...\n")"

if ! "${aur_helper}" --color "${pacman_color_opt}" "${devel_flag[@]}" -Syu; then
icon_updates_available
state_updates_available
echo
error_msg "$(eval_gettext "An error has occurred during the update process\nThe update has been aborted\n")" && quit_msg
exit 5
Expand All @@ -424,13 +424,13 @@ update() {
main_msg "$(eval_gettext "Updating Flatpak Packages...\n")"

if ! flatpak update; then
icon_updates_available
state_updates_available
error_msg "$(eval_gettext "An error has occurred during the update process\nThe update has been aborted\n")" && quit_msg
exit 5
fi
fi

icon_up_to_date
state_up_to_date
echo
info_msg "$(eval_gettext "The update has been applied\n")"
}
Expand Down