Skip to content

Commit

Permalink
fix(cli.js): .ico icon generation, closes #2692 (#2694)
Browse files Browse the repository at this point in the history
* fix(cli.js): `.ico` icon generation, closes #2692

* fmt

* chore: cleanup resize logic
  • Loading branch information
lucasfernog committed Oct 2, 2021
1 parent 45573ae commit 11db96e
Show file tree
Hide file tree
Showing 5 changed files with 556 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changes/cli.js-fix-ico.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cli.js": patch
---

Fixes `.ico` icon generation.
20 changes: 10 additions & 10 deletions tooling/api/src/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,12 +861,12 @@ class WindowManager extends WebviewWindowHandle {
type: 'setMinSize',
payload: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
type: size.type,
data: {
width: size.width,
height: size.height
}
}
}
: null
}
}
Expand Down Expand Up @@ -903,12 +903,12 @@ class WindowManager extends WebviewWindowHandle {
type: 'setMaxSize',
payload: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
type: size.type,
data: {
width: size.width,
height: size.height
}
}
}
: null
}
}
Expand Down
1 change: 1 addition & 0 deletions tooling/cli.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"is-png": "3.0.1",
"minimist": "1.2.5",
"ms": "2.1.3",
"png-to-ico": "2.1.2",
"png2icons": "2.0.1",
"read-chunk": "4.0.2",
"semver": "7.3.5",
Expand Down
16 changes: 13 additions & 3 deletions tooling/cli.js/src/api/tauricon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const { access, ensureDir, ensureFileSync, writeFileSync } = fsExtra.default
const require = createRequire(import.meta.url)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { version } = require('../../package.json')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pngToIco = require('png-to-ico')

const log = logger('app:spawn')
const warn = logger('app:spawn', chalk.red)
Expand Down Expand Up @@ -498,8 +500,16 @@ const tauricon = {
}
await this.validate(src, target)

const sharpSrc = sharp(src)
const buf = await sharpSrc.toBuffer()
const s = sharp(src)
const metadata = await s.metadata()
const buf = await s.toBuffer()
let icoBuf
if (metadata.width !== metadata.height) {
const size = Math.min(metadata.width ?? 256, metadata.height ?? 256)
icoBuf = await s.resize(size, size).toBuffer()
} else {
icoBuf = await s.toBuffer()
}

const out = png2icons.createICNS(buf, png2icons.BICUBIC, 0)
if (out === null) {
Expand All @@ -508,7 +518,7 @@ const tauricon = {
ensureFileSync(path.join(target, '/icon.icns'))
writeFileSync(path.join(target, '/icon.icns'), out)

const out2 = png2icons.createICO(buf, png2icons.BICUBIC, 0, true)
const out2 = await pngToIco(icoBuf)
if (out2 === null) {
throw new Error('Failed to create icon.ico')
}
Expand Down
Loading

0 comments on commit 11db96e

Please sign in to comment.