App updatesNew
Follow a Nucleus app's Flatpak remote for a newer version, install it from inside the app with progress, restart into it, and send the user to the store when the update needs new permissions.
GNOME Software and KDE Discover update Flatpaks in the background, on their own schedule.
Flatpak.updates installs a newer version from inside the app, through the Flatpak portal, for
any remote: Flathub, your own, or a local test repository.
The Nucleus updater does not apply to Flatpak installs:
isUpdateSupported() is false there.
Follow the remote
import dev.nucleusframework.flatpak.Flatpak
import dev.nucleusframework.flatpak.FlatpakUpdateStatus
Flatpak.updates.status.collect { status ->
when (status) {
is FlatpakUpdateStatus.Available -> offerUpdate()
is FlatpakUpdateStatus.Installed -> offerRestart()
is FlatpakUpdateStatus.UpToDate -> Unit
}
}| Status | Meaning |
|---|---|
Available | The remote has a newer commit than the installed one |
Installed | A newer commit is installed, by install(), the store or flatpak update, but this process runs the old one |
UpToDate | This process runs the remote's latest commit |
Each status carries the OSTree commits: runningCommit, and installedCommit / remoteCommit
where they differ.
No check now
The portal has no "check now". It checks every app on one timer, every 30 minutes, and the first
status arrives on the first tick after you start collecting: up to 30 minutes later. Then it
reports only when a commit changes. Collect status for the life of the app, not behind a button.
Each collection runs a monitor of its own, closed when the collection ends.
Install it
import dev.nucleusframework.flatpak.FlatpakUpdateState
Flatpak.updates
.install(parent) // a FlatpakParentWindow, see the Flathub page
.collect { progress ->
when (progress.state) {
FlatpakUpdateState.Installing -> showProgress(progress.progress) // 0.0 to 1.0
FlatpakUpdateState.Completed -> offerRestart()
FlatpakUpdateState.UpToDate -> Unit // nothing to install
}
}- The first install shows the portal's "Update …?" dialog over
parent. Flatpak remembers the answer: after Deny, this and every later install fail withFlatpakErrorCode.UpdateDenied. progresscovers the whole update. An update may also pull a runtime or an extension, each its own operation:operationcounts from0out ofoperationCount.- The flow completes after
CompletedorUpToDate. Cancelling the collection cancels the update. - A new version that asks for more permissions fails with
FlatpakErrorCode.NewPermissionsRequired: only the store may grant them. Send the user there.
Restart into it
The process keeps running the old version after install(), and after the store updated it
(Installed). restart() starts the new one and exits:
Flatpak.updates.restart()The new process gets this process's arguments, or the ones you pass. Nucleus hands the
single-instance lock over first, so the new process does not take the old one for a running
instance. If the portal refuses to start it, restart() throws and this process runs on.
Send the user to the store
Flatpak.updates.openStorePage(parent)openStorePage() opens appstream://<app id> in the desktop's store, GNOME Software or Discover,
where the user updates the app, new permissions included.
Test without publishing
Build two versions into a local repository and install the first: the second is an update of it.
Restart the portal with /usr/libexec/flatpak-portal --replace --poll-timeout=10 to get a status
every 10 seconds instead of 30 minutes. See Test it locally.
Last updated on
Publish on Flathub
Take a closed-source Nucleus app to Flathub: publish its tar.gz, describe it with linux { flathub { } }, generate its repository, test it with Flathub's own checks, submit it, verify the app id, and ship updates.
Runtimes and performance
Build the same Kotlin source as a GraalVM native image or as a JDK image with an AOT cache, pick the right one, and detect the runtime from code.