New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for building Flatpak bundles #512 #5711
Conversation
0400b40
to
e3fa211
Compare
FYI I've rebased and force-pushed to fix some small conflicts introduced by the recent migration from Yarn to pnpm (#5710). |
9ffc66f
to
ec72ef4
Compare
Hi @vially! Thanks for the contribution! You might be able to literally just copy one of the test files and switch up the target to flatpak |
ec72ef4
to
d7d2f78
Compare
@mmaietta Thanks for the feedback! I added some tests (da167a1) and a fix for an issue uncovered by the tests (d7d2f78). I think it's worth mentioning that these tests are really slow. On my machine it's taking around 5 minutes just for these Flatpak tests to run. For what it's worth it's pretty close to what I get when running the underlying flatpak-builder commands directly, so I don't think this is due to some overhead introduced in I'm not sure what would be considered a reasonable time frame for these tests, but it may be worth considering disabling them by default if you think this is unacceptable (similar to these snap tests). |
Thanks for adding the tests! I'll need to figure out a way for us to get some more build node coverage for these heavy tests (similar as was done for mas and dmg tests) @refi64 you're our resident expert! 😉 Could you run a final review please? |
😅 I'm admittedly not too familiar with electron-builder, but at a glance everything here does seem to check out. |
I joined the maintainer crew only a month or so ago 😅 Thanks for reviewing the flatpak implementation! That helps a lot. |
Done! |
@vially would you be willing to also add documentation for this new feature to electron-builder |
I think I may need some assistance in doing that. Just to make sure I'm on the right track here, the documentation is supposed to be auto-generated from the TypeScript comments and/or the schema, right? If that's the case then I must be doing something wrong because I didn't manage to get the scripts to run. I also get the feeling the documentation may not be entirely up-to-date. These are some of the things I tried that didn't work: mkdocs buildOut of the box it fails with an error complaining about the usage of IP address 0.0.0.0. Once I change that to Maybe an older version of pnpm run docsInitially it fails with some errors complaining about some missing node modules ( For example, this is one such problematic comment taken from /**
* @param {Array<Platform<>>} platforms
* @param {string | "undefined"} type
* @param {string | "undefined"} arch
* @returns {Map<Platform<> | Map<Arch | Array<string>>>}
*/
export function createTargets() {} So, my main question is, are these actually the right commands for generating the documentation? And if they are, can anyone confirm that they have been able to run them recently on the |
It would be really handy, if this was documented |
Documentation of FlatpakOptions (https://www.electron.build/configuration/configuration.html#FlatpakOptions) would definitely be great. In the meantime, a simple example config file could be very useful. Has someone found one already? |
https://www.electron.build/api/programmatic-usage for a js/scripted configuration |
@mmaietta Thanks for coming back. I had seen this example, but it unfortunately doesn't contain any specific configuration for producing a flatpak build. And the link https://www.electron.build/configuration/configuration.html#FlatpakOptions seems to be pointing nowhere. I've nevertheless tried to run
With this minimal config, I get the following output / error:
As you can see, I'm new to flatpak, so I'm kind of stuck here at the moment. Any help or link to relevant info would be appreciated. |
Interesting that it's not linking anywhere on the website. Here's the interface/options for the flatpak config to get you in the right direction electron-builder/packages/app-builder-lib/src/options/linuxOptions.ts Lines 133 to 232 in a138a86
|
Just in case it helps anyone I was able to build flatpaks while getting essentially get all the benefits of using electron-builder (e.g. native module support) using an additional step in the build process with @malept/electron-installer-flatpak. The relevant npm scripts are: "scripts": {
"postinstall": "electron-builder install-app-deps",
"build:main": "cross-env NODE_ENV=production webpack --config ./webpack/main.js",
"build:renderer": "cross-env NODE_ENV=production webpack --config ./webpack/renderer.js",
"build:dist": "rimraf dist && npm run build:main && npm run build:renderer",
"build:linux": "electron-builder --linux --ia32 --x64 --dir && cp LICENSE release/linux-unpacked/ && cp electron-version release/linux-unpacked/version",
"build:flatpak": "electron-installer-flatpak --src release/linux-unpacked --dest release/ --arch x64",
}, Then to make a flatpak package I simply do:
Essentially electron-builder is used to create an unpacked version of the build ( |
Add a new Linux target for exporting applications in Flatpak format.
Implementation details
The current implementation is delegating the actual build process to @malept/flatpak-bundler, which is a Node wrapper over the flatpak-builder tool.
Similar to the other Linux targets (e.g.: AppImage, snap, etc) the Flatpak target allows the user to customize some of the options. However, in order to make it as easy as possible to get started, some sensible defaults are also provided out-of-the-box:
org.freedesktop.Platform
20.08
org.freedesktop.Sdk
20.08
Also, an
electron-wrapper
script is automatically added to the bundle which uses zypak for sandboxing the applications.When the electron version supports it (version 12 and above), the Wayland flags (
--enable-features=UseOzonePlatform --ozone-platform=wayland
) are also automatically added to this wrapper script in order to provide a better out-of-the-box experience for Wayland users.Limitations and possible future work
Note: This pull-request only makes it possible to export
*.flatpak
bundles.In the future, it might make sense to also implement a Flatpak publisher (similar to the Snap Store publisher) that makes it possible to publish the application to a repository (e.g.: Flathub).
However, it's not entirely clear how that would work so it is not part of this pull-request. But it is something that should be considered as a possible next step.
Related issues: #512