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;QACxB,kBAAkB;QAClB,cAAc;QACd,aAAa;QACb,UAAU;QACV,cAAc;QACd,eAAe;QACf,qBAAqB;QACrB,mCAAmC;QACnC,mBAAmB;QACnB,mCAAmC;QACnC,iBAAiB;QACjB,sCAAsC;QACtC,2CAA2C;KAC5C;CACF,CAAA;AAED,SAAS,wBAAwB,CAAC,cAAsB,EAAE,eAAwB;IAChF,OAAO,eAAe;QACpB,CAAC,CAAC;;;;;qBAKe,cAAc;;qBAEd,cAAc;;CAElC;QACG,CAAC,CAAC;;;;iBAIW,cAAc;CAC9B,CAAA;AACD,CAAC;AAED,SAAS,0BAA0B,CAAC,UAAkB;IACpD,sGAAsG;IACtG,6FAA6F;IAC7F,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAA;AACrE,CAAC","sourcesContent":["import { bundle as bundleFlatpak, FlatpakBundlerBuildOptions, FlatpakManifest } from \"@malept/flatpak-bundler\"\nimport { Arch, copyFile, toLinuxArchString } from \"builder-util\"\nimport { chmod, outputFile } from \"fs-extra\"\nimport * as path from \"path\"\nimport { Target } from \"../core\"\nimport { LinuxPackager } from \"../linuxPackager\"\nimport { FlatpakOptions } from \"../options/linuxOptions\"\nimport { getNotLocalizedLicenseFile } from \"../util/license\"\nimport { LinuxTargetHelper } from \"./LinuxTargetHelper\"\nimport { createStageDir, StageDir } from \"./targetUtil\"\n\nexport default class FlatpakTarget extends Target {\n readonly options: FlatpakOptions = {\n ...this.packager.platformSpecificBuildOptions,\n ...(this.packager.config as any)[this.name],\n }\n\n constructor(name: string, private readonly packager: LinuxPackager, private helper: LinuxTargetHelper, readonly outDir: string) {\n super(name)\n }\n\n get appId(): string {\n return filterFlatpakAppIdentifier(this.packager.appInfo.id)\n }\n\n async build(appOutDir: string, arch: Arch): Promise {\n const { packager, options } = this\n const artifactName = packager.expandArtifactNamePattern(options, \"flatpak\", arch, undefined, false)\n const artifactPath = path.join(this.outDir, artifactName)\n await packager.info.callArtifactBuildStarted({\n targetPresentableName: \"flatpak\",\n file: artifactPath,\n arch,\n })\n\n const stageDir = await this.prepareStageDir(arch)\n\n const { manifest, buildOptions } = this.getFlatpakBuilderOptions(appOutDir, stageDir.dir, artifactName, arch)\n await bundleFlatpak(manifest, buildOptions)\n\n await stageDir.cleanup()\n\n await packager.info.callArtifactBuildCompleted({\n file: artifactPath,\n safeArtifactName: packager.computeSafeArtifactName(artifactName, \"flatpak\", arch, false),\n target: this,\n arch,\n packager,\n isWriteUpdateInfo: false,\n })\n }\n\n private async prepareStageDir(arch: Arch): Promise {\n const stageDir = await createStageDir(this, this.packager, arch)\n\n await Promise.all([this.createSandboxBinWrapper(stageDir), this.createDesktopFile(stageDir), this.copyLicenseFile(stageDir), this.copyIcons(stageDir)])\n\n return stageDir\n }\n\n private async createSandboxBinWrapper(stageDir: StageDir) {\n const useWaylandFlags = !!this.options.useWaylandFlags\n const electronWrapperPath = stageDir.getTempFile(path.join(\"bin\", \"electron-wrapper\"))\n await outputFile(electronWrapperPath, getElectronWrapperScript(this.packager.executableName, useWaylandFlags))\n await chmod(electronWrapperPath, 0o755)\n }\n\n private async createDesktopFile(stageDir: StageDir) {\n const appIdentifier = this.appId\n const desktopFile = stageDir.getTempFile(path.join(\"share\", \"applications\", `${appIdentifier}.desktop`))\n await this.helper.writeDesktopEntry(this.options, \"electron-wrapper %U\", desktopFile, { Icon: appIdentifier })\n }\n\n private async copyLicenseFile(stageDir: StageDir) {\n const licenseSrc = await getNotLocalizedLicenseFile(this.options.license, this.packager, [\"txt\", \"html\"])\n if (licenseSrc) {\n const licenseDst = stageDir.getTempFile(path.join(\"share\", \"doc\", this.appId, \"copyright\"))\n await copyFile(licenseSrc, licenseDst)\n }\n }\n\n private async copyIcons(stageDir: StageDir) {\n const icons = await this.helper.icons\n const copyIcons = icons.map(async icon => {\n const extWithDot = path.extname(icon.file)\n const sizeName = extWithDot === \".svg\" ? \"scalable\" : `${icon.size}x${icon.size}`\n const iconDst = stageDir.getTempFile(path.join(\"share\", \"icons\", \"hicolor\", sizeName, \"apps\", `${this.appId}${extWithDot}`))\n\n return copyFile(icon.file, iconDst)\n })\n\n await Promise.all(copyIcons)\n }\n\n private getFlatpakBuilderOptions(appOutDir: string, stageDir: string, artifactName: string, arch: Arch): { manifest: FlatpakManifest; buildOptions: FlatpakBundlerBuildOptions } {\n const appIdentifier = this.appId\n const { executableName } = this.packager\n const flatpakArch = toLinuxArchString(arch, \"flatpak\")\n\n const manifest: FlatpakManifest = {\n id: appIdentifier,\n command: \"electron-wrapper\",\n runtime: this.options.runtime || flatpakBuilderDefaults.runtime,\n runtimeVersion: this.options.runtimeVersion || flatpakBuilderDefaults.runtimeVersion,\n sdk: this.options.sdk || flatpakBuilderDefaults.sdk,\n base: this.options.base || flatpakBuilderDefaults.base,\n baseVersion: this.options.baseVersion || flatpakBuilderDefaults.baseVersion,\n finishArgs: this.options.finishArgs || flatpakBuilderDefaults.finishArgs,\n branch: this.options.branch,\n modules: this.options.modules,\n }\n\n const buildOptions: FlatpakBundlerBuildOptions = {\n baseFlatpakref: `app/${manifest.base}/${flatpakArch}/${manifest.baseVersion}`,\n runtimeFlatpakref: `runtime/${manifest.runtime}/${flatpakArch}/${manifest.runtimeVersion}`,\n sdkFlatpakref: `runtime/${manifest.sdk}/${flatpakArch}/${manifest.runtimeVersion}`,\n arch: flatpakArch as any,\n bundlePath: path.join(this.outDir, artifactName),\n files: [[stageDir, \"/\"], [appOutDir, path.join(\"/lib\", appIdentifier)], ...(this.options.files || [])],\n symlinks: [[path.join(\"/lib\", appIdentifier, executableName), path.join(\"/bin\", executableName)], ...(this.options.symlinks || [])],\n }\n\n return { manifest, buildOptions }\n }\n}\n\nconst flatpakBuilderDefaults: Omit = {\n runtime: \"org.freedesktop.Platform\",\n runtimeVersion: \"20.08\",\n sdk: \"org.freedesktop.Sdk\",\n base: \"org.electronjs.Electron2.BaseApp\",\n baseVersion: \"20.08\",\n finishArgs: [\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\nfunction getElectronWrapperScript(executableName: string, useWaylandFlags: boolean): string {\n return useWaylandFlags\n ? `#!/bin/sh\n\nexport TMPDIR=\"$XDG_RUNTIME_DIR/app/$FLATPAK_ID\"\n\nif [ \"\\${XDG_SESSION_TYPE}\" == \"wayland\" ]; then\n zypak-wrapper \"${executableName}\" --enable-features=UseOzonePlatform --ozone-platform=wayland \"$@\"\nelse\n zypak-wrapper \"${executableName}\" \"$@\"\nfi\n`\n : `#!/bin/sh\n\nexport TMPDIR=\"$XDG_RUNTIME_DIR/app/$FLATPAK_ID\"\n\nzypak-wrapper \"${executableName}\" \"$@\"\n`\n}\n\nfunction filterFlatpakAppIdentifier(identifier: string) {\n // Remove special characters and allow only alphanumeric (A-Z,a-z,0-9), underscore (_), and period (.)\n // Flatpak documentation: https://docs.flatpak.org/en/latest/conventions.html#application-ids\n return identifier.replace(/-/g, \"_\").replace(/[^a-zA-Z0-9._]/g, \"\")\n}\n"]}