* chore: bump cortex 1.0.11-rc10 * chore: bump to latest cortex release * feat: Cortex API Authorization * chore: correct CI CD repo name * chore: correct new menloresearch repo name * feat: rotate api token for each run (#4820) * feat: rotate api token for each run * chore: correct github repo url * chore: correct github api url * chore: should not filter out models first launch * chore: bump cortex release * chore: should get hardware information on launch (#4821) * chore: should have an option to not revalidate hardware information * chore: cortex.cpp gpu activation could cause a race condition (#4825) * fix: jan beta logo displayed in jan release (#4828) --------- Co-authored-by: David <davidpt.janai@gmail.com> Co-authored-by: Nguyen Ngoc Minh <91668012+Minh141120@users.noreply.github.com>
93 lines
2.6 KiB
TypeScript
93 lines
2.6 KiB
TypeScript
'use client'
|
|
|
|
import { Fragment, useEffect } from 'react'
|
|
|
|
import {
|
|
AppConfiguration,
|
|
EngineEvent,
|
|
events,
|
|
getUserHomePath,
|
|
} from '@janhq/core'
|
|
import { useSetAtom } from 'jotai'
|
|
|
|
import { useDebouncedCallback } from 'use-debounce'
|
|
|
|
import useAssistants from '@/hooks/useAssistants'
|
|
import { useGetEngines } from '@/hooks/useEngineManagement'
|
|
import useGetSystemResources from '@/hooks/useGetSystemResources'
|
|
import { useGetHardwareInfo } from '@/hooks/useHardwareManagement'
|
|
import useModels from '@/hooks/useModels'
|
|
import useThreads from '@/hooks/useThreads'
|
|
|
|
import { SettingScreenList } from '@/screens/Settings'
|
|
|
|
import { defaultJanDataFolderAtom } from '@/helpers/atoms/App.atom'
|
|
import {
|
|
janDataFolderPathAtom,
|
|
quickAskEnabledAtom,
|
|
} from '@/helpers/atoms/AppConfig.atom'
|
|
import { janSettingScreenAtom } from '@/helpers/atoms/Setting.atom'
|
|
|
|
const DataLoader: React.FC = () => {
|
|
const setJanDataFolderPath = useSetAtom(janDataFolderPathAtom)
|
|
const setQuickAskEnabled = useSetAtom(quickAskEnabledAtom)
|
|
const setJanDefaultDataFolder = useSetAtom(defaultJanDataFolderAtom)
|
|
const setJanSettingScreen = useSetAtom(janSettingScreenAtom)
|
|
const { getData: loadModels } = useModels()
|
|
const { mutate } = useGetEngines()
|
|
const { mutate: getHardwareInfo } = useGetHardwareInfo(false)
|
|
|
|
useThreads()
|
|
useAssistants()
|
|
useGetSystemResources()
|
|
|
|
useEffect(() => {
|
|
// Load data once
|
|
loadModels()
|
|
getHardwareInfo()
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [])
|
|
const reloadData = useDebouncedCallback(() => {
|
|
mutate()
|
|
}, 300)
|
|
|
|
useEffect(() => {
|
|
events.on(EngineEvent.OnEngineUpdate, reloadData)
|
|
return () => {
|
|
// Remove listener on unmount
|
|
events.off(EngineEvent.OnEngineUpdate, reloadData)
|
|
}
|
|
}, [reloadData])
|
|
|
|
useEffect(() => {
|
|
window.core?.api
|
|
?.getAppConfigurations()
|
|
?.then((appConfig: AppConfiguration) => {
|
|
setJanDataFolderPath(appConfig.data_folder)
|
|
setQuickAskEnabled(appConfig.quick_ask)
|
|
})
|
|
}, [setJanDataFolderPath, setQuickAskEnabled])
|
|
|
|
useEffect(() => {
|
|
async function getDefaultJanDataFolder() {
|
|
const defaultJanDataFolder = await getUserHomePath()
|
|
|
|
setJanDefaultDataFolder(defaultJanDataFolder)
|
|
}
|
|
getDefaultJanDataFolder()
|
|
}, [setJanDefaultDataFolder])
|
|
|
|
useEffect(() => {
|
|
const janSettingScreen = SettingScreenList.filter(
|
|
(screen) => window.electronAPI || screen !== 'Extensions'
|
|
)
|
|
setJanSettingScreen(janSettingScreen)
|
|
}, [setJanSettingScreen])
|
|
|
|
console.debug('Load Data...')
|
|
|
|
return <Fragment></Fragment>
|
|
}
|
|
|
|
export default DataLoader
|