refactor(ChatBox): use Host abstraction for Electron APIs

Use useHost() for file selection and opening skill folders instead of
window.electronAPI.

Made-with: Cursor
This commit is contained in:
Douglas 2026-04-23 13:47:29 +01:00
parent ae753dc7cd
commit 43ee2b7b53
2 changed files with 6 additions and 2 deletions

View file

@ -12,6 +12,7 @@
// limitations under the License.
// ========= Copyright 2025-2026 @ Eigent.ai All Rights Reserved. =========
import { useHost } from '@/host';
import {
RICH_SKILL_STYLE_CLASSES,
hashSkillLabel,
@ -113,11 +114,12 @@ export function UserMessageRichContent({
variant = 'card',
className,
}: UserMessageRichContentProps) {
const host = useHost();
const contentNodes = parseContentWithTags(content);
const handleOpenSkillFolder = (skillName: string) => {
if (!isSafeSkillFolderName(skillName)) return;
window.electronAPI?.openSkillFolder?.(skillName);
host?.electronAPI?.openSkillFolder?.(skillName);
};
const bodyClass =

View file

@ -20,6 +20,7 @@ import {
proxyFetchGet,
} from '@/api/http';
import useChatStoreAdapter from '@/hooks/useChatStoreAdapter';
import { useHost } from '@/host';
import { generateUniqueId } from '@/lib';
import { proxyUpdateTriggerExecution } from '@/service/triggerApi';
import { useAuthStore } from '@/store/authStore';
@ -46,6 +47,7 @@ const CHAT_SCROLL_BOTTOM_MIN_PX = 128;
const CHAT_SCROLL_BOTTOM_GAP_PX = 8;
export default function ChatBox(): JSX.Element {
const [message, setMessage] = useState<string>('');
const host = useHost();
//Get Chatstore for the active project's task
const { chatStore, projectStore } = useChatStoreAdapter();
@ -675,7 +677,7 @@ export default function ChatBox(): JSX.Element {
// File selection handler
const handleFileSelect = async () => {
try {
const result = await window.electronAPI.selectFile({
const result = await host?.electronAPI?.selectFile({
title: t('chat.select-file'),
filters: [{ name: t('chat.all-files'), extensions: ['*'] }],
});