2025-12-07 19:32:53 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import type { RuntimeAPISelector, RuntimeAPIs } from '@/lib/api/types';
|
|
|
|
|
import { RuntimeAPIContext } from '@/contexts/runtimeAPIContext';
|
|
|
|
|
|
|
|
|
|
export const useRuntimeAPIs = (): RuntimeAPIs => {
|
|
|
|
|
const apis = React.useContext(RuntimeAPIContext);
|
|
|
|
|
if (!apis) {
|
|
|
|
|
throw new Error('Runtime APIs are not available. Did you forget to wrap the app in <RuntimeAPIProvider>?');
|
|
|
|
|
}
|
|
|
|
|
return apis;
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-26 19:27:53 +03:00
|
|
|
const useRuntimeAPI = <TValue,>(selector: RuntimeAPISelector<TValue>): TValue => {
|
2025-12-07 19:32:53 +02:00
|
|
|
const apis = useRuntimeAPIs();
|
|
|
|
|
return selector(apis);
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-13 16:34:17 +02:00
|
|
|
export const useIsVSCodeRuntime = (): boolean => useRuntimeAPI((api) => api.runtime.isVSCode);
|