mattrguerra/cortexmainPrivate on GitHub, published here in full

index.ts

Language TypeScript678 B23 lines

src/ipc/index.ts

  1. import type { IpcClient } from './client'
  2. declare global {
  3. interface Window {
  4. __TAURI_INTERNALS__?: unknown
  5. }
  6. }
  7. // Inside the app: the real shell. In a browser (tests, screenshots, `npm run
  8. // dev` without Tauri): sample data, so the interface is always explorable.
  9. const inTauri = typeof window !== 'undefined' && !!window.__TAURI_INTERNALS__
  10. let client: IpcClient | null = null
  11. export async function ipc(): Promise<IpcClient> {
  12. if (client) return client
  13. if (inTauri && import.meta.env.VITE_IPC !== 'mock') {
  14. client = (await import('./tauri')).tauriClient
  15. } else {
  16. client = (await import('./mock/mockClient')).createMockClient()
  17. }
  18. return client
  19. }