SurfSense/surfsense_web/contexts/platform-context.tsx
DESKTOP-RTLN3BA\$punk 91ea293fa2 chore: linting
2026-04-07 03:10:06 -07:00

29 lines
783 B
TypeScript

"use client";
import { createContext, type ReactNode, useEffect, useState } from "react";
export interface PlatformContextValue {
isDesktop: boolean;
isWeb: boolean;
electronAPI: ElectronAPI | null;
}
const SSR_VALUE: PlatformContextValue = {
isDesktop: false,
isWeb: false,
electronAPI: null,
};
export const PlatformContext = createContext<PlatformContextValue>(SSR_VALUE);
export function PlatformProvider({ children }: { children: ReactNode }) {
const [value, setValue] = useState<PlatformContextValue>(SSR_VALUE);
useEffect(() => {
const api = window.electronAPI ?? null;
const isDesktop = !!api;
setValue({ isDesktop, isWeb: !isDesktop, electronAPI: api });
}, []);
return <PlatformContext.Provider value={value}>{children}</PlatformContext.Provider>;
}