Skip to content

Commit

Permalink
Write current state to a statefile (preparation for the future systra…
Browse files Browse the repository at this point in the history
…y applet) (#148)

* - Write to state file

* - Use user statefile

* - match state styling

* - relabel functions
- update comments

* - fixed a typo

* - rename `state-update-available`
  • Loading branch information
trigg authored May 7, 2024
1 parent 3c36de4 commit 0de8419
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/script/arch-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -192,29 +192,29 @@ invalid_option() {
# Definition of the icon directory
icon_dir="/usr/share/icons/hicolor/scalable/apps"

# 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 @@ -232,7 +232,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 @@ -255,7 +255,7 @@ check() {
fi
fi
else
icon_up_to_date
state_up_to_date
fi

if [ -f "${statedir}/current_updates_check" ]; then
Expand All @@ -265,7 +265,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 @@ -302,14 +302,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 @@ -392,14 +392,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 @@ -411,7 +411,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 @@ -423,13 +423,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

0 comments on commit 0de8419

Please sign in to comment.