fix: disable gpu drop down box if there's no GPU ready (#2046)

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
This commit is contained in:
NamH 2024-02-16 10:46:42 +07:00 committed by GitHub
parent fb13d57890
commit b7e94aac02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View File

@ -434,20 +434,20 @@ export default class JanModelExtension extends ModelExtension {
handleDesktopEvents() {
if (window && window.electronAPI) {
window.electronAPI.onFileDownloadUpdate(
async (_event: string, state: any | undefined) => {
async (_event: string, state: DownloadState | undefined) => {
if (!state) return
state.downloadState = 'update'
state.downloadState = 'downloading'
events.emit(DownloadEvent.onFileDownloadUpdate, state)
}
)
window.electronAPI.onFileDownloadError(
async (_event: string, state: any) => {
async (_event: string, state: DownloadState) => {
state.downloadState = 'error'
events.emit(DownloadEvent.onFileDownloadError, state)
}
)
window.electronAPI.onFileDownloadSuccess(
async (_event: string, state: any) => {
async (_event: string, state: DownloadState) => {
state.downloadState = 'end'
events.emit(DownloadEvent.onFileDownloadSuccess, state)
}

View File

@ -85,14 +85,14 @@ const Advanced = () => {
useEffect(() => {
const setUseGpuIfPossible = async () => {
const settings = await readSettings()
setGpuEnabled(settings.run_mode === 'gpu')
setGpuEnabled(settings.run_mode === 'gpu' && gpuList.length > 0)
setGpusInUse(settings.gpus_in_use || [])
if (settings.gpus) {
setGpuList(settings.gpus)
}
}
setUseGpuIfPossible()
}, [readSettings])
}, [readSettings, gpuList])
const clearLogs = async () => {
if (await fs.existsSync(`file://logs`)) {
@ -254,7 +254,10 @@ const Advanced = () => {
</div>
<div className="mt-2 w-full rounded-lg bg-secondary p-4">
<label className="mb-1 inline-block font-medium">Choose GPU</label>
<Select disabled={!gpuEnabled} value={selectedGpu.join()}>
<Select
disabled={gpuList.length === 0 || !gpuEnabled}
value={selectedGpu.join()}
>
<SelectTrigger className="w-[340px] bg-white">
<SelectValue placeholder={gpuSelectionPlaceHolder}>
<span className="line-clamp-1 w-full pr-8">