Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

1.1 KB
Raw Blame
import { useCallback, useEffect, useState } from 'react';

import {
  getSessionRuntimeFallbackEnabled,
  setSessionRuntimeFallbackEnabled,
  subscribeSessionRuntimeFallbackEnabled,
} from '@/lib/sessionRuntimeFallbackStore';

export function useSessionRuntimeFallback() {
  const [enabled, setEnabledState] = useState(getSessionRuntimeFallbackEnabled);
  const [isCustomized, setIsCustomized] = useState(false);
  const setEnabled = useCallback((next: boolean) => setSessionRuntimeFallbackEnabled(next), []);

  useEffect(() => {
    let cancelled = false;
    void window.electronAPI.maker
      .sessionRuntimeFallbackGet()
      .then((settings) => {
        if (cancelled) return;
        setSessionRuntimeFallbackEnabled(settings.enabled);
        setEnabledState(settings.enabled);
        setIsCustomized(Boolean(settings.isCustomized));
      })
      .catch(() => undefined);
    const unsubscribe = subscribeSessionRuntimeFallbackEnabled(setEnabledState);
    return () => {
      cancelled = true;
      unsubscribe();
    };
  }, []);

  return { enabled, isCustomized, setEnabled, setIsCustomized };
}