feat(default-flatpaks): install & uninstall notifs (#109)

* feat(default-flatpaks): Support for notifications that inform the user before flatpak install/uninstall procedure begins

This can be implemented to be more readable maybe, but this should work.

* chore(default-flatpaks): There is no need to call notifications true statement twice

* chore(default-flatpaks): Make starting notifications consistent with finished ones

* chore(default-flatpaks): Use "listed" term rather than "some"

* chore(default-flatpaks): Use "some" notification only for uninstalling flatpaks
This commit is contained in:
fiftydinar 2024-01-30 18:06:25 +01:00 committed by GitHub
parent 122d436f21
commit 9b66c64563
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 16 deletions

View file

@ -51,6 +51,14 @@ FLATPAK_LIST=$(flatpak list --system --columns=application)
INSTALL_LIST_FILE="/etc/flatpak/system/install"
REMOVE_LIST_FILE="/etc/flatpak/system/remove"
function notify-send-pre-install {
user_name=$(loginctl list-sessions --output=json | jq -r '.[].user')
uid=$(loginctl list-sessions --output=json | jq -r '.[].uid')
xdg_runtime_path="/run/user/$uid"
display_var=$(printenv DISPLAY)
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Started install of system flatpaks" --app-name="Flatpak Installer" -u NORMAL
}
function notify-send-install {
user_name=$(loginctl list-sessions --output=json | jq -r '.[].user')
uid=$(loginctl list-sessions --output=json | jq -r '.[].uid')
@ -59,6 +67,14 @@ function notify-send-install {
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Finished install of system flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL
}
function notify-send-pre-uninstall {
user_name=$(loginctl list-sessions --output=json | jq -r '.[].user')
uid=$(loginctl list-sessions --output=json | jq -r '.[].uid')
xdg_runtime_path="/run/user/$uid"
display_var=$(printenv DISPLAY)
sudo -u "$user_name" DBUS_SESSION_BUS_ADDRESS=unix:path="$xdg_runtime_path"/bus DISPLAY="$display_var" notify-send "Flatpak Installer" "Started uninstall of some system flatpaks" --app-name="Flatpak Installer" -u NORMAL
}
function notify-send-uninstall {
user_name=$(loginctl list-sessions --output=json | jq -r '.[].user')
uid=$(loginctl list-sessions --output=json | jq -r '.[].uid')
@ -74,21 +90,23 @@ if [[ -f $INSTALL_LIST_FILE ]]; then
else
INSTALL_LIST=$(cat $INSTALL_LIST_FILE)
fi
if [[ -n $INSTALL_LIST ]]; then
if [[ -n $INSTALL_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
if [[ $NOTIFICATIONS == "true" ]]; then
notify-send-install
fi
elif [[ -n $INSTALL_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
notify-send-pre-install
flatpak install --system --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
notify-send-install
fi
fi
# Remove flatpaks in list
if [[ -f $REMOVE_LIST_FILE ]]; then
REMOVE_LIST=$(echo "$FLATPAK_LIST" | grep -o -f - "$REMOVE_LIST_FILE")
if [[ -n $REMOVE_LIST ]]; then
if [[ -n $REMOVE_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
flatpak uninstall --system --noninteractive ${REMOVE_LIST[@]}
if [[ $NOTIFICATIONS == "true" ]]; then
notify-send-uninstall
fi
elif [[ -n $REMOVE_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
notify-send-pre-uninstall
flatpak uninstall --system --noninteractive ${REMOVE_LIST[@]}
notify-send-uninstall
fi
fi

View file

@ -40,21 +40,23 @@ if [[ -f $INSTALL_LIST_FILE ]]; then
else
INSTALL_LIST=$(cat $INSTALL_LIST_FILE)
fi
if [[ -n $INSTALL_LIST ]]; then
if [[ -n $INSTALL_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
if [[ $NOTIFICATIONS == "true" ]]; then
notify-send "Flatpak Installer" "Finished install of user flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL
fi
elif [[ -n $INSTALL_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
notify-send "Flatpak Installer" "Started install of user flatpaks" --app-name="Flatpak Installer" -u NORMAL
flatpak install --user --noninteractive "$REPO_NAME" ${INSTALL_LIST[@]}
notify-send "Flatpak Installer" "Finished install of user flatpaks:\n$INSTALL_LIST" --app-name="Flatpak Installer" -u NORMAL
fi
fi
# Remove flatpaks in list
if [[ -f $REMOVE_LIST_FILE ]]; then
REMOVE_LIST=$(echo "$FLATPAK_LIST" | grep -o -f - "$REMOVE_LIST_FILE")
if [[ -n $REMOVE_LIST ]]; then
if [[ -n $REMOVE_LIST ]] && [[ ! $NOTIFICATIONS == "true" ]]; then
flatpak uninstall --user --noninteractive ${REMOVE_LIST[@]}
if [[ $NOTIFICATIONS == "true" ]]; then
notify-send "Flatpak Installer" "Finished uninstall of user flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL
fi
elif [[ -n $REMOVE_LIST ]] && [[ $NOTIFICATIONS == "true" ]]; then
notify-send "Flatpak Installer" "Started uninstall of some user flatpaks" --app-name="Flatpak Installer" -u NORMAL
flatpak uninstall --user --noninteractive ${REMOVE_LIST[@]}
notify-send "Flatpak Installer" "Finished uninstall of user flatpaks:\n$REMOVE_LIST" --app-name="Flatpak Installer" -u NORMAL
fi
fi