fix: 4094 - gpu mode toggle on by default but not affect for the first time launch

This commit is contained in:
Louis 2024-11-26 19:50:23 +07:00
parent 79287d5748
commit d55b1dd2f8
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
2 changed files with 14 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import {
ModelEvent, ModelEvent,
SystemInformation, SystemInformation,
dirName, dirName,
AppConfigurationEventName,
} from '@janhq/core' } from '@janhq/core'
import PQueue from 'p-queue' import PQueue from 'p-queue'
import ky from 'ky' import ky from 'ky'
@ -70,7 +71,7 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
super.onLoad() super.onLoad()
this.queue.add(() => this.clean()) this.queue.add(() => this.clean())
// Run the process watchdog // Run the process watchdog
const systemInfo = await systemInformation() const systemInfo = await systemInformation()
this.queue.add(() => executeOnMain(NODE, 'run', systemInfo)) this.queue.add(() => executeOnMain(NODE, 'run', systemInfo))
@ -81,6 +82,15 @@ export default class JanInferenceCortexExtension extends LocalOAIEngine {
window.addEventListener('beforeunload', () => { window.addEventListener('beforeunload', () => {
this.clean() this.clean()
}) })
const currentMode = systemInfo.gpuSetting?.run_mode
events.on(AppConfigurationEventName.OnConfigurationUpdate, async () => {
const systemInfo = await systemInformation()
// Update run mode on settings update
if (systemInfo.gpuSetting?.run_mode !== currentMode)
this.setDefaultEngine(systemInfo)
})
} }
async onUnload() { async onUnload() {

View File

@ -1,7 +1,9 @@
import { import {
AppConfigurationEventName,
GpuSetting, GpuSetting,
MonitoringExtension, MonitoringExtension,
OperatingSystemInfo, OperatingSystemInfo,
events,
executeOnMain, executeOnMain,
} from '@janhq/core' } from '@janhq/core'
@ -37,6 +39,7 @@ export default class JanMonitoringExtension extends MonitoringExtension {
// Attempt to fetch nvidia info // Attempt to fetch nvidia info
await executeOnMain(NODE, 'updateNvidiaInfo') await executeOnMain(NODE, 'updateNvidiaInfo')
events.emit(AppConfigurationEventName.OnConfigurationUpdate, {})
} }
onSettingUpdate<T>(key: string, value: T): void { onSettingUpdate<T>(key: string, value: T): void {