feat: integrate MCP server initialization into app initialization process
- Added useInitMCPServers hook to manage MCP server state and communication with the main process. - Updated useAppInit to include useInitMCPServers for improved server management during app initialization.
This commit is contained in:
parent
8c5273d47d
commit
555c5baafa
@ -10,6 +10,7 @@ import { useEffect } from 'react'
|
|||||||
|
|
||||||
import { useDefaultModel } from './useAssistant'
|
import { useDefaultModel } from './useAssistant'
|
||||||
import useFullScreenNotice from './useFullScreenNotice'
|
import useFullScreenNotice from './useFullScreenNotice'
|
||||||
|
import { useInitMCPServers } from './useMCPServers'
|
||||||
import { useRuntime } from './useRuntime'
|
import { useRuntime } from './useRuntime'
|
||||||
import { useSettings } from './useSettings'
|
import { useSettings } from './useSettings'
|
||||||
import useUpdateHandler from './useUpdateHandler'
|
import useUpdateHandler from './useUpdateHandler'
|
||||||
@ -22,8 +23,8 @@ export function useAppInit() {
|
|||||||
const avatar = useLiveQuery(() => db.settings.get('image://avatar'))
|
const avatar = useLiveQuery(() => db.settings.get('image://avatar'))
|
||||||
|
|
||||||
useUpdateHandler()
|
useUpdateHandler()
|
||||||
|
|
||||||
useFullScreenNotice()
|
useFullScreenNotice()
|
||||||
|
useInitMCPServers()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
avatar?.value && dispatch(setAvatar(avatar.value))
|
avatar?.value && dispatch(setAvatar(avatar.value))
|
||||||
|
|||||||
@ -10,19 +10,10 @@ ipcRenderer.on('mcp:servers-changed', (_event, servers) => {
|
|||||||
store.dispatch(setMCPServers(servers))
|
store.dispatch(setMCPServers(servers))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Send initial servers state to main process
|
|
||||||
const initialServers = store.getState().mcp.servers
|
|
||||||
ipcRenderer.send('mcp:servers-from-renderer', initialServers)
|
|
||||||
|
|
||||||
export const useMCPServers = () => {
|
export const useMCPServers = () => {
|
||||||
const mcpServers = useAppSelector((state) => state.mcp.servers)
|
const mcpServers = useAppSelector((state) => state.mcp.servers)
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
|
|
||||||
// Send servers to main process when they change in Redux
|
|
||||||
useEffect(() => {
|
|
||||||
ipcRenderer.send('mcp:servers-from-renderer', mcpServers)
|
|
||||||
}, [mcpServers])
|
|
||||||
|
|
||||||
// Initial load of MCP servers from main process
|
// Initial load of MCP servers from main process
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadServers = async () => {
|
const loadServers = async () => {
|
||||||
@ -90,3 +81,12 @@ export const useMCPServers = () => {
|
|||||||
getActiveMCPServers
|
getActiveMCPServers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useInitMCPServers = () => {
|
||||||
|
const mcpServers = useAppSelector((state) => state.mcp.servers)
|
||||||
|
|
||||||
|
// Send servers to main process when they change in Redux
|
||||||
|
useEffect(() => {
|
||||||
|
ipcRenderer.send('mcp:servers-from-renderer', mcpServers)
|
||||||
|
}, [mcpServers])
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user