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.

2.7 KB
Raw Blame
import {
  type DataSyncConfig,
  type ElectronAppState,
  type GatewayConnectionError,
  type GatewayConnectionStatus,
  type NetworkProxySettings,
} from '@lobechat/electron-client-ipc';

import { createReplicaState, type ReplicaState } from '@/libs/replica';

import { type CurrentRouteMetaState } from './actions/currentRouteMeta';
import { currentRouteMetaInitialState } from './actions/currentRouteMeta';
import { type GatewayDeviceInfo } from './actions/gateway';
import { type RecentPagesState } from './actions/recentPages';
import { recentPagesInitialState } from './actions/recentPages';
import { type TabPagesState } from './actions/tabPages';
import { tabPagesInitialState } from './actions/tabPages';
import { type GatewayStableDeviceId } from './projection';

export type RemoteServerError = 'CONFIG_ERROR' | 'AUTH_ERROR' | 'DISCONNECT_ERROR';

export const defaultProxySettings: NetworkProxySettings = {
  enableProxy: false,
  proxyBypass: 'localhost, 127.0.0.1, ::1',
  proxyPort: '',
  proxyRequireAuth: false,
  proxyServer: '',
  proxyType: 'http',
};

export interface ElectronState extends CurrentRouteMetaState, RecentPagesState, TabPagesState {
  appState: ElectronAppState;
  appTrayVisible: boolean;
  dataSyncConfig: DataSyncConfig;
  desktopHotkeys: Record<string, string>;
  /** Why the last connection attempt ended, as reported by the main process. */
  gatewayConnectionError?: GatewayConnectionError;
  gatewayConnectionStatus: GatewayConnectionStatus;
  gatewayDeviceInfo?: GatewayDeviceInfo;
  /** Replica view of this desktop's stable gateway device id (`GATEWAY_STABLE_DEVICE_ID_KEY`). */
  gatewayStableDeviceIdMap: Record<string, GatewayStableDeviceId>;
  /** Replica bookkeeping of `gatewayStableDeviceIdMap`. */
  gatewayStableDeviceIdReplica: ReplicaState<GatewayStableDeviceId>;
  isAppStateInit?: boolean;
  isConnectingServer?: boolean;
  isConnectionDrawerOpen?: boolean;
  isDesktopHotkeysInit: boolean;
  isInitRemoteServerConfig: boolean;
  isSyncActive?: boolean;
  proxySettings: NetworkProxySettings;
  remoteServerSyncError?: { message?: string; type: RemoteServerError };
}

export const initialState: ElectronState = {
  ...currentRouteMetaInitialState,
  ...recentPagesInitialState,
  ...tabPagesInitialState,
  appState: {},
  appTrayVisible: true,
  dataSyncConfig: { storageMode: 'cloud' },
  desktopHotkeys: {},
  gatewayConnectionStatus: 'disconnected',
  gatewayStableDeviceIdMap: {},
  gatewayStableDeviceIdReplica: createReplicaState(),
  isAppStateInit: false,
  isConnectingServer: false,
  isConnectionDrawerOpen: false,
  isDesktopHotkeysInit: false,
  isInitRemoteServerConfig: false,
  isSyncActive: false,
  proxySettings: defaultProxySettings,
};