Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/platforms/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SourceImage,
sourceImages,
} from "../helpers";
import { Platform, uniformIconOptions } from "./base";
import { OptionalMixin, Platform, uniformIconOptions } from "./base";

interface Icon {
readonly src: string;
Expand All @@ -27,7 +27,7 @@ interface Shortcut {
readonly icons?: Icon[];
}

const ICONS_OPTIONS: NamedIconOptions[] = [
const ICONS_OPTIONS: (NamedIconOptions & OptionalMixin)[] = [
{ name: "android-chrome-36x36.png", ...transparentIcon(36) },
{ name: "android-chrome-48x48.png", ...transparentIcon(48) },
{ name: "android-chrome-72x72.png", ...transparentIcon(72) },
Expand All @@ -37,6 +37,7 @@ const ICONS_OPTIONS: NamedIconOptions[] = [
{ name: "android-chrome-256x256.png", ...transparentIcon(256) },
{ name: "android-chrome-384x384.png", ...transparentIcon(384) },
{ name: "android-chrome-512x512.png", ...transparentIcon(512) },
{ name: "android-chrome.svg", ...transparentIcon(1024), optional: true },
];

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

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

return {
src: this.cacheBusting(relativeTo(basePath, iconOptions.name)),
sizes: `${width}x${height}`,
type: "image/png",
purpose: iconOptions.purpose ?? defaultPurpose,
};
if (iconOptions.name.endsWith(".svg")) {
return { src, sizes: "any", type: "image/svg+xml", purpose };
} else {
// png
const { width, height } = iconOptions.sizes[0];
return { src, sizes: `${width}x${height}`, type: "image/png", purpose };
}
});

if (Array.isArray(options.shortcuts) && options.shortcuts.length > 0) {
Expand Down
17 changes: 17 additions & 0 deletions test/svgOutput.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,20 @@ test("should generate svg favicon", async () => {
});
await expect(roundtripResult).toMatchFaviconsSnapshot();
});

test("should generate svg as a android icon", async () => {
expect.assertions(1);

const result = await favicons(logo_svg, {
icons: {
favicons: false,
android: ["android-chrome.svg"],
appleIcon: false,
appleStartup: false,
windows: false,
yandex: false,
},
});

await expect(result).toMatchFaviconsSnapshot();
});
Loading