Skip to content

Commit ccb7702

Browse files
committed
Optional support of SVG icons for Android/Chrome
1 parent 3a5a0a9 commit ccb7702

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/platforms/android.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
SourceImage,
1212
sourceImages,
1313
} from "../helpers";
14-
import { Platform, uniformIconOptions } from "./base";
14+
import { OptionalMixin, Platform, uniformIconOptions } from "./base";
1515

1616
interface Icon {
1717
readonly src: string;
@@ -27,7 +27,7 @@ interface Shortcut {
2727
readonly icons?: Icon[];
2828
}
2929

30-
const ICONS_OPTIONS: NamedIconOptions[] = [
30+
const ICONS_OPTIONS: (NamedIconOptions & OptionalMixin)[] = [
3131
{ name: "android-chrome-36x36.png", ...transparentIcon(36) },
3232
{ name: "android-chrome-48x48.png", ...transparentIcon(48) },
3333
{ name: "android-chrome-72x72.png", ...transparentIcon(72) },
@@ -37,6 +37,7 @@ const ICONS_OPTIONS: NamedIconOptions[] = [
3737
{ name: "android-chrome-256x256.png", ...transparentIcon(256) },
3838
{ name: "android-chrome-384x384.png", ...transparentIcon(384) },
3939
{ name: "android-chrome-512x512.png", ...transparentIcon(512) },
40+
{ name: "android-chrome.svg", ...transparentIcon(1024), optional: true },
4041
];
4142

4243
const ICONS_OPTIONS_MASKABLE: NamedIconOptions[] = [
@@ -243,14 +244,16 @@ export class AndroidPlatform extends Platform {
243244
options.manifestMaskable === true ? "any maskable" : "any";
244245

245246
properties.icons = icons.map((iconOptions) => {
246-
const { width, height } = iconOptions.sizes[0];
247+
const src = this.cacheBusting(relativeTo(basePath, iconOptions.name));
248+
const purpose = iconOptions.purpose ?? defaultPurpose;
247249

248-
return {
249-
src: this.cacheBusting(relativeTo(basePath, iconOptions.name)),
250-
sizes: `${width}x${height}`,
251-
type: "image/png",
252-
purpose: iconOptions.purpose ?? defaultPurpose,
253-
};
250+
if (iconOptions.name.endsWith(".svg")) {
251+
return { src, sizes: "any", type: "image/svg+xml", purpose };
252+
} else {
253+
// png
254+
const { width, height } = iconOptions.sizes[0];
255+
return { src, sizes: `${width}x${height}`, type: "image/png", purpose };
256+
}
254257
});
255258

256259
if (Array.isArray(options.shortcuts) && options.shortcuts.length > 0) {

test/svgOutput.test.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,20 @@ test("should generate svg favicon", async () => {
5757
});
5858
await expect(roundtripResult).toMatchFaviconsSnapshot();
5959
});
60+
61+
test("should generate svg as a android icon", async () => {
62+
expect.assertions(1);
63+
64+
const result = await favicons(logo_svg, {
65+
icons: {
66+
favicons: false,
67+
android: ["android-chrome.svg"],
68+
appleIcon: false,
69+
appleStartup: false,
70+
windows: false,
71+
yandex: false,
72+
},
73+
});
74+
75+
await expect(result).toMatchFaviconsSnapshot();
76+
});

0 commit comments

Comments
 (0)