Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

1.1 KB
Raw Blame
import { useEffect, useState } from 'react';

/** The shell's `md` breakpoint. Exported as a number too, because layout
 *  budgeting has to do arithmetic with it and a second literal would drift. */
export const DESKTOP_MIN_WIDTH = 768;
export const DESKTOP_MEDIA_QUERY = `(min-width: ${DESKTOP_MIN_WIDTH}px)`;

type MatchMediaOwner = Pick<Window, 'matchMedia'>;

export function isDesktopViewport(
  targetWindow: MatchMediaOwner | null = typeof window === 'undefined' ? null : window,
): boolean {
  return Boolean(targetWindow?.matchMedia?.(DESKTOP_MEDIA_QUERY).matches);
}

/** Reactive counterpart to the shell's `md` desktop breakpoint. */
export function useIsDesktop(): boolean {
  const [isDesktop, setIsDesktop] = useState(isDesktopViewport);

  useEffect(() => {
    if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;
    const media = window.matchMedia(DESKTOP_MEDIA_QUERY);
    const sync = () => setIsDesktop(media.matches);
    sync();
    media.addEventListener('change', sync);
    return () => media.removeEventListener('change', sync);
  }, []);

  return isDesktop;
}