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

chore: Rename "state" functions & file to "(tray) icon" #241

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/lib/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [ -n "${notif}" ]; then
fi

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

if [ -n "${notif}" ]; then
if ! diff "${statedir}/current_updates_check" "${statedir}/last_updates_check" &> /dev/null; then
Expand All @@ -47,7 +47,7 @@ if [ -n "${update_available}" ]; then
fi
fi
else
state_up_to_date
icon_up-to-date
fi

if [ -f "${statedir}/current_updates_check" ]; then
Expand Down
13 changes: 7 additions & 6 deletions src/lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ if [ -n "${diff_prog}" ]; then
fi
fi

# Definition of the state_updates_available function: Change state to "updates-available"
state_updates_available() {
# Definition of the icon_up-to-date function: Change icon to "up to date"
icon_up-to-date() {
# shellcheck disable=SC2154
echo "${name}_updates-available" > "${statedir}/current_state"
echo "${name}" > "${statedir}/tray_icon"
}

# Definition of the state_up_to_date function: Change state to "up to date"
state_up_to_date() {
echo "${name}" > "${statedir}/current_state"
# Definition of the icon_updates-available function: Change tray icon to "updates available"
icon_updates-available() {
# shellcheck disable=SC2154
echo "${name}_updates-available" > "${statedir}/tray_icon"
}
4 changes: 2 additions & 2 deletions src/lib/list_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ if [ -n "${flatpak_packages}" ]; then
fi

if [ -z "${packages}" ] && [ -z "${aur_packages}" ] && [ -z "${flatpak_packages}" ]; then
state_up_to_date
icon_up-to-date
info_msg "$(eval_gettext "No update available\n")"

if [ -n "${list_option}" ]; then
exit 7
fi
else
state_updates_available
icon_updates-available
if [ -z "${list_option}" ]; then
ask_msg "$(eval_gettext "Proceed with update? [Y/n]")"

Expand Down
32 changes: 16 additions & 16 deletions src/lib/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
# Create logger
log = logging.getLogger(__name__)

# Find Statefile
STATE_FILE = None
# Find Icon file
ICON_FILE = None
if 'XDG_STATE_HOME' in os.environ:
STATE_FILE = os.path.join(
os.environ['XDG_STATE_HOME'], 'arch-update', 'current_state')
ICON_FILE = os.path.join(
os.environ['XDG_STATE_HOME'], 'arch-update', 'tray_icon')
elif 'HOME' in os.environ:
STATE_FILE = os.path.join(
os.environ['HOME'], '.local', 'state', 'arch-update', 'current_state')
if not os.path.isfile(STATE_FILE):
log.error("Statefile does not exist: %s", STATE_FILE)
ICON_FILE = os.path.join(
os.environ['HOME'], '.local', 'state', 'arch-update', 'tray_icon')
if not os.path.isfile(ICON_FILE):
log.error("Statefile does not exist: %s", ICON_FILE)
sys.exit(1)

# Find translations
Expand Down Expand Up @@ -79,13 +79,13 @@ class ArchUpdateQt6:
""" System Tray using QT6 library """

def file_changed(self):
""" Called when statefile contents change """
""" Called when icon file content changes """

contents = ""
if self.watcher and not self.statefile in self.watcher.files():
self.watcher.addPath(self.statefile)
if self.watcher and not self.iconfile in self.watcher.files():
self.watcher.addPath(self.iconfile)
try:
with open(self.statefile, encoding="utf-8") as f:
with open(self.iconfile, encoding="utf-8") as f:
contents = f.readline().strip()
except FileNotFoundError:
log.error("Statefile Missing")
Expand All @@ -102,10 +102,10 @@ def exit(self):
""" Close systray process """
sys.exit(0)

def __init__(self, statefile):
def __init__(self, iconfile):
""" Start Qt6 System Tray """

self.statefile = statefile
self.iconfile = iconfile
self.watcher = None

# Application
Expand All @@ -131,11 +131,11 @@ def __init__(self, statefile):
self.tray.setContextMenu(menu)

# File Watcher
self.watcher = QFileSystemWatcher([self.statefile])
self.watcher = QFileSystemWatcher([self.iconfile])
self.watcher.fileChanged.connect(self.file_changed)

app.exec()


if __name__ == "__main__":
ArchUpdateQt6(STATE_FILE)
ArchUpdateQt6(ICON_FILE)
4 changes: 2 additions & 2 deletions src/lib/tray.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ if [ "${2}" == "--enable" ]; then
fi
else
# shellcheck disable=SC2154
if [ ! -f "${statedir}/current_state" ]; then
state_up_to_date
if [ ! -f "${statedir}/tray_icon" ]; then
icon_up-to-date
fi

# shellcheck disable=SC2154
Expand Down
8 changes: 4 additions & 4 deletions src/lib/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [ -n "${packages}" ]; then

# shellcheck disable=SC2154
if ! "${su_cmd}" pacman --color "${pacman_color_opt}" -Syu; then
state_updates_available
icon_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 @@ -25,7 +25,7 @@ if [ -n "${aur_packages}" ]; then

# shellcheck disable=SC2154
if ! "${aur_helper}" --color "${pacman_color_opt}" "${devel_flag[@]}" -Syu; then
state_updates_available
icon_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 @@ -40,12 +40,12 @@ if [ -n "${flatpak_packages}" ]; then
main_msg "$(eval_gettext "Updating Flatpak Packages...\n")"

if ! flatpak update; then
state_updates_available
icon_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

state_up_to_date
icon_up-to-date
echo
info_msg "$(eval_gettext "The update has been applied\n")"