Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.5 KB
Raw Blame
import { cssVar } from '@lobehub/ui';

import { isDesktop } from '@/const/version';
import { MAC_VIBRANCY_BACKGROUND } from '@/features/Electron/system/macWindowFullscreen';
import { useGlobalStore } from '@/store/global';
import { INITIAL_STATUS } from '@/store/global/initialState';
import { systemStatusSelectors } from '@/store/global/selectors';
import { isMacOS } from '@/utils/platform';

export interface BootShellGeometry {
  isDark: boolean;
  navPanelBackground: string;
  navPanelWidth: number;
  showLeftPanel: boolean;
}

const readIsDark = () => {
  try {
    return document.documentElement.dataset.theme === 'dark';
  } catch {
    return false;
  }
};

// Mirrors `NavPanelDraggable`'s panel background so the shell hands over to a
// panel of the same color instead of flashing an opaque block over vibrancy.
const readNavPanelBackground = () =>
  isDesktop && isMacOS() ? MAC_VIBRANCY_BACKGROUND : cssVar.colorBgLayout;

export const readBootShellGeometry = (): BootShellGeometry => {
  const base = {
    isDark: readIsDark(),
    navPanelBackground: readNavPanelBackground(),
  };

  try {
    const state = useGlobalStore.getState();

    return {
      ...base,
      navPanelWidth: systemStatusSelectors.leftPanelWidth(state),
      showLeftPanel: Boolean(systemStatusSelectors.showLeftPanel(state)),
    };
  } catch {
    return {
      ...base,
      navPanelWidth: INITIAL_STATUS.leftPanelWidth,
      showLeftPanel: Boolean(INITIAL_STATUS.showLeftPanel),
    };
  }
};