diff --git a/electron/handlers/fs.ts b/electron/handlers/fs.ts index fdfaba6063..a7b4b3d9a5 100644 --- a/electron/handlers/fs.ts +++ b/electron/handlers/fs.ts @@ -2,7 +2,7 @@ import { ipcMain } from 'electron' import { FileSystemRoute } from '@janhq/core' import { userSpacePath } from '../utils/path' -import { join } from 'path' +import { join, sep } from 'path' /** * Handles file system operations. */ @@ -13,12 +13,19 @@ export function handleFsIPCs() { return import(moduleName).then((mdl) => mdl[route]( ...args.map((arg) => - typeof arg === 'string' && arg.includes('file:/') - ? join(userSpacePath, arg.replace('file:/', '')) + typeof arg === 'string' && + (arg.includes(`file:/`) || arg.includes(`file:\\`)) + ? join( + userSpacePath, + arg.replace(`file://`, '') + .replace(`file:/`, '') + .replace(`file:\\\\`, '') + .replace(`file:\\`, '') + ) : arg ) ) ) }) }) -} +} \ No newline at end of file diff --git a/extensions/inference-nitro-extension/src/index.ts b/extensions/inference-nitro-extension/src/index.ts index 595866b35b..4503946471 100644 --- a/extensions/inference-nitro-extension/src/index.ts +++ b/extensions/inference-nitro-extension/src/index.ts @@ -87,8 +87,8 @@ export default class JanInferenceNitroExtension implements InferenceExtension { // Attempt to fetch nvidia info await executeOnMain(MODULE, "updateNvidiaInfo", {}); - const gpuDriverConf = await fs.readFile( - join(__dirname, "bin", "nvidia.json") + const gpuDriverConf = await fs.readFileSync( + join(JanInferenceNitroExtension._settingsDir, "settings.json") ); if (gpuDriverConf.notify && gpuDriverConf.run_mode === "cpu") { // Driver is fully installed, but not in use diff --git a/extensions/inference-nitro-extension/src/module.ts b/extensions/inference-nitro-extension/src/module.ts index acd51fc74b..963962fa9d 100644 --- a/extensions/inference-nitro-extension/src/module.ts +++ b/extensions/inference-nitro-extension/src/module.ts @@ -18,10 +18,26 @@ const NITRO_HTTP_KILL_URL = `${NITRO_HTTP_SERVER_URL}/processmanager/destroy`; const SUPPORTED_MODEL_FORMAT = ".gguf"; const NVIDIA_INFO_FILE = path.join( require("os").homedir(), + "jan", "settings", "settings.json" ); +const DEFALT_SETTINGS = { + "notify": false, + "run_mode": "cpu", + "nvidia_driver": { + "exist": false, + "version": "" + }, + "cuda": { + "exist": false, + "version": "" + }, + "gpus": [], + "gpu_highest_vram": "" +} + // The subprocess instance for Nitro let subprocess = undefined; let currentModelFile: string = undefined; @@ -43,7 +59,13 @@ async function updateNvidiaDriverInfo(): Promise { exec( "nvidia-smi --query-gpu=driver_version --format=csv,noheader", (error, stdout) => { - let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); + let data; + try { + data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); + } catch (error) { + data = DEFALT_SETTINGS; + } + // let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); if (!error) { const firstLine = stdout.split("\n")[0].trim(); @@ -86,7 +108,14 @@ function updateCudaExistence() { (file) => existsSync(file) || checkFileExistenceInPaths(file, paths) ); - let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); + let data; + try { + data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); + } catch (error) { + data = DEFALT_SETTINGS; + } + + // let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); data["cuda"].exist = cudaExists; writeFileSync(NVIDIA_INFO_FILE, JSON.stringify(data, null, 2)); } @@ -95,7 +124,13 @@ async function updateGpuInfo(): Promise { exec( "nvidia-smi --query-gpu=index,memory.total --format=csv,noheader,nounits", (error, stdout) => { - let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); + let data; + try { + data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); + } catch (error) { + data = DEFALT_SETTINGS; + } + // let data = JSON.parse(readFileSync(NVIDIA_INFO_FILE, "utf8")); if (!error) { // Get GPU info and gpu has higher memory first