* feat: better hardware setting * chore: update layout * feat: better hardware setting * chore: fix title section * chore: added hardware engine management * chore: integrate gpus and enable set gpu activate * chore: update calculate ram and vram * chore: update calulate vram and ram used * fix: set active gpus * chore: fix progress bar spacing * chore: always update cache vram gpu * chore: update cpu usage percentage * chore: fix type usage cpu * chore: update ram cpus usage getsystemmonitor from new api harware engine management system * test: update test case data using hardware management extension * chore: resolve conflict lock json * chore: cleanup app services * chore: update type OperationSystemInfo * chore: update app service * chore: show list gpus on system monitor * chore: remove monitoring extension * chore: update test case app service * chore: remove unused hooks useGpusSetting * chore: remove monitor from shource index * chore: fix test core * chore: update gpu and cpu info on engine management ext * chore: fix app service test * chore: update test appService include cpu info * chore: filter gpus show or hide on system monitor based activated gpu * chore: remove unused run_mode * chore: remove tensort * chore: update check gpu run_mode * chore: handle undefined gpus * chore: cleanup PR * chore: cleanup process node error * chore: fix type
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { useCallback, useEffect, useState } from 'react'
|
|
|
|
import { fs, GpuSettingInfo, joinPath } from '@janhq/core'
|
|
|
|
export type AppSettings = {
|
|
vulkan: boolean
|
|
gpus: GpuSettingInfo[]
|
|
}
|
|
|
|
export const useSettings = () => {
|
|
const [settings, setSettings] = useState<AppSettings>()
|
|
|
|
useEffect(() => {
|
|
readSettings().then((settings) => setSettings(settings as AppSettings))
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [])
|
|
|
|
const readSettings = useCallback(async () => {
|
|
if (!window?.core?.api) {
|
|
return
|
|
}
|
|
const settingsFile = await joinPath(['file://settings', 'settings.json'])
|
|
if (await fs.existsSync(settingsFile)) {
|
|
const settings = await fs.readFileSync(settingsFile, 'utf-8')
|
|
return typeof settings === 'object' ? settings : JSON.parse(settings)
|
|
}
|
|
return {}
|
|
}, [])
|
|
|
|
const saveSettings = async ({ vulkan }: { vulkan?: boolean | undefined }) => {
|
|
const settingsFile = await joinPath(['file://settings', 'settings.json'])
|
|
const settings = await readSettings()
|
|
if (vulkan != null) {
|
|
settings.vulkan = vulkan
|
|
// GPU enabled, set run_mode to 'gpu'
|
|
if (settings.vulkan === true) {
|
|
settings?.gpus?.some((gpu: { activated: boolean }) =>
|
|
gpu.activated === true ? 'gpu' : 'cpu'
|
|
)
|
|
}
|
|
}
|
|
await fs.writeFileSync(settingsFile, JSON.stringify(settings))
|
|
}
|
|
|
|
return {
|
|
readSettings,
|
|
saveSettings,
|
|
settings,
|
|
}
|
|
}
|