diff --git a/web/hooks/useGetSystemResources.ts b/web/hooks/useGetSystemResources.ts index 40c9b578a7..e40100a55a 100644 --- a/web/hooks/useGetSystemResources.ts +++ b/web/hooks/useGetSystemResources.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import { useCallback, useEffect, useState } from 'react' import { ExtensionTypeEnum, HardwareManagementExtension } from '@janhq/core' @@ -83,7 +84,7 @@ export default function useGetSystemResources() { setRamUtilitized, setCpuUsage, setGpus, - // setTotalNvidiaVram, + setTotalNvidiaVram, setAvailableVram, ]) diff --git a/web/screens/Settings/Engines/LocalEngineSettings.tsx b/web/screens/Settings/Engines/LocalEngineSettings.tsx index c324f1b932..e19accffd4 100644 --- a/web/screens/Settings/Engines/LocalEngineSettings.tsx +++ b/web/screens/Settings/Engines/LocalEngineSettings.tsx @@ -9,6 +9,7 @@ import { } from '@janhq/core' import { Button, ScrollArea, Badge, Select, Progress } from '@janhq/joi' +import { useAtom } from 'jotai' import { twMerge } from 'tailwind-merge' import { useActiveModel } from '@/hooks/useActiveModel' @@ -27,8 +28,8 @@ import { formatDownloadPercentage } from '@/utils/converter' import ExtensionSetting from '../ExtensionSetting' import DeleteEngineVariant from './DeleteEngineVariant' + import { LocalEngineDefaultVariantAtom } from '@/helpers/atoms/App.atom' -import { useAtom } from 'jotai' const os = () => { switch (PLATFORM) { case 'win32': @@ -104,7 +105,7 @@ const LocalEngineSettings = ({ engine }: { engine: InferenceEngine }) => { if (defaultEngineVariant?.variant) { setSelectedVariants(defaultEngineVariant.variant || '') } - }, [defaultEngineVariant]) + }, [defaultEngineVariant, setSelectedVariants]) const handleEngineUpdate = useCallback( async (event: { id: string; type: DownloadEvent; percent: number }) => { diff --git a/web/services/appService.test.ts b/web/services/appService.test.ts index e64fb143e8..c4360f7e5c 100644 --- a/web/services/appService.test.ts +++ b/web/services/appService.test.ts @@ -2,36 +2,33 @@ import { extensionManager } from '@/extension' import { appService } from './appService' test('should return correct system information when monitoring extension is found', async () => { - const mockGpuSetting = { name: 'NVIDIA GeForce GTX 1080', memory: 8192 } - const mockOsInfo = { platform: 'win32', release: '10.0.19041' } - const mockHardwareInfo = { - cpu: { arch: 'arc' }, - ram: { available: 4000, total: 8000 }, - } - const mockMonitoringExtension = { - getGpuSetting: jest.fn().mockResolvedValue(mockGpuSetting), - getOsInfo: jest.fn().mockResolvedValue(mockOsInfo), - getHardware: jest.fn().mockResolvedValue(mockHardwareInfo), + + (global as any).isMac = false; + (global as any).PLATFORM = "win32"; + + const mock = { cpu: { arch: 'arc' }, ram: { available: 4000, total: 8000 }, gpus: [{name: 'NVIDIA GeForce GTX 1080', total_vram: 8192}] } + + const mockHardwareExtension = { + getHardware: jest.fn().mockResolvedValue(mock), } - extensionManager.get = jest.fn().mockReturnValue(mockMonitoringExtension) + extensionManager.get = jest.fn().mockReturnValue(mockHardwareExtension) const result = await appService.systemInformation() - expect(mockMonitoringExtension.getGpuSetting).toHaveBeenCalled() - expect(mockMonitoringExtension.getOsInfo).toHaveBeenCalled() - expect(mockMonitoringExtension.getHardware).toHaveBeenCalled() + expect(mockHardwareExtension.getHardware).toHaveBeenCalled() + expect(result).toEqual({ - gpuSetting: mockGpuSetting, + gpuSetting: {gpus: mock.gpus, vulkan: false}, osInfo: { - ...mockOsInfo, - arch: mockHardwareInfo.cpu.arch, - freeMem: mockHardwareInfo.ram.available, - totalMem: mockHardwareInfo.ram.total, + platform: 'win32', + arch: mock.cpu.arch, + freeMem: mock.ram.available, + totalMem: mock.ram.total, }, }) }) -test('should log a warning when monitoring extension is not found', async () => { +test('should log a warning when hardware extension is not found', async () => { const consoleWarnMock = jest .spyOn(console, 'warn') .mockImplementation(() => {}) @@ -40,7 +37,7 @@ test('should log a warning when monitoring extension is not found', async () => await appService.systemInformation() expect(consoleWarnMock).toHaveBeenCalledWith( - 'System monitoring extension not found' + 'Hardware extension not found' ) consoleWarnMock.mockRestore() }) diff --git a/web/services/appService.ts b/web/services/appService.ts index 60f6e7ac35..92bb50b0de 100644 --- a/web/services/appService.ts +++ b/web/services/appService.ts @@ -5,7 +5,6 @@ import { SystemInformation, GpuSetting, GpuSettingInfo, - EngineManagementExtension, } from '@janhq/core' import { getDefaultStore } from 'jotai' @@ -27,20 +26,11 @@ export const appService = { ExtensionTypeEnum.Hardware ) - const engineExtension = extensionManager?.get( - ExtensionTypeEnum.Engine - ) - if (!hardwareExtension) { console.warn('Hardware extension not found') return undefined } - if (!engineExtension) { - console.warn('Engine extension not found') - return undefined - } - const hardwareInfo = await hardwareExtension?.getHardware() const gpuSettingInfo: GpuSetting | undefined = {