Antiz96 / arch-update

An update notifier & applier for Arch Linux with a systray applet that assists you with important pre / post update tasks.
GNU General Public License v3.0
112 stars 11 forks source link

Add the ability to cache pending updates for external application use #223

Closed derethil closed 3 months ago

derethil commented 3 months ago

Description

It'd be super nice for other applications to have the ability to query the pending updates at any time (after updates were checked). When --check is run, arch-update could potentially write the update count to a cache file/socket in /tmp or XDG_RUNTIME_DIR. Then, external applications could simply read the last check to retrieve the information they need.

For my use case, I just need the update count, but it might be more useful to cache the full update status and then applications can parse the file as needed.

Motivation and context

It's understandable if this is out of scope for arch-update, but this feature would be extremely convenient - currently, if I want to get the number of pending updates into some other application, I have to have two very similar systemd timers running. Implementing this cache feature would allow me to use arch-update as the only update checking timer on my system.

For context, I've written my own custom desktop widgets with AGS and I need some way to read the number of pending updates to display in my dashboard UI.

Antiz96 commented 3 months ago

Hi,

Thanks a lot for the request!

Actually, Arch-Update already writes/caches the list of pending updates to a file! It is under XDG_STATE_HOME/arch-update/last_updates_check or $HOME/.local/state/arch-update/last_updates_check (if XDG_STATE_HOME isn't set):

$ cat ~/.local/state/arch-update/last_updates_check
cryptsetup 2.7.3-1 -> 2.7.4-1
sbctl 0.14-1 -> 0.15.2-1

This file is updated after each --check run. Your application/widget can look into that file for the list of pending updates, and parse it as needed (for instance, get the number of line in that file to get the number of pending updates).

Does that covers your need? :)

Antiz96 commented 3 months ago

Alternatively, the arch-update --list command prints the list of pending updates:

image

Here also, I guess the output could be parsed as needed (but it might be a bit more complex than parsing the file directly).

Antiz96 commented 3 months ago

For what it's worth, I would like to achieve just that at the Arch-Update systray applet level directly, so the systray applet would also show the number of pending updates next to the icon. But I'm not sure how to achieve that yet, nor how complex it is. See https://github.com/Antiz96/arch-update/issues/154 :)

derethil commented 3 months ago

Oh, great! I can't believe I missed that when I was skimming, that will serve my usecase perfectly, thanks :)

Are the cached files worth mentioning in the README for anybody in the future looking to do the same thing? I know it would have saved me some time if it had been. That is, if it's not already... At this rate, I wouldn't be surprised if I passed over it, even though I skimmed through it like 3 times lol

Antiz96 commented 3 months ago

It is not mentioned in the README, so you didn't missed anything :wink:
One could have find that by skimming through the code itself but I don't think the documentation mentions it.

I understand your use case but it's rather specific in my opinion, so I'm unsure how relevant it is to mention that in the README :thinking: These cache/state files are initially made for "internal processing" of Arch-Update itself and should not be of any use for users in most cases. If I ever have a similar request in the future, I'll think about documenting that somewhere.

However, it's awesome to see someone building something around Arch-Update :pray: :star_struck: :heart:

Is there anything else you need? Otherwise I guess we can close that issue :)

derethil commented 3 months ago

Gotcha, that's fair - I don't imagine I represent the average user of Arch-Update :laughing:

I'll go ahead and close the issue, I've updated my package module to use the cache files and it's working great :)

Appreciate your work on this!