From e6743ce3f8443efe693a59ab30bd7122964fca6b Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Wed, 20 Mar 2024 01:48:22 +0100 Subject: [PATCH] It would be cool if this worked in a systemd service... --- flatpak-updater.nu | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/flatpak-updater.nu b/flatpak-updater.nu index 13730ae..58b6dbe 100755 --- a/flatpak-updater.nu +++ b/flatpak-updater.nu @@ -1,20 +1,42 @@ #!/usr/bin/env nu # Documentation for notify -def notify [message: string, prefix?: string] { - notify-send $"Flatpak updater ($prefix)" $message +#def notify [message: string, prefix?: string] { +# notify-send $"Flatpak updater ($prefix)" $message +#} + +def notify [message: string, urgency: string, prefix?: string] { + notify-send $"Flatpak updater ($prefix)" $message -u $urgency } +#def update_flatpaks [] { +# notify "Starting unattended flatpak update..." +# let flatpak_status = do { flatpak update -y } | complete +# if $flatpak_status != 0 { +# if $flatpak_status.stderr != "" { +# notify $flatpak_status.stderr "stderr" +# } else { +# notify "Unattended update complete.\nConsider restarting presently running flatpaks." +# } +# } +#} def update_flatpaks [] { - notify "Starting unattended flatpak update..." - let flatpak_status = do { flatpak update -y } | complete - if $flatpak_status != 0 { - if $flatpak_status.stderr != "" { - notify $flatpak_status.stderr "stderr" + notify "Starting unattended flatpak update..." "normal" + let flatpak_status = do { flatpak update -y } | complete + if $flatpak_status.exit_code != 0 { + if $flatpak_status.stderr != "" { + notify $flatpak_status.stderr "critical" "stderr" + } + if $flatpak_status.stdout != "" { + notify $flatpak_status.stdout "normal" "stdout" + } } else { - notify "Unattended update complete.\nConsider restarting presently running flatpaks." + notify $"Unattended update complete.\nConsider restarting presently running flatpaks:\n\n(running_flatpaks)" "normal" } - } +} + +def running_flatpaks [] { + flatpak ps --columns="application" | lines | uniq | str join "\n" } # Documentation for main