notification service initial
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Notify when a new version of CoreDesktop is available
|
||||
# Notifications need a desktop session to show in
|
||||
ConditionEnvironment=|WAYLAND_DISPLAY
|
||||
ConditionEnvironment=|DISPLAY
|
||||
|
||||
[Service]
|
||||
# Not oneshot: the script waits, without a time limit, for the notification
|
||||
# to be clicked or dismissed
|
||||
Type=simple
|
||||
ExecStart=%h/.local/share/coredesktop/system/update-check
|
||||
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Check for a new version of CoreDesktop every few hours
|
||||
|
||||
[Timer]
|
||||
OnStartupSec=5min
|
||||
# Counted from when the last check finished, so a notification left open for
|
||||
# hours doesn't have another check queued up behind it
|
||||
OnUnitInactiveSec=4h
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Show a GNOME notification when a newer CoreDesktop is available.
|
||||
# Clicking it (or its "Update now" button) runs update in a terminal.
|
||||
# Run by coredesktop-update-check.timer (see system/update-notify.sh).
|
||||
|
||||
# Wrapped in { ...; exit; } so bash reads the whole script up front; update
|
||||
# replaces this file (git pull) while the notification is waiting for a click.
|
||||
{
|
||||
|
||||
# The newest version the user has been told about. Dismissing a notification
|
||||
# means not hearing about that version again, only about a newer one.
|
||||
NOTIFIED="$HOME/.local/state/coredesktop/update-notified"
|
||||
|
||||
latest="$("$HOME/.local/bin/version" --check)" || exit 0
|
||||
[ "$(cat "$NOTIFIED" 2> /dev/null)" = "$latest" ] && exit 0
|
||||
|
||||
# Waits until the notification is clicked or dismissed, then prints the action
|
||||
# ("default" is a click on the notification itself, empty if dismissed)
|
||||
action="$(notify-send --wait \
|
||||
--app-name=CoreDesktop \
|
||||
--icon=software-update-available \
|
||||
--action=default=Update \
|
||||
--action=update="Update now" \
|
||||
"CoreDesktop update available" \
|
||||
"Version $latest is ready. Click to run update.")" || exit 0
|
||||
|
||||
mkdir -p "$(dirname "$NOTIFIED")"
|
||||
echo "$latest" > "$NOTIFIED"
|
||||
|
||||
[ "$action" = "default" ] || [ "$action" = "update" ] || exit 0
|
||||
|
||||
# Open the first terminal found. bash -i reads ~/.bashrc, as if the user had
|
||||
# typed update themselves, and the window stays open to show how it went.
|
||||
run_update=(bash -ic 'update; echo; read -rp "Press Enter to close this window."')
|
||||
if command -v xdg-terminal-exec &> /dev/null; then
|
||||
terminal=(xdg-terminal-exec)
|
||||
elif command -v kgx &> /dev/null; then
|
||||
terminal=(kgx --)
|
||||
elif command -v ghostty &> /dev/null; then
|
||||
terminal=(ghostty -e)
|
||||
elif command -v kitty &> /dev/null; then
|
||||
terminal=(kitty)
|
||||
else
|
||||
notify-send --app-name=CoreDesktop "No terminal found" "Open a terminal and run update."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run the terminal as its own unit: when this service exits, systemd stops
|
||||
# everything still running in it, which would close the terminal mid-update
|
||||
exec systemd-run --user --quiet --collect -- "${terminal[@]}" "${run_update[@]}"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Install and enable the timer that checks for a new version of
|
||||
# CoreDesktop and shows a GNOME notification (system/update-check).
|
||||
# Run by install.sh and on every update (updates.d/16-update-notify.sh)
|
||||
# so changes to the units reach existing machines.
|
||||
|
||||
set -e
|
||||
|
||||
COREDESKTOP="$HOME/.local/share/coredesktop"
|
||||
UNITS="$HOME/.config/systemd/user"
|
||||
|
||||
mkdir -p "$UNITS"
|
||||
cp "$COREDESKTOP"/system/systemd/coredesktop-update-check.{service,timer} "$UNITS/"
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now coredesktop-update-check.timer
|
||||
Reference in New Issue
Block a user