Skip to content

Commit

Permalink
fix: AppImage desktop icons
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jul 5, 2016
1 parent a9afdd4 commit 9a69286
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 281 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dist/
/typings/browser.d.ts
/typings/main.d.ts
.DS_Store
.idea/shelf/
.idea/shelf/
test/typings/electron-builder.d.ts
14 changes: 14 additions & 0 deletions .idea/bashsupport_project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Complete solution to package and build ready for distribution and "auto update"
* Numerous target formats:
* All platforms: `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`.
* [MacOS](https://github.com/electron-userland/electron-builder/wiki/Options#MacOptions-target): `dmg`, `mas`.
* [Linux](https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-target): `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
* [Linux](https://github.com/electron-userland/electron-builder/wiki/Options#LinuxBuildOptions-target): `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
* [Windows](https://github.com/electron-userland/electron-builder/wiki/Options#WinBuildOptions-target): NSIS, Squirrel.Windows.
* [Publishing artifacts to GitHub Releases](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts).

Expand Down
2 changes: 1 addition & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ Linux specific build options.
| Name | Description
| --- | ---
| description | <a name="LinuxBuildOptions-description"></a>As [description](#AppMetadata-description) from application package.json, but allows you to specify different for Linux.
| target | <a name="LinuxBuildOptions-target"></a><p>Target package type: list of <code>AppImage</code>, <code>deb</code>, <code>rpm</code>, <code>freebsd</code>, <code>pacman</code>, <code>p5p</code>, <code>apk</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>. Defaults to <code>deb</code>.</p> <p>The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.</p> <p>Only <code>deb</code> and <code>AppImage</code> is tested. Feel free to file issues for <code>rpm</code> and other package formats.</p>
| synopsis | <a name="LinuxBuildOptions-synopsis"></a>*deb-only.* The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).
| maintainer | <a name="LinuxBuildOptions-maintainer"></a>The maintainer. Defaults to [author](#AppMetadata-author).
| vendor | <a name="LinuxBuildOptions-vendor"></a>The vendor. Defaults to [author](#AppMetadata-author).
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. Defaults to `xz`.
| depends | <a name="LinuxBuildOptions-depends"></a>Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
| target | <a name="LinuxBuildOptions-target"></a><p>Target package type: list of <code>deb</code>, <code>rpm</code>, <code>freebsd</code>, <code>pacman</code>, <code>p5p</code>, <code>apk</code>, <code>7z</code>, <code>zip</code>, <code>tar.xz</code>, <code>tar.lz</code>, <code>tar.gz</code>, <code>tar.bz2</code>. Defaults to <code>deb</code>.</p> <p>The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.</p> <p>Only <code>deb</code> is tested. Feel free to file issues for <code>rpm</code> and other package formats.</p>

<a name="MetadataDirectories"></a>
## `.directories`
Expand Down
24 changes: 10 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
},
"scripts": {
"compile": "npm run compile-production && npm run compile-test",
"compile-production": "tsconfig -i 2 && ts-babel",
"compile-test": "tsconfig -i 2 test && ts-babel test",
"compile-production": "ts-babel",
"compile-test": "ts-babel test",
"lint": "tslint src/*.ts test/src/*.ts",
"pretest": "npm run compile && npm run lint",
"test": "node ./test/out/helpers/runTests.js",
Expand Down Expand Up @@ -83,7 +83,7 @@
"semver": "^5.2.0",
"signcode-tf": "~0.7.3",
"source-map-support": "^0.4.1",
"typescript": "^2.0.0-dev.20160630",
"typescript": "2.0.0-dev.20160705",
"update-notifier": "^1.0.2",
"uuid-1345": "^0.99.6",
"yargs": "^4.7.1"
Expand All @@ -100,11 +100,11 @@
]
},
"devDependencies": {
"@types/debug": "0.0.22-alpha",
"@types/mime": "0.0.25-alpha",
"@types/progress": "^1.1.24-alpha",
"@types/semver": "^4.3.23-alpha",
"@types/source-map-support": "^0.2.24-alpha",
"@types/debug": "0.0.26-alpha",
"@types/mime": "0.0.26-alpha",
"@types/progress": "^1.1.25-alpha",
"@types/semver": "^4.3.24-alpha",
"@types/source-map-support": "^0.2.25-alpha",
"ava-tf": "^0.15.3",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-es2015-destructuring": "^6.9.0",
Expand All @@ -119,8 +119,7 @@
"semantic-release": "^6.3.0",
"should": "^9.0.2",
"ts-babel": "^1.0.3",
"tsconfig-glob": "^0.4.3",
"tslint": "3.12.0-dev.1",
"tslint": "3.13.0",
"typescript": "2.0.0-dev.20160620-1.0",
"whitespace": "^2.0.0"
},
Expand All @@ -139,8 +138,5 @@
"test/out/*.js"
]
},
"typings": "./out/electron-builder.d.ts",
"publishConfig": {
"tag": "next"
}
"typings": "./out/electron-builder.d.ts"
}
1 change: 1 addition & 0 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export function normalizeOptions(args: CliOptions): BuildOptions {
delete r.w
delete r.windows
delete r.osx
delete r.macos
delete r["$0"]
delete r._
delete r.version
Expand Down
20 changes: 11 additions & 9 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export interface BuildMetadata {
*/
readonly linux?: LinuxBuildOptions | null

readonly deb?: LinuxBuildOptions | null

/*
The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
*/
Expand Down Expand Up @@ -391,6 +393,15 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
*/
readonly description?: string | null

/*
Target package type: list of `AppImage`, `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `deb`.
The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.
Only `deb` and `AppImage` is tested. Feel free to file issues for `rpm` and other package formats.
*/
readonly target?: Array<string> | null

/*
*deb-only.* The [short description](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description).
*/
Expand Down Expand Up @@ -424,15 +435,6 @@ export interface LinuxBuildOptions extends PlatformSpecificBuildOptions {
Package dependencies. Defaults to `["libappindicator1", "libnotify-bin"]`.
*/
readonly depends?: string[] | null

/*
Target package type: list of `deb`, `rpm`, `freebsd`, `pacman`, `p5p`, `apk`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`. Defaults to `deb`.
The most effective [xz](https://en.wikipedia.org/wiki/Xz) compression format used by default.
Only `deb` is tested. Feel free to file issues for `rpm` and other package formats.
*/
readonly target?: Array<string> | null
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class LinuxTargetHelper {
}
}

async computeDesktopEntry(exec?: string): Promise<string> {
async computeDesktopEntry(exec?: string, extra?: string): Promise<string> {
const appInfo = this.packager.appInfo

const custom = this.packager.platformSpecificBuildOptions.desktop
Expand All @@ -81,7 +81,7 @@ Exec=${(exec == null ? `"${installPrefix}/${productFilename}/${productFilename}"
Terminal=false
Type=Application
Icon=${appInfo.name}
`)
${extra == null ? "" : `${extra}\n`}`)
return tempFile
}

Expand Down
26 changes: 16 additions & 10 deletions src/targets/appImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ import { Promise as BluebirdPromise } from "bluebird"
const __awaiter = require("../util/awaiter")

const appImageVersion = "AppImage-5"
//noinspection SpellCheckingInspection
const appImagePathPromise = getBin("AppImage", appImageVersion, `https://dl.bintray.com/electron-userland/bin/${appImageVersion}.7z`, "19833e5db3cbc546432de8ddc8a54181489e6faad4944bd1f3138adf4b771259")

export default class AppImageTarget extends TargetEx {
private readonly desktopEntry: Promise<string>

constructor(private packager: PlatformPackager<LinuxBuildOptions>, private helper: LinuxTargetHelper, private outDir: string) {
super("appImage")

this.desktopEntry = helper.computeDesktopEntry("AppRun", `X-AppImage-Version=${packager.appInfo.buildVersion}`)
}

async build(appOutDir: string, arch: Arch): Promise<any> {
Expand All @@ -33,6 +38,7 @@ export default class AppImageTarget extends TargetEx {
"-padding", "0",
"-map", appOutDir, "/usr/bin",
"-map", path.join(__dirname, "..", "..", "templates", "linux", "AppRun.sh"), `/AppRun`,
"-map", await this.desktopEntry, `/${appInfo.name}.desktop`,
"-move", `/usr/bin/${appInfo.productFilename}`, "/usr/bin/app",
]
for (let [from, to] of (await this.helper.icons)) {
Expand All @@ -50,17 +56,17 @@ export default class AppImageTarget extends TargetEx {

await exec(process.platform === "darwin" ? path.join(appImagePath, "xorriso") : "xorriso", args)

await new BluebirdPromise((resolve, reject) => {
const rd = createReadStream(path.join(appImagePath, arch === Arch.ia32 ? "32" : "64", "runtime"))
rd.on("error", reject)
const wr = createWriteStream(image)
wr.on("error", reject)
wr.on("finish", resolve)
rd.pipe(wr)
})

const fd = await open(image, "r+")
try {
await new BluebirdPromise((resolve, reject) => {
const rd = createReadStream(path.join(appImagePath, arch === Arch.ia32 ? "32" : "64", "runtime"))
rd.on("error", reject)
const wr = createWriteStream(image, <any>{fd: fd, autoClose: false})
wr.on("error", reject)
wr.on("finish", resolve)
rd.pipe(wr)
})

const magicData = new Buffer([0x41, 0x49, 0x01])
await write(fd, magicData, 0, magicData.length, 8)
}
Expand All @@ -72,7 +78,7 @@ export default class AppImageTarget extends TargetEx {
// we archive because you cannot distribute exe as is - e.g. Ubuntu clear exec flag and user cannot just click on AppImage to run
// also, LZMA compression - 29MB vs zip 42MB
// we use slow xz instead of 7za because 7za doesn't preserve exec file permissions for xz
await spawn("xz", ["--compress", "--force", image], {
await spawn("xz", ["--x86", "--lzma2", "--compress", "--force", packager.devMetadata.build.compression === "store" ? "-0" : "-9e", image], {
cwd: path.dirname(image),
stdio: ["ignore", debug.enabled ? "inherit" : "ignore", "inherit"],
})
Expand Down
5 changes: 2 additions & 3 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import * as path from "path"
import { readJson, stat, Stats, unlink } from "fs-extra-p"
import { yellow, red } from "chalk"
import debugFactory = require("debug")
import IDebugger = debug.IDebugger
import { warn, task, log } from "./log"
import { createHash } from "crypto"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")

export const debug: IDebugger = debugFactory("electron-builder")
export const debug7z: IDebugger = debugFactory("electron-builder:7z")
export const debug = debugFactory("electron-builder")
export const debug7z = debugFactory("electron-builder:7z")

const DEFAULT_APP_DIR_NAMES = ["app", "www"]

Expand Down
Loading

0 comments on commit 9a69286

Please sign in to comment.