getDesktopPlatform (lib/desktop-platform.ts)

nexu · apps/web/src/lib/desktop-platform.ts · typescript · MIT
infra, tag:knn-classified

Utility to detect desktop platform (win32, darwin, linux) via env or navigator.

// Source: https://github.com/nexu-io/nexu | License: MIT | Copyright 2026 Powerformer, Inc
// Provided via justclaw.it.com; keep this notice with the code.
export function getDesktopPlatform(): string | null {
  // Prefer the build-time env injected by desktop packaging / dev scripts.
  const envValue = import.meta.env.VITE_DESKTOP_PLATFORM;
  if (typeof envValue === "string" && envValue.trim().length > 0) {
    return envValue;
  }
  // Fallback: detect at runtime via navigator so dev-mode webviews
  // (where Vite may not receive the env) still get the correct platform.
  if (typeof navigator !== "undefined") {
    const ua = navigator.userAgent.toLowerCase();
    if (ua.includes("win")) return "win32";
    if (ua.includes("mac")) return "darwin";
    if (ua.includes("linux")) return "l

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key