notification service initial

This commit is contained in:
2026-10-26 10:49:54 -06:00
parent c27354df20
commit 4593082c4a
8 changed files with 133 additions and 3 deletions
+3 -1
View File
@@ -184,7 +184,9 @@ Kernel 7.2.11-arch1-1
Last update 2026-10-22 13:43 Last update 2026-10-22 13:43
``` ```
The kernel comes from Arch, so it's shown separately. If a newer kernel is waiting for a reboot, "version" says so. The kernel comes from Arch, so it's shown separately. If a newer kernel is waiting for a reboot, "version" says so. It also tells you if a newer version of CoreDesktop is available.
You don't have to check by hand: a few minutes after you log in, and every few hours after that, CoreDesktop checks for a new version and shows a notification if there is one. Click it to run "update" in a terminal, or dismiss it. Once dismissed, you won't be notified again until there's an even newer version.
### Sibling projects ### Sibling projects
+4
View File
@@ -190,6 +190,10 @@ bash ~/.local/share/coredesktop/system/nvidia.sh
echo "Configuring the shell..." echo "Configuring the shell..."
bash ~/.local/share/coredesktop/shell/setup.sh bash ~/.local/share/coredesktop/shell/setup.sh
# Notify in GNOME when a new version of CoreDesktop is available
echo "Configuring update notifications..."
bash ~/.local/share/coredesktop/system/update-notify.sh
# Apply GNOME dconf settings only if the settings file has changed since last run # Apply GNOME dconf settings only if the settings file has changed since last run
bash ~/.local/share/coredesktop/gnome/apply-gnome-settings.sh bash ~/.local/share/coredesktop/gnome/apply-gnome-settings.sh
@@ -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
+52
View File
@@ -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[@]}"
}
+16
View File
@@ -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
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
COREDESKTOP="$HOME/.local/share/coredesktop"
run_update() {
bash "$COREDESKTOP/system/update-notify.sh"
}
+29 -2
View File
@@ -6,6 +6,9 @@
# the local checkout is on, plus the short hash to tell same-day commits apart, # the local checkout is on, plus the short hash to tell same-day commits apart,
# e.g. 2026.10.22 (c5f0651). The kernel is shown separately because it comes # e.g. 2026.10.22 (c5f0651). The kernel is shown separately because it comes
# from Arch, not CoreDesktop. # from Arch, not CoreDesktop.
#
# version --check prints the newer version and exits 0 if one is available,
# exits 1 if this machine is up to date, or 2 if it couldn't check.
COREDESKTOP="$HOME/.local/share/coredesktop" COREDESKTOP="$HOME/.local/share/coredesktop"
@@ -13,16 +16,40 @@ source "$COREDESKTOP/utils.sh"
if ! git -C "$COREDESKTOP" rev-parse --git-dir &> /dev/null; then if ! git -C "$COREDESKTOP" rev-parse --git-dir &> /dev/null; then
echo "CoreDesktop isn't installed in $COREDESKTOP." echo "CoreDesktop isn't installed in $COREDESKTOP."
exit 1 exit 2
fi fi
version="$(git -C "$COREDESKTOP" log -1 --format='%cd (%h)' --date=format:%Y.%m.%d)" # Version string for a commit, e.g. 2026.10.22 (c5f0651)
describe() {
git -C "$COREDESKTOP" log -1 --format='%cd (%h)' --date=format:%Y.%m.%d "$1"
}
# Print the newer version if the remote has commits this checkout doesn't.
# Returns 1 if up to date, 2 if the remote couldn't be reached.
newer_version() {
GIT_TERMINAL_PROMPT=0 timeout 30 git -C "$COREDESKTOP" fetch --quiet &> /dev/null || return 2
local behind
behind="$(git -C "$COREDESKTOP" rev-list --count 'HEAD..@{upstream}' 2> /dev/null)" || return 2
(( behind > 0 )) || return 1
describe '@{upstream}'
}
if [ "$1" = "--check" ]; then
newer_version
exit
fi
version="$(describe HEAD)"
# Local edits to the checkout mean this isn't exactly the version above # Local edits to the checkout mean this isn't exactly the version above
if [ -n "$(git -C "$COREDESKTOP" status --porcelain --untracked-files=no)" ]; then if [ -n "$(git -C "$COREDESKTOP" status --porcelain --untracked-files=no)" ]; then
version="$version, modified" version="$version, modified"
fi fi
if latest="$(newer_version)"; then
version="$version, $latest is available (run update)"
fi
kernel="$(uname -r)" kernel="$(uname -r)"
# If the running kernel's modules are gone, a newer kernel was installed # If the running kernel's modules are gone, a newer kernel was installed
if [ ! -d "/usr/lib/modules/$kernel" ]; then if [ ! -d "/usr/lib/modules/$kernel" ]; then