Skip to content

Commit

Permalink
fix(mac): don't fail if the icon path given doesn't exist (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Jan 13, 2020
1 parent 3090c4c commit 291680b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/mac.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ class MacApp extends App {
/* istanbul ignore next */
return Promise.resolve()
}
debug(`Copying icon "${icon}" to app's Resources as "${this.appPlist.CFBundleIconFile}"`)
await fs.copy(icon, path.join(this.originalResourcesDir, this.appPlist.CFBundleIconFile))
if (icon) {
debug(`Copying icon "${icon}" to app's Resources as "${this.appPlist.CFBundleIconFile}"`)
await fs.copy(icon, path.join(this.originalResourcesDir, this.appPlist.CFBundleIconFile))
}
}

async renameAppAndHelpers () {
Expand Down
3 changes: 3 additions & 0 deletions src/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class App {

if (await fs.pathExists(iconFilename)) {
return iconFilename
} else {
/* istanbul ignore next */
common.warning(`Could not find icon "${iconFilename}", not updating app icon`)
}
}

Expand Down
18 changes: 18 additions & 0 deletions test/darwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const config = require('./config.json')
const childProcess = require('child_process')
const crypto = require('crypto')
const fs = require('fs-extra')
const mac = require('../src/mac')
const packager = require('..')
Expand Down Expand Up @@ -207,6 +208,23 @@ if (!(process.env.CI && process.platform === 'win32')) {
test.serial('macOS icon: .icns specified', darwinTest(iconTest, icnsPath, icnsPath))
test.serial('macOS icon: .ico specified (should replace with .icns)', darwinTest(iconTest, `${iconBase}.ico`, icnsPath))
test.serial('macOS icon: basename only (should add .icns)', darwinTest(iconTest, iconBase, icnsPath))
test.serial('macOS icon: invalid icon path should skip copy', darwinTest(async (t, opts) => {
let expectedChecksum
opts.icon = path.join(__dirname, 'fixtures', 'nonexistent')
opts.afterExtract = [
async (extractPath, _electronVersion, _platform, _arch, callback) => {
const hash = crypto.createHash('sha256')
hash.update(await fs.readFile(path.join(extractPath, 'Electron.app', 'Contents', 'Resources', 'electron.icns')))
expectedChecksum = hash.digest('hex')
callback()
}
]

const finalPath = (await packager(opts))[0]
const hash = crypto.createHash('sha256')
hash.update(await fs.readFile(path.join(finalPath, `${opts.name}.app`, 'Contents', 'Resources', 'electron.icns')))
return t.is(hash.digest('hex'), expectedChecksum, 'Icon should not have been overwritten')
}))

const extraInfoPath = path.join(__dirname, 'fixtures', 'extrainfo.plist')
const extraInfoParams = plist.parse(fs.readFileSync(extraInfoPath).toString())
Expand Down

0 comments on commit 291680b

Please sign in to comment.