fix: respect color scheme in PWA manifest theme color
This commit is contained in:
1 parent
2b1a03849d
commit
bdb2e8478d
2 files changed
+28
-3
No files matched your search
@@ -68,6 +68,13 @@ const nextConfig: NextConfig = {
|
|||||||
// eslint-disable-next-line @typescript-eslint/require-await,no-restricted-syntax
|
// eslint-disable-next-line @typescript-eslint/require-await,no-restricted-syntax
|
||||||
async headers() {
|
async headers() {
|
||||||
return [
|
return [
|
||||||
|
{
|
||||||
|
source: "/manifest.webmanifest",
|
||||||
|
headers: [
|
||||||
|
{ key: "Accept-CH", value: "Sec-CH-Prefers-Color-Scheme" },
|
||||||
|
{ key: "Vary", value: "Sec-CH-Prefers-Color-Scheme" },
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
source: "/sw.js",
|
source: "/sw.js",
|
||||||
headers: [
|
headers: [
|
||||||
|
|||||||
@@ -1,14 +1,32 @@
|
|||||||
import type { MetadataRoute } from "next";
|
import type { MetadataRoute } from "next";
|
||||||
|
import { headers } from "next/headers";
|
||||||
|
|
||||||
|
import { getCurrentColorSchemeAsync } from "~/theme/color-scheme";
|
||||||
|
|
||||||
|
const themeColors = {
|
||||||
|
light: "#fff",
|
||||||
|
dark: "#242424",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export default async function manifest(): Promise<MetadataRoute.Manifest> {
|
||||||
|
const colorScheme = await getCurrentColorSchemeAsync();
|
||||||
|
const resolvedColorScheme =
|
||||||
|
colorScheme === "auto"
|
||||||
|
? (await headers()).get("sec-ch-prefers-color-scheme") === "dark"
|
||||||
|
? "dark"
|
||||||
|
: "light"
|
||||||
|
: colorScheme;
|
||||||
|
|
||||||
|
const themeColor = themeColors[resolvedColorScheme];
|
||||||
|
|
||||||
export default function manifest(): MetadataRoute.Manifest {
|
|
||||||
return {
|
return {
|
||||||
name: "Homarr",
|
name: "Homarr",
|
||||||
short_name: "Homarr",
|
short_name: "Homarr",
|
||||||
description: "Your dashboard for managing your server.",
|
description: "Your dashboard for managing your server.",
|
||||||
start_url: "/",
|
start_url: "/",
|
||||||
display: "standalone",
|
display: "standalone",
|
||||||
background_color: "#fff",
|
background_color: themeColor,
|
||||||
theme_color: "#fff",
|
theme_color: themeColor,
|
||||||
icons: [
|
icons: [
|
||||||
{
|
{
|
||||||
src: "/images/pwa/192.maskable.png",
|
src: "/images/pwa/192.maskable.png",
|
||||||
|
|||||||
Reference in new issue
Block a user