Skip to content

Commit 11db96e

Browse files
authored
fix(cli.js): .ico icon generation, closes #2692 (#2694)
* fix(cli.js): `.ico` icon generation, closes #2692 * fmt * chore: cleanup resize logic
1 parent 45573ae commit 11db96e

File tree

5 files changed

+556
-14
lines changed

5 files changed

+556
-14
lines changed

.changes/cli.js-fix-ico.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.js": patch
3+
---
4+
5+
Fixes `.ico` icon generation.

tooling/api/src/window.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -861,12 +861,12 @@ class WindowManager extends WebviewWindowHandle {
861861
type: 'setMinSize',
862862
payload: size
863863
? {
864-
type: size.type,
865-
data: {
866-
width: size.width,
867-
height: size.height
864+
type: size.type,
865+
data: {
866+
width: size.width,
867+
height: size.height
868+
}
868869
}
869-
}
870870
: null
871871
}
872872
}
@@ -903,12 +903,12 @@ class WindowManager extends WebviewWindowHandle {
903903
type: 'setMaxSize',
904904
payload: size
905905
? {
906-
type: size.type,
907-
data: {
908-
width: size.width,
909-
height: size.height
906+
type: size.type,
907+
data: {
908+
width: size.width,
909+
height: size.height
910+
}
910911
}
911-
}
912912
: null
913913
}
914914
}

tooling/cli.js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"is-png": "3.0.1",
6565
"minimist": "1.2.5",
6666
"ms": "2.1.3",
67+
"png-to-ico": "2.1.2",
6768
"png2icons": "2.0.1",
6869
"read-chunk": "4.0.2",
6970
"semver": "7.3.5",

tooling/cli.js/src/api/tauricon.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const { access, ensureDir, ensureFileSync, writeFileSync } = fsExtra.default
3939
const require = createRequire(import.meta.url)
4040
// eslint-disable-next-line @typescript-eslint/no-var-requires
4141
const { version } = require('../../package.json')
42+
// eslint-disable-next-line @typescript-eslint/no-var-requires
43+
const pngToIco = require('png-to-ico')
4244

4345
const log = logger('app:spawn')
4446
const warn = logger('app:spawn', chalk.red)
@@ -498,8 +500,16 @@ const tauricon = {
498500
}
499501
await this.validate(src, target)
500502

501-
const sharpSrc = sharp(src)
502-
const buf = await sharpSrc.toBuffer()
503+
const s = sharp(src)
504+
const metadata = await s.metadata()
505+
const buf = await s.toBuffer()
506+
let icoBuf
507+
if (metadata.width !== metadata.height) {
508+
const size = Math.min(metadata.width ?? 256, metadata.height ?? 256)
509+
icoBuf = await s.resize(size, size).toBuffer()
510+
} else {
511+
icoBuf = await s.toBuffer()
512+
}
503513

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

511-
const out2 = png2icons.createICO(buf, png2icons.BICUBIC, 0, true)
521+
const out2 = await pngToIco(icoBuf)
512522
if (out2 === null) {
513523
throw new Error('Failed to create icon.ico')
514524
}

0 commit comments

Comments
 (0)