mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-07-17 05:08:36 +00:00
|
Some checks failed
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Pre-commit / pre-commit (push) Has been cancelled
Test / Run Web + Local Brain Smoke (push) Has been cancelled
Test / Run Frontend Guardrails (push) Has been cancelled
Test / Run Python Tests (push) Has been cancelled
Co-authored-by: Douglas <douglas.ym.lai@gmail.com> Co-authored-by: Douglas Lai <115660088+Douglasymlai@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Tao Sun <168447269+fengju0213@users.noreply.github.com> Co-authored-by: Weijie Bai <happy.regina.bai@gmail.com> |
||
|---|---|---|
| .. | ||
| context.tsx | ||
| createHost.ts | ||
| index.ts | ||
| README.md | ||
| types.ts | ||
Host 抽象层
统一桌面(Electron)与 Web 的能力注入,避免在业务代码中显式判断运行环境。
使用方式
import { useHost } from '@/host';
function MyComponent() {
const host = useHost();
// host.electronAPI / host.ipcRenderer 在 Web 下为 null
if (host?.electronAPI?.someMethod) {
host.electronAPI.someMethod();
}
}
初始化
main.tsx 中通过 createHost() 创建 host,由 HostProvider 注入。createHost() 是唯一读取 window 的地方。
后续扩展
- 桌面端若用其他技术栈(Tauri、原生等)重构,只需提供新的 host 实现
- CLI、Browser Extension 等可复用同一套 React 组件,注入不同的 host