usePlatformusePlatform

현재 OS와 실행 셸, Mod가 가리키는 키를 알려줍니다.The current OS, the shell the page runs in and the key behind Mod.

사용법Usage

composer.tsx
import { isModKey, usePlatform } from "@horon-ai/react";

function Composer({ onStart }: { onStart: () => void }) {
  const { os } = usePlatform();
  return (
    <textarea
      onKeyDown={(event) => {
        if (event.key === "Enter" && isModKey(event, os)) onStart();
      }}
    />
  );
}

시그니처Signature

use-platform.ts
export type ModKey = "meta" | "ctrl";

export type Platform = {
  os: "macos" | "windows" | "linux" | "ios" | "android" | "unknown";
  runtime: "web" | "desktop";
  modKey: ModKey;
};

export function usePlatform(): Platform

매개변수Parameters

매개변수가 없습니다.Takes no parameters.

반환값Returns

현재 Platform을 돌려줍니다. os, runtime, modKey 세 필드입니다.The current Platform: os, runtime and modKey.

동작과 주의Behavior notes

  • os는 navigator와 window에서 한 번만 읽고 페이지가 살아 있는 동안 그 값을 재사용합니다. 구독할 저장소가 없어 훅이 스스로 다시 렌더되지 않습니다.The value is read from navigator and window once and cached for the life of the page: there is no store to subscribe to, so the hook never re-renders on its own.
  • 서버 렌더와 첫 하이드레이션 패스는 unknown, web, meta를 받아 Mac 키를 그립니다. 클라이언트에서는 첫 렌더부터 감지한 플랫폼을 보고합니다.A server render and the first hydration pass get unknown, web and meta, which draws the Mac keys; on the client the first render already reports the detected platform.
  • os는 macos, windows, linux, ios, android, unknown 중 하나입니다. 서버에서는 unknown입니다.os is one of macos, windows, linux, ios, android or unknown, and unknown on the server.
  • runtime은 Tauri나 Electron 안에서 desktop, 그 밖에는 서버를 포함해 web입니다.runtime is desktop inside the Tauri shell or Electron, and web everywhere else including the server.
  • modKey는 windows, linux, android에서 ctrl이고 나머지는 meta입니다. keydown 검사에 그대로 쓸 수 있습니다.modKey is ctrl on Windows, Linux and Android and meta elsewhere, ready for a keydown check.