Flatpak: include the bundle in update info, and add an opt-in FlatpakUpdater
- Electron-Builder Version: 26.15.7
- Electron Updater (as-needed): 6.8.9
- Node Version: 22.22.3
- Electron Version: 43.7.6
- Platform & Target: Linux,
flatpaktarget (Ubuntu 26.04 LTS, GNOME, Flatpak 1.16.6) - Debug Logs: n/a (feature request)
Summary
Apps that distribute their Flatpak build as a standalone .flatpak bundle through a generic or GitHub provider, rather than through Flathub or another Flatpak remote, have no auto-update path with electron-updater today. I'd like to propose two changes and am happy to open a PR:
- The
flatpaktarget writes the bundle into the update info file, likedeb,rpmandAppImage. - An opt-in
FlatpakUpdaterin electron-updater.
Both are opt-in, so nothing changes for existing Flatpak apps, including those on Flathub.
Current behavior
FlatpakTargetcallsemitArtifactBuildCompleted({ ..., isWriteUpdateInfo: false }), so the.flatpakbundle never appears inlatest-linux.yml.- Inside a Flatpak sandbox,
doLoadAutoUpdater()falls back toAppImageUpdater, which disables itself becauseAPPIMAGEis unset. That's the right outcome by default, and Flathub apps rely on it: a Flatpak app shouldn't start updating itself without opting in.
Proposal
1. FlatpakTarget: include the bundle in the update info
Set isWriteUpdateInfo: true and pass updateInfo: { sha512, size }, as FpmTarget does. The sha512 key is needed: createUpdateInfo() only merges updateInfo into files[0] when it contains sha512. A size-only object ends up in the legacy top-level fields instead.
2. Opt-in marker
When the app has a publish configuration, write package-type = flatpak into the bundle's resources directory (/app/lib/<appId>/resources/), the same way FpmTarget writes it for deb/rpm/pacman. It would be added through the flatpak stage files, so the shared linux-unpacked directory isn't touched.
3. electron-updater: FlatpakUpdater
doLoadAutoUpdater() picks it only when FLATPAK_ID is set and package-type is flatpak. Flatpaks built any other way (for example from Flathub manifests) never have the marker and keep today's behavior.
What it does. All of this was verified live; see "Tested" below.
- Download: the
.flatpakfile from the feed, like the other Linux updaters. - Install:
flatpak-spawn --host flatpak install --<scope> --bundle -y <file>. A sandboxed process can't runflatpakitself.flatpak-spawn --hostneeds--talk-name=org.freedesktop.Flatpakin the app'sfinishArgs. Installing a newer bundle over an existing install is a normal update:flatpak historylogs it asdeploy update. - Scope (
--user/--system): read from[Instance] app-pathin/.flatpak-info(/var/lib/flatpak/...means system). Not fromflatpak info <id>: when the app is installed in both scopes, that reports one of them regardless of which instance is running. - System scope: the command is wrapped with
pkexec, as inDebUpdater/RpmUpdater. Without it the call is rejected outright withFlatpak system operation InstallBundle not allowed for user, even thoughorg.freedesktop.Flatpak.install-bundleisauth_admin_keep: polkit doesn't prompt for a caller reached throughflatpak-spawn --host. Withpkexec, the normal polkit password dialog appears and the update succeeds. - Relaunch:
flatpak-spawn --host flatpak run --<scope> <FLATPAK_ID>rather thanapp.relaunch().app.relaunch()re-executes inside the current sandbox, whose/appis still mounted from the old commit; a freshflatpak runstarts on the new one. The scope is passed explicitly becauseflatpak rundefaults to--systemwhen both scopes are installed. - Failure: if the install command fails,
doInstall()returnsfalse, soquitAndInstall()doesn't quit the app and the error is emitted. For example, reinstalling the same commit fails withThis version of <id> is already installed.
Security note for the docs: --talk-name=org.freedesktop.Flatpak lets the app run commands on the host, which effectively removes the Flatpak sandbox. It should be documented as a deliberate trade-off for self-distributed bundles, and not used for apps on Flathub, which updates its apps itself.
Why not a Flatpak remote
For apps on Flathub or another Flatpak remote, flatpak update (or the UpdateMonitor in org.freedesktop.portal.Flatpak) is the right mechanism, and this proposal doesn't change that. It targets apps that ship a standalone bundle through the same providers they already use for deb/rpm/AppImage, where there's no remote to update from.
Tested
Ubuntu 26.04 LTS (GNOME), Flatpak 1.16.6, Electron 43.x, electron-updater 6.8.9, app-builder-lib 26.15.7, generic provider:
- User-scope install: updated from an older build to a newer one in-app and relaunched on the new version, with no prompt.
- System-scope install: the same, with the polkit password prompt.
- Update info: the flatpak entry appears in the yml with
sha512andsizeinsidefiles[0].
Questions
- Is the
package-typemarker acceptable as the opt-in, or would you prefer something else, such as a config option? - Is one PR covering both
app-builder-libandelectron-updaterOK?
Source: electron-userland/electron-builder