Skip to content

Commit de11289

Browse files
committed
fix: generate icons on the fly
1 parent 51fb3b8 commit de11289

File tree

10 files changed

+33
-9
lines changed

10 files changed

+33
-9
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ out/
44
coverage/
55
.version-update
66
.env
7+
8+
public/icons/

build-icons.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Svg2 from "oslllo-svg2"
2+
import { join } from 'path'
3+
import { mkdirSync } from "fs"
4+
5+
const indir = 'icons'
6+
const outdir = 'public/icons'
7+
const svgs = ['icon-grey.svg', 'icon.svg']
8+
const sizes = [48, 96]
9+
10+
mkdirSync(outdir, { recursive: true })
11+
12+
for (let svgfile of svgs) {
13+
const instance = Svg2(join(indir, svgfile))
14+
const svg = instance.svg
15+
16+
const pngfile = svgfile.replace(/\.svg$/,'.png')
17+
for (const size of sizes) {
18+
svg.resize({ width: size, height: size })
19+
await instance.png().background('#0000').toFile(join(outdir, `${size}-${pngfile}`))
20+
}
21+
}

bun.lockb

33.9 KB
Binary file not shown.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"url": "git+https://github.com/nobkd/replace-maps.git"
1616
},
1717
"scripts": {
18-
"icons": "inkscape -w 48 -h 48 icons/icon.svg -o public/icons/48.png && inkscape -w 48 -h 48 icons/icon-grey.svg -o public/icons/48-grey.png && inkscape -w 96 -h 96 icons/icon.svg -o public/icons/96.png && inkscape -w 96 -h 96 icons/icon-grey.svg -o public/icons/96-grey.png",
18+
"postinstall": "bun build-icons.js",
1919
"format": "prettier . --check",
2020
"format:fix": "npm run format -- --write",
2121
"test": "vitest run",
@@ -34,6 +34,7 @@
3434
"@types/webextension-polyfill": "^0.10.7",
3535
"@vitest/coverage-v8": "^1.6.0",
3636
"npm-run-all": "^4.1.5",
37+
"oslllo-svg2": "^2.0.2",
3738
"prettier": "^3.3.2",
3839
"release-it": "^17.4.0",
3940
"release-it-changelogen": "^0.1.0",

public/icons/48-grey.png

-1.89 KB
Binary file not shown.

public/icons/48.png

-1.96 KB
Binary file not shown.

public/icons/96-grey.png

-3.54 KB
Binary file not shown.

public/icons/96.png

-3.75 KB
Binary file not shown.

public/manifest.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"version": "0.0.6",
66
"homepage_url": "https://github.com/nobkd/replace-maps",
77
"icons": {
8-
"48": "icons/48.png",
9-
"96": "icons/96.png"
8+
"48": "icons/48-icon.png",
9+
"96": "icons/96-icon.png"
1010
},
1111
"browser_specific_settings": {
1212
"gecko": {
@@ -28,8 +28,8 @@
2828
"web_accessible_resources": ["map.html"],
2929
"browser_action": {
3030
"default_icon": {
31-
"48": "icons/48.png",
32-
"96": "icons/96.png"
31+
"48": "icons/48-icon.png",
32+
"96": "icons/96-icon.png"
3333
},
3434
"default_area": "navbar",
3535
"default_title": "Replace Maps"

src/bg/utils/actionIcon.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ export function updateIcon(hostname) {
1111
browserAction.setIcon({
1212
path: !disabled
1313
? {
14-
48: '/icons/48.png',
15-
96: '/icons/96.png',
14+
48: '/icons/48-icon.png',
15+
96: '/icons/96-icon.png',
1616
}
1717
: {
18-
48: '/icons/48-grey.png',
19-
96: '/icons/96-grey.png',
18+
48: '/icons/48-icon-grey.png',
19+
96: '/icons/96-icon-grey.png',
2020
},
2121
})
2222
}

0 commit comments

Comments
 (0)