Skip to content

Commit

Permalink
Add support for building Flatpak bundles (electron-userland#5711)
Browse files Browse the repository at this point in the history
  • Loading branch information
vially committed Apr 8, 2021
1 parent 0f3b46c commit 6b1be73
Show file tree
Hide file tree
Showing 13 changed files with 740 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"Mac",
"appx",
"snap",
"flatpak",
"portable"
],
"author": "Vladimir Krivosheev",
Expand All @@ -45,6 +46,7 @@
"7zip-bin": "~5.1.1",
"@develar/schema-utils": "~2.6.5",
"@electron/universal": "1.0.4",
"@malept/flatpak-bundler": "^0.4.0",
"async-exit-hook": "^2.0.1",
"bluebird-lst": "^1.0.9",
"builder-util": "workspace:*",
Expand Down
221 changes: 220 additions & 1 deletion packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,214 @@
},
"type": "object"
},
"FlatpakOptions": {
"additionalProperties": false,
"properties": {
"artifactName": {
"description": "The [artifact file name template](/configuration/configuration#artifact-file-name-template).",
"type": [
"null",
"string"
]
},
"base": {
"description": "Start with the files from the specified application. This can be used to create applications that extend another application.\nDefaults to [org.electronjs.Electron2.BaseApp](https://github.com/flathub/org.electronjs.Electron2.BaseApp).\n\nSee [flatpak manifest documentation](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest).",
"type": "string"
},
"baseVersion": {
"description": "Use this specific version of the application specified in base. Defaults to `20.08`.\n\nSee [flatpak manifest documentation](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest).",
"type": "string"
},
"branch": {
"description": "The branch to use when exporting the application. Defaults to `master`.\n\nSee [flatpak manifest documentation](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest).",
"type": "string"
},
"category": {
"description": "The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).",
"type": [
"null",
"string"
]
},
"description": {
"description": "As [description](/configuration/configuration#Metadata-description) from application package.json, but allows you to specify different for Linux.",
"type": [
"null",
"string"
]
},
"desktop": {
"description": "The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries (name to value)."
},
"executableArgs": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"description": "The executable parameters. Pass to executableName"
},
"files": {
"description": "Files to copy directly into the app. Should be a list of [source, dest] tuples. Source should be a relative/absolute path to a file/directory to copy into the flatpak, and dest should be the path inside the app install prefix (e.g. /share/applications/).\n\nSee [@malept/flatpak-bundler documentation](https://github.com/malept/flatpak-bundler#build-options).",
"items": {
"items": [
{
"type": "string"
},
{
"type": "string"
}
],
"maxItems": 2,
"minItems": 2,
"type": "array"
},
"type": "array"
},
"finishArgs": {
"description": "An array of arguments passed to the flatpak build-finish command. Defaults to:\n```json\n[\n // Wayland/X11 Rendering\n \"--socket=wayland\",\n \"--socket=x11\",\n \"--share=ipc\",\n // Open GL\n \"--device=dri\",\n // Audio output\n \"--socket=pulseaudio\",\n // Read/write home directory access\n \"--filesystem=home\",\n // Allow communication with network\n \"--share=network\",\n // System notifications with libnotify\n \"--talk-name=org.freedesktop.Notifications\",\n]\n```\n\nSee [flatpak manifest documentation](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest).",
"items": {
"type": "string"
},
"type": "array"
},
"license": {
"description": "The path to EULA license file. Defaults to `license.txt` or `eula.txt` (or uppercase variants). Only plain text is supported.",
"type": [
"null",
"string"
]
},
"mimeTypes": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"description": "The mime types in addition to specified in the file associations. Use it if you don't want to register a new mime type, but reuse existing."
},
"modules": {
"description": "An array of objects specifying the modules to be built in order.\n\nSee [flatpak manifest documentation](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest).",
"items": {},
"type": "array"
},
"publish": {
"anyOf": [
{
"$ref": "#/definitions/GithubOptions"
},
{
"$ref": "#/definitions/S3Options"
},
{
"$ref": "#/definitions/SpacesOptions"
},
{
"$ref": "#/definitions/GenericServerOptions"
},
{
"$ref": "#/definitions/BintrayOptions"
},
{
"$ref": "#/definitions/CustomPublishOptions"
},
{
"$ref": "#/definitions/SnapStoreOptions"
},
{
"items": {
"anyOf": [
{
"$ref": "#/definitions/GithubOptions"
},
{
"$ref": "#/definitions/S3Options"
},
{
"$ref": "#/definitions/SpacesOptions"
},
{
"$ref": "#/definitions/GenericServerOptions"
},
{
"$ref": "#/definitions/BintrayOptions"
},
{
"$ref": "#/definitions/CustomPublishOptions"
},
{
"$ref": "#/definitions/SnapStoreOptions"
},
{
"type": "string"
}
]
},
"type": "array"
},
{
"type": [
"null",
"string"
]
}
]
},
"runtime": {
"description": "The name of the runtime that the application uses. Defaults to `org.freedesktop.Platform`.\n\nSee [flatpak manifest documentation](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest).",
"type": "string"
},
"runtimeVersion": {
"description": "The version of the runtime that the application uses. Defaults to `20.08`.\n\nSee [flatpak manifest documentation](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest).",
"type": "string"
},
"sdk": {
"description": "The name of the development runtime that the application builds with. Defaults to `org.freedesktop.Sdk`.\n\nSee [flatpak manifest documentation](https://docs.flatpak.org/en/latest/flatpak-builder-command-reference.html#flatpak-manifest).",
"type": "string"
},
"symlinks": {
"description": "Symlinks to create in the app files. Should be a list of [target, location] symlink tuples. Target can be either a relative or absolute path inside the app install prefix, and location should be a absolute path inside the prefix to create the symlink at.\n\nSee [@malept/flatpak-bundler documentation](https://github.com/malept/flatpak-bundler#build-options).",
"items": {
"items": [
{
"type": "string"
},
{
"type": "string"
}
],
"maxItems": 2,
"minItems": 2,
"type": "array"
},
"type": "array"
},
"synopsis": {
"description": "The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).",
"type": [
"null",
"string"
]
},
"useWaylandFlags": {
"description": "Whether to enable the Wayland specific flags (`--enable-features=UseOzonePlatform --ozone-platform=wayland`) in the wrapper script. These flags are only available starting with Electron version 12. Defaults to `false`.",
"type": "boolean"
}
},
"type": "object"
},
"GenericServerOptions": {
"additionalProperties": false,
"description": "Generic (any HTTP(S) server) options.\nIn all publish options [File Macros](/file-patterns#file-macros) are supported.",
Expand Down Expand Up @@ -4710,7 +4918,7 @@
"type": "null"
}
],
"description": "The list of Ubuntu packages to use that are needed to support the `app` part creation. Like `depends` for `deb`.\nDefaults to `[\"libasound2\", \"libgconf2-4\", \"libnotify4\", \"libnspr4\", \"libnss3\", \"libpcre3\", \"libpulse0\", \"libxss1\", \"libxtst6\"]`.\n\nIf list contains `default`, it will be replaced to default list, so, `[\"default\", \"foo\"]` can be used to add custom package `foo` in addition to defaults."
"description": "The list of Ubuntu packages to use that are needed to support the `app` part creation. Like `depends` for `deb`.\nDefaults to `[\"libnspr4\", \"libnss3\", \"libxss1\", \"libappindicator3-1\", \"libsecret-1-0\"]`.\n\nIf list contains `default`, it will be replaced to default list, so, `[\"default\", \"foo\"]` can be used to add custom package `foo` in addition to defaults."
},
"summary": {
"description": "The 78 character long summary. Defaults to [productName](/configuration/configuration#Configuration-productName).",
Expand Down Expand Up @@ -5931,6 +6139,17 @@
}
]
},
"flatpak": {
"anyOf": [
{
"$ref": "#/definitions/FlatpakOptions"
},
{
"type": "null"
}
],
"description": "Flatpak options."
},
"forceCodeSigning": {
"default": false,
"description": "Whether to fail if the application is not signed (to prevent unsigned app if code signing configuration is not correct).",
Expand Down
6 changes: 5 additions & 1 deletion packages/app-builder-lib/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BeforeBuildContext, Target } from "./core"
import { ElectronBrandingOptions, ElectronDownloadOptions } from "./electron/ElectronFramework"
import { PrepareApplicationStageDirectoryOptions } from "./Framework"
import { AppXOptions } from "./options/AppXOptions"
import { AppImageOptions, DebOptions, LinuxConfiguration, LinuxTargetSpecificOptions } from "./options/linuxOptions"
import { AppImageOptions, DebOptions, FlatpakOptions, LinuxConfiguration, LinuxTargetSpecificOptions } from "./options/linuxOptions"
import { DmgOptions, MacConfiguration, MasConfiguration } from "./options/macOptions"
import { MsiOptions } from "./options/MsiOptions"
import { PkgOptions } from "./options/pkgOptions"
Expand Down Expand Up @@ -90,6 +90,10 @@ export interface Configuration extends PlatformSpecificBuildOptions {
* AppImage options.
*/
readonly appImage?: AppImageOptions | null
/**
* Flatpak options.
*/
readonly flatpak?: FlatpakOptions | null
readonly pacman?: LinuxTargetSpecificOptions | null
readonly rpm?: LinuxTargetSpecificOptions | null
readonly freebsd?: LinuxTargetSpecificOptions | null
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export { AppXOptions } from "./options/AppXOptions"
export { MsiOptions } from "./options/MsiOptions"
export { CommonWindowsInstallerConfiguration } from "./options/CommonWindowsInstallerConfiguration"
export { NsisOptions, NsisWebOptions, PortableOptions, CommonNsisOptions } from "./targets/nsis/nsisOptions"
export { LinuxConfiguration, DebOptions, CommonLinuxOptions, LinuxTargetSpecificOptions, AppImageOptions } from "./options/linuxOptions"
export { LinuxConfiguration, DebOptions, CommonLinuxOptions, LinuxTargetSpecificOptions, AppImageOptions, FlatpakOptions } from "./options/linuxOptions"
export { SnapOptions } from "./options/SnapOptions"
export { Metadata, AuthorMetadata, RepositoryInfo } from "./options/metadata"
export { AppInfo } from "./appInfo"
Expand Down
7 changes: 5 additions & 2 deletions packages/app-builder-lib/src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Packager } from "./packager"
import { PlatformPackager } from "./platformPackager"
import { RemoteBuilder } from "./remoteBuilder/RemoteBuilder"
import AppImageTarget from "./targets/AppImageTarget"
import FlatpakTarget from "./targets/FlatpakTarget"
import FpmTarget from "./targets/fpm"
import { LinuxTargetHelper } from "./targets/LinuxTargetHelper"
import SnapTarget from "./targets/snap"
Expand All @@ -22,7 +23,7 @@ export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
}

get defaultTarget(): Array<string> {
return ["snap", "appimage"]
return ["snap", "appimage", "flatpak"]
}

createTargets(targets: Array<string>, mapper: (name: string, factory: (outDir: string) => Target) => void): void {
Expand All @@ -41,12 +42,14 @@ export class LinuxPackager extends PlatformPackager<LinuxConfiguration> {
continue
}

const targetClass: typeof AppImageTarget | typeof SnapTarget | typeof FpmTarget | null = (() => {
const targetClass: typeof AppImageTarget | typeof SnapTarget | typeof FlatpakTarget | typeof FpmTarget | null = (() => {
switch (name) {
case "appimage":
return require("./targets/AppImageTarget").default
case "snap":
return require("./targets/snap").default
case "flatpak":
return require("./targets/FlatpakTarget").default
case "deb":
case "rpm":
case "sh":
Expand Down

0 comments on commit 6b1be73

Please sign in to comment.