diff --git a/hooks/use-device-detection.ts b/hooks/use-device-detection.ts index 17581445..c6dfef10 100644 --- a/hooks/use-device-detection.ts +++ b/hooks/use-device-detection.ts @@ -1,17 +1,28 @@ import { useMediaQuery } from '@darkroom.engineering/hamo' -import { useOrchestra } from '~/libs/orchestra/react' import { breakpoints } from '~/styles/config.mjs' +interface NavigatorWithBattery extends Navigator { + getBattery(): Promise<{ charging: boolean; level: number }> +} + export function useDeviceDetection() { const breakpoint = breakpoints.dt - const { webgl } = useOrchestra() - const isMobile = useMediaQuery(`(max-width: ${breakpoint - 1}px)`) const isDesktop = useMediaQuery(`(min-width: ${breakpoint}px)`) const isReducedMotion = useMediaQuery('(prefers-reduced-motion: reduce)') - const isWebGL = isDesktop && !isReducedMotion && webgl - // TODO: const isLowPowerMode + const isWebGL = isDesktop && !isReducedMotion + + // test thoroughly + const isLowPowerMode = + useMediaQuery('(any-pointer: coarse) and (hover: none)') && + 'getBattery' in navigator && + (navigator as NavigatorWithBattery) + .getBattery() + .then( + (battery: { charging: boolean; level: number }) => + battery.charging === false && battery.level <= 0.2 + ) - return { isMobile, isDesktop, isReducedMotion, isWebGL } + return { isMobile, isDesktop, isReducedMotion, isWebGL, isLowPowerMode } } diff --git a/hooks/use-fouc-fix.ts b/hooks/use-fouc-fix.ts deleted file mode 100644 index 52b308a5..00000000 --- a/hooks/use-fouc-fix.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { useEffect } from 'react' - -// Temporary fix to avoid flash of unstyled content (FOUC) during route transitions. -// Keep an eye on this issue and remove this code when resolved: https://github.com/vercel/next.js/issues/17464 -export function useFoucFix() { - useEffect(() => { - // Gather all server-side rendered stylesheet entries. - let stylesheets = Array.from( - document.querySelectorAll('link[rel="stylesheet"][data-n-p]') - ).map((element) => ({ - element, - href: element.getAttribute('href'), - })) - - // Remove the `data-n-p` attribute to prevent Next.js from removing it early. - for (const { element } of stylesheets) { - element.removeAttribute('data-n-p') - } - - const hrefs: string[] = [] - - const mutationHandler = (mutations: MutationRecord[]) => { - // Gather all