Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

1.5 KB
Raw Blame
"use client";

import type { RefObject, PointerEvent as ReactPointerEvent } from "react";

/* Pull-DOWN gesture (Android quick-settings shade). Same hardening as the
   other shell gestures: fires AT the threshold during move (robust against
   pointercancel — Android Chrome reclaims touches mid-gesture), and an
   optional scrollRef keeps a scrollable child working: the pull only arms
   when that element is at its top. */
export function usePullDown(
  // startX (viewport px) lets a caller split the gesture by half — e.g. Android
  // pulls LEFT→notifications, RIGHT→Control Center. Existing callers ignore it.
  onPull: (startX: number) => void,
  scrollRef?: RefObject<HTMLElement | null>,
): (e: ReactPointerEvent) => void {
  return (e: ReactPointerEvent) => {
    const scroller = scrollRef?.current;
    if (scroller && scroller.contains(e.target as Node) && scroller.scrollTop > 0) return;
    const sx = e.clientX;
    const sy = e.clientY;
    const cleanup = () => {
      window.removeEventListener("pointermove", move);
      window.removeEventListener("pointerup", end);
      window.removeEventListener("pointercancel", end);
    };
    const move = (ev: PointerEvent) => {
      const dx = ev.clientX - sx;
      const dy = ev.clientY - sy;
      if (dy > 60 && dy > Math.abs(dx)) {
        cleanup();
        onPull(sx);
      }
    };
    const end = () => cleanup();
    window.addEventListener("pointermove", move);
    window.addEventListener("pointerup", end);
    window.addEventListener("pointercancel", end);
  };
}