Skip to content

Commit

Permalink
feat: use iconutil on macOS to convert icns to iconset
Browse files Browse the repository at this point in the history
`libicns` is not required anymore on macOS.
  • Loading branch information
develar committed Sep 19, 2016
1 parent ac4e0ea commit 1ad417f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/develar.xml

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

9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ before_install:
- curl -L https://dl.bintray.com/develar/bin/7za -o /tmp/7za
- chmod +x /tmp/7za
- curl -L https://dl.bintray.com/develar/bin/wine.7z -o /tmp/wine.7z
- brew unlink libpng
# https://github.com/Homebrew/homebrew-core/issues/2987
- brew prune
- rm -rf /usr/local/Cellar/libpng
- /tmp/7za x -aoa /tmp/wine.7z -o/usr/local/Cellar -y
- brew link --overwrite fontconfig libpng freetype gd gnutls jasper libgphoto2 libicns libtasn1 libusb libusb-compat little-cms2 nettle sane-backends webp wine git-lfs gnu-tar dpkg graphicsmagick xz
- /tmp/7za x -o/usr/local/Cellar -y /tmp/wine.7z
- brew link --overwrite fontconfig gd gnutls jasper libgphoto2 libicns libtasn1 libusb libusb-compat little-cms2 nettle openssl sane-backends webp wine git-lfs gnu-tar dpkg xz
- brew install freetype graphicsmagick
- git-lfs pull

install:
Expand Down
2 changes: 1 addition & 1 deletion docs/Multi Platform Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ brew install mono

### To build app for Linux on MacOS:
```
brew install gnu-tar libicns graphicsmagick xz
brew install gnu-tar graphicsmagick xz
```

To build rpm: `brew install rpm`.
Expand Down
72 changes: 52 additions & 20 deletions src/targets/LinuxTargetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class LinuxTargetHelper {
return this.iconsFromDir(path.join(this.packager.buildResourcesDir, "icons"))
}
else {
return this.createFromIcns(await this.packager.getTempFile("electron-builder-linux").then(it => ensureDir(it).thenReturn(it)))
return this.createFromIcns(await this.packager.getTempFile("electron-builder-linux.iconset").then(it => ensureDir(it).thenReturn(it)))
}
}

Expand Down Expand Up @@ -103,39 +103,71 @@ export class LinuxTargetHelper {
return this.iconsFromDir(path.join(__dirname, "..", "..", "templates", "linux", "electron-icons"))
}

const output = await exec("icns2png", ["-x", "-o", tempDir, iconPath])
debug(output)
if (process.platform === "darwin") {
await exec("iconutil", ["--convert", "iconset", "--output", tempDir, iconPath])
const iconFiles = await readdir(tempDir)
const imagePath = iconFiles.includes("icon_512x512.png") ? path.join(tempDir, "icon_512x512.png") : path.join(tempDir, "icon_256x256.png")
this.maxIconPath = imagePath

//noinspection UnnecessaryLocalVariableJS
const imagePath = path.join(tempDir, "icon_256x256x32.png")
function resize(size: number): BluebirdPromise<any> {
const filename = `icon_${size}x${size}.png`

this.maxIconPath = imagePath
if (iconFiles.includes(filename)) {
return BluebirdPromise.resolve()
}

function resize(size: number): BluebirdPromise<any> {
const sizeArg = `${size}x${size}`
return exec("gm", ["convert", "-size", sizeArg, imagePath, "-resize", sizeArg, path.join(tempDir, `icon_${size}x${size}x32.png`)])
}
const sizeArg = `${size}x${size}`
return exec("gm", ["convert", "-size", sizeArg, imagePath, "-resize", sizeArg, path.join(tempDir, filename)])
}

const promises: Array<Promise<any>> = [resize(24), resize(96)]
if (!output.includes("is32")) {
const promises: Array<Promise<any>> = [resize(24), resize(96)]
promises.push(resize(16))
}
if (!output.includes("ih32")) {
promises.push(resize(48))
}
if (!output.toString().includes("icp6")) {
promises.push(resize(64))
}
if (!output.includes("it32")) {
promises.push(resize(128))
await BluebirdPromise.all(promises)

return this.createMappings(tempDir)
}
else {
const output = await exec("icns2png", ["-x", "-o", tempDir, iconPath])
debug(output)

//noinspection UnnecessaryLocalVariableJS
const imagePath = path.join(tempDir, "icon_256x256x32.png")

this.maxIconPath = imagePath

await BluebirdPromise.all(promises)
function resize(size: number): BluebirdPromise<any> {
const sizeArg = `${size}x${size}`
return exec("gm", ["convert", "-size", sizeArg, imagePath, "-resize", sizeArg, path.join(tempDir, `icon_${size}x${size}x32.png`)])
}

const promises: Array<Promise<any>> = [resize(24), resize(96)]
if (!output.includes("is32")) {
promises.push(resize(16))
}
if (!output.includes("ih32")) {
promises.push(resize(48))
}
if (!output.toString().includes("icp6")) {
promises.push(resize(64))
}
if (!output.includes("it32")) {
promises.push(resize(128))
}

await BluebirdPromise.all(promises)

return this.createMappings(tempDir)
}
}

private createMappings(tempDir: string) {
const appName = this.packager.appInfo.name

function createMapping(size: string) {
return [`${tempDir}/icon_${size}x${size}x32.png`, `${size}x${size}/apps/${appName}.png`]
return [process.platform === "darwin" ? `${tempDir}/icon_${size}x${size}.png` : `${tempDir}/icon_${size}x${size}x32.png`, `${size}x${size}/apps/${appName}.png`]
}

return [
Expand Down
2 changes: 1 addition & 1 deletion test/create-bottle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cd /usr/local/Cellar
brew cleanup
brew prune
rm -f ~/wine.7z
7za a -m0=lzma2 -mx=9 -mfb=64 -md=64m -ms=on -xr!man -xr!doc ~/wine.7z libpng fontconfig freetype gd gnutls jasper libgphoto2 libicns libtasn1 libusb libusb-compat little-cms2 nettle openssl sane-backends webp wine git-lfs gnu-tar dpkg graphicsmagick xz
7za a -m0=lzma2 -mx=9 -mfb=64 -md=64m -ms=on -xr!man -xr!doc ~/wine.7z fontconfig gd gnutls jasper libgphoto2 libicns libtasn1 libusb libusb-compat little-cms2 nettle openssl sane-backends webp wine git-lfs gnu-tar dpkg xz

SEC=`security find-generic-password -l BINTRAY_API_KEY -g 2>&1`
ACCOUNT=`echo "$SEC" | grep "acct" | cut -d \" -f 4`
Expand Down

0 comments on commit 1ad417f

Please sign in to comment.