Listen for installed update of app

Hello,

how can an app monitor whether it was updated while it was running, e.g. via auto-updates through Gnome Software, KDE Discover, or just by good old flatpak update? Is there a portal for this, or can the app somehow query the installed commit and compare it against what’s in /.flatpak-info?

My app mostly runs non-interactively in the background, and can keep running for days or weeks if the user doesn’t reboot. To poke users to restart the app after a significant update, I’d like to show some kind of indicator in the main window, and perhaps send a desktop notification.

Cheers

Regarding portals, the closest you have is the UpdateAvailable signal in the Flatpak.UpdateNotifier portal:

Unless you restart the Flatpak, things inside the sandbox are immutable and running the “old version”. This is one of the benefits of Flatpak, so that you don’t have to say restart the browser when updates get applied. I don’t think there’s an easy way to do this, you can probably do it out of band.

I’m sorry and I mean no offence, but that’s not very helpful. I know how flatpak works, I know that the whole flatpak needs to be restarted, that’s in fact precisely why I am asking this question. I know that I do need to do this out of band, because there’s probably no existing portal for this.

What I’m asking is how I could do this, because I probably need to reach outside of the sandbox, or somehow call into flatpak to figure out what app version is installed.

@CodedOre I’ve seen this portal, but it doesn’t do what I want. As far as I can see I can only use it to monitor whether an update is available on the remote, and to install that update, but neither is what I’d like to do.

I don’t care to update immediately, I’m fine with having my app updated automatically at some point without me noticing. But I’d like to be reminded that I have to restart the app to use the newer version.

There are multiple ways to do it. You can check for /app/.updated, you can check the commit of the running app and the one on disk, compare it with info/remote-info. These won’t give a version comparison, if you want that you have to parse the files on disk or flatpak’s CLI output.

1 Like

Thanks, that helps a lot :pray: but…

  1. what’s /app/.updated? Is that a file which flatpak creates when the app geht’s updated? Is there some docs for this?
  2. The running commit is probably in the flatpak-info file, but how can I get the on disk commit of my app from within the sandbox?

I don’t need the version number, I just want to know whether the running commit is different from the installed commit (e. g. also for downgrade).

It’s a regular file that gets created inside the running instance only when it’s updated. You have to periodically check if it appears.

get the on disk commit of my app from within the sandbox?

Not possible without extra permissions. flatpak info -c $appid gives it. Another way is to get access to app-path through filesystem permission and check the folder for the commit.

I found references to that file in some libportal tests, but it doesn’t seem to be documented anywhere? Is that a stable interface which I can rely on?

It’s there since 0.6 2016.

1 Like

This topic was automatically closed after 3 days. New replies are no longer allowed.