Nucleus
Flathub

FlathubNew

Publish a Nucleus app on Flathub without opening its source, and install its updates from inside the app with the flatpak module.

View as Markdown

Flathub builds nothing from your source here: its manifest repackages the Linux tar.gz your release already publishes, the path a closed-source app takes. The plugin writes that manifest and its store metadata, and the flatpak module talks to the Flatpak portal from the installed app:

Entry pointWhat it does
linux { flathub { } } + generateFlathubRepositoryWrites the Flathub repository of the app: manifest, AppStream metainfo, desktop entry, icon, MIME types
Flatpak.updatesFollows the app's remote for a newer version, installs it from inside the app, and restarts into it
flatpakLinuxGradle plugin: RequiredWindow runtime: Not neededWorks only inside the Flatpak the plugin builds.

The Lab, Nucleus's test bench, went through this procedure as dev.nucleusframework.Lab. Its probe system.flatpak-updates calls every function of the module.

PageCovers
Publish on FlathubDescribe the app, generate its repository, test it locally, submit it, ship updates
App updatesFind a newer version on the remote, install it and restart without leaving the app

Add the dependency

The plugin side needs nothing. For in-app updates:

build.gradle.kts
dependencies {
    implementation("dev.nucleusframework:nucleus.flatpak:3.0.0")
}

Where it works

The portal only answers a process that runs inside a Flatpak sandbox: the app installed from Flathub, from any other remote, or from a local repository.

Where the app runsavailability()Flatpak calls
Installed as a Flatpak, portal version 2 or later (flatpak 1.6)AvailableWork
Installed as a Flatpak, older or missing portalPortalMissingFail with FlatpakErrorCode.PortalMissing
DEB, RPM, AppImage, Pacman, Snap, or ./gradlew runNotFlatpakFail with FlatpakErrorCode.NotFlatpak
macOS, WindowsUnsupportedFail with FlatpakErrorCode.Unsupported
import dev.nucleusframework.flatpak.Flatpak
import dev.nucleusframework.flatpak.FlatpakAvailability

if (Flatpak.availability() == FlatpakAvailability.Available) {
    showUpdatesMenu()
}

Flatpak.isSupported is true on Linux when the native bridge loaded, and Flatpak.appId is the sandbox's FLATPAK_ID (null outside one). Neither says whether the portal can serve you: check availability() before you show any update UI.

ExecutableRuntime.type() reports FLATPAK for the repackaged archive too: Nucleus reads /.flatpak-info, which Flatpak mounts in every sandbox, before the archive's own marker. The Nucleus updater stays out of the way there: isUpdateSupported() is false.

Inside the sandbox

A Flatpak hides the user's home and system from the app. Nucleus adapts on its own, with nothing to configure:

WhatInside a Flatpak
Preferences (java.util.prefs, multiplatform-settings' Settings())Kept in ~/.var/app/<app id>/config, which Flatpak persists, instead of a temporary home
HTTPS with native-sslTrusts the CAs installed on the user's system (company proxy, filter), read through p11-kit
Linux notificationsGo through the notification portal, with no manifest permission
Wayland app_idThe Flatpak app id, so desktops pair the window with its entry
Title bar buttonsFollow the desktop's button-layout, read through the Settings portal

The app's own files land under ~/.var/app/<app id>/: FileKit's and the XDG directories point there. Uninstalling the app keeps that folder unless the user runs flatpak uninstall --delete-data.

Calls, threads and cancellation

  • Every call suspends or returns a Flow, and you may call it from any thread, the UI thread included.
  • Cancelling the collection of install() cancels the update.
  • Failures throw FlatpakException.
  • The portal's dialogs (the update consent, the store page) sit on a window you pass as a FlatpakParentWindow. Resolve it off the UI thread: on Wayland the export waits on the event loop.
import dev.nucleusframework.flatpak.FlatpakParentWindow

suspend fun TaoWindow.flatpakParent(): FlatpakParentWindow? =
    withContext(Dispatchers.IO) { xdgPortalParent() }
        ?.let { FlatpakParentWindow(it.portalParent, keepAlive = it as? AutoCloseable) }

Get the TaoWindow from LocalNucleusWindow.current.unsafe.taoWindow. keepAlive holds the Wayland export open until the call that borrowed it is over; the module closes it.

Errors

FlatpakException.code tells you what failed; portalError carries the D-Bus error name when the failure came from the portal. The portal's messages are translated: tell errors apart by code, never by message.

FlatpakErrorCodeMeaning
UnsupportedNot Linux, or the native bridge failed to load
NotFlatpakThe process runs outside a Flatpak sandbox
PortalMissingNo Flatpak portal of version 2 or later, or no Access portal for its update dialog
UpdateDeniedThe user answered Deny to the "Update …?" dialog. Flatpak remembers it; the user changes it in the desktop's privacy settings (GNOME: Apps, the app's page)
NewPermissionsRequiredThe new version asks for permissions the installed one lacks: only the store or flatpak update may grant them
InProgressinstall() is already running in this process
PlatformAny other portal error; see portalError
InternalA bug in the module or its native bridge

Logging

The module logs through java.util.logging under dev.nucleusframework.flatpak. Raise that logger's level, or set allowNucleusRuntimeLogging = true (dev.nucleusframework.core.runtime.tools).

flatpak { } is not Flathub

linux { flatpak { } } builds a single-file .flatpak bundle through electron-builder, for sideloading. Flathub does not accept bundles: it builds from a manifest, which linux { flathub { } } writes. The two blocks are independent.

Was this page helpful?
Edit on GitHub

Last updated on