Skip to content

Commit 1ad417f

Browse files
committed
feat: use iconutil on macOS to convert icns to iconset
`libicns` is not required anymore on macOS.
1 parent ac4e0ea commit 1ad417f

File tree

5 files changed

+59
-28
lines changed

5 files changed

+59
-28
lines changed

.idea/dictionaries/develar.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ before_install:
2222
- curl -L https://dl.bintray.com/develar/bin/7za -o /tmp/7za
2323
- chmod +x /tmp/7za
2424
- curl -L https://dl.bintray.com/develar/bin/wine.7z -o /tmp/wine.7z
25-
- brew unlink libpng
26-
# https://github.com/Homebrew/homebrew-core/issues/2987
27-
- brew prune
28-
- rm -rf /usr/local/Cellar/libpng
29-
- /tmp/7za x -aoa /tmp/wine.7z -o/usr/local/Cellar -y
30-
- 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
25+
- /tmp/7za x -o/usr/local/Cellar -y /tmp/wine.7z
26+
- 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
27+
- brew install freetype graphicsmagick
3128
- git-lfs pull
3229

3330
install:

docs/Multi Platform Build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ brew install mono
3232

3333
### To build app for Linux on MacOS:
3434
```
35-
brew install gnu-tar libicns graphicsmagick xz
35+
brew install gnu-tar graphicsmagick xz
3636
```
3737

3838
To build rpm: `brew install rpm`.

src/targets/LinuxTargetHelper.ts

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class LinuxTargetHelper {
2626
return this.iconsFromDir(path.join(this.packager.buildResourcesDir, "icons"))
2727
}
2828
else {
29-
return this.createFromIcns(await this.packager.getTempFile("electron-builder-linux").then(it => ensureDir(it).thenReturn(it)))
29+
return this.createFromIcns(await this.packager.getTempFile("electron-builder-linux.iconset").then(it => ensureDir(it).thenReturn(it)))
3030
}
3131
}
3232

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

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

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

112-
this.maxIconPath = imagePath
115+
if (iconFiles.includes(filename)) {
116+
return BluebirdPromise.resolve()
117+
}
113118

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

119-
const promises: Array<Promise<any>> = [resize(24), resize(96)]
120-
if (!output.includes("is32")) {
123+
const promises: Array<Promise<any>> = [resize(24), resize(96)]
121124
promises.push(resize(16))
122-
}
123-
if (!output.includes("ih32")) {
124125
promises.push(resize(48))
125-
}
126-
if (!output.toString().includes("icp6")) {
127126
promises.push(resize(64))
128-
}
129-
if (!output.includes("it32")) {
130127
promises.push(resize(128))
128+
await BluebirdPromise.all(promises)
129+
130+
return this.createMappings(tempDir)
131131
}
132+
else {
133+
const output = await exec("icns2png", ["-x", "-o", tempDir, iconPath])
134+
debug(output)
135+
136+
//noinspection UnnecessaryLocalVariableJS
137+
const imagePath = path.join(tempDir, "icon_256x256x32.png")
138+
139+
this.maxIconPath = imagePath
132140

133-
await BluebirdPromise.all(promises)
141+
function resize(size: number): BluebirdPromise<any> {
142+
const sizeArg = `${size}x${size}`
143+
return exec("gm", ["convert", "-size", sizeArg, imagePath, "-resize", sizeArg, path.join(tempDir, `icon_${size}x${size}x32.png`)])
144+
}
145+
146+
const promises: Array<Promise<any>> = [resize(24), resize(96)]
147+
if (!output.includes("is32")) {
148+
promises.push(resize(16))
149+
}
150+
if (!output.includes("ih32")) {
151+
promises.push(resize(48))
152+
}
153+
if (!output.toString().includes("icp6")) {
154+
promises.push(resize(64))
155+
}
156+
if (!output.includes("it32")) {
157+
promises.push(resize(128))
158+
}
159+
160+
await BluebirdPromise.all(promises)
161+
162+
return this.createMappings(tempDir)
163+
}
164+
}
134165

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

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

141173
return [

test/create-bottle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cd /usr/local/Cellar
55
brew cleanup
66
brew prune
77
rm -f ~/wine.7z
8-
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
8+
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
99

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

0 commit comments

Comments
 (0)