2026-04-07 00:43:40 -07:00
|
|
|
"use client";
|
|
|
|
|
|
2026-04-07 03:10:06 -07:00
|
|
|
import { createContext, type ReactNode, useEffect, useState } from "react";
|
2026-04-07 00:43:40 -07:00
|
|
|
|
|
|
|
|
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 });
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-04-07 03:10:06 -07:00
|
|
|
return <PlatformContext.Provider value={value}>{children}</PlatformContext.Provider>;
|
2026-04-07 00:43:40 -07:00
|
|
|
}
|