import os from "node:os"; import { MIN_DARWIN_MAJOR } from "./constants.ts"; export type PlatformSupport = | { ok: true } | { ok: false; reason: string }; export type PlatformInfo = { platform: NodeJS.Platform; /** Darwin kernel release string, e.g. `25.5.0`. */ release: string; }; /** * Caps Lock LED control is supported on macOS 26+ only (Darwin major >= 25). */ export function checkPlatformSupport( info: PlatformInfo = { platform: process.platform, release: os.release(), }, ): PlatformSupport { if (info.platform !== "darwin") { return { ok: false, reason: `pi-caps-blink is macOS-only (got ${info.platform})`, }; } const major = Number.parseInt(info.release.split(".")[0] ?? "", 10); if (!Number.isFinite(major) || major < MIN_DARWIN_MAJOR) { return { ok: false, reason: `pi-caps-blink requires macOS 26+ (Darwin ${MIN_DARWIN_MAJOR}+; got ${info.release})`, }; } return { ok: true }; }