diff --git a/electron/main.ts b/electron/main.ts index 7687ee3b5..2a94269a0 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -18,7 +18,7 @@ import { handleAppIPCs } from './handlers/native' * Utils **/ import { setupMenu } from './utils/menu' -import { createUserSpace, getAppConfigurations } from './utils/path' +import { createUserSpace, getJanDataFolderPath } from './utils/path' import { migrate } from './utils/migration' import { cleanUpAndQuit } from './utils/clean' import { setupCore } from './utils/setup' @@ -34,8 +34,6 @@ const mainPath = join(rendererPath, 'index.html') const mainUrl = 'http://localhost:3000' -import { dependencies } from './package.json' - const gotTheLock = app.requestSingleInstanceLock() if (process.defaultApp) { @@ -65,7 +63,11 @@ const host = '127.0.0.1' app .whenReady() - .then(() => setupCore(dependencies['cortexso'] ?? 'Not found')) + .then(() => { + const dataFolderPath = join(getJanDataFolderPath(), 'jan.log') + log.transports.file.resolvePathFn = () => dataFolderPath + }) + .then(() => setupCore()) .then(() => { if (!gotTheLock) { app.quit() @@ -87,13 +89,11 @@ app ) } }) + .then(() => killProcessesOnPort(cortexCppPort)) .then(() => killProcessesOnPort(cortexJsPort)) .then(() => { - const appConfiguration = getAppConfigurations() - const janDataFolder = appConfiguration.dataFolderPath - - start('jan', host, cortexJsPort, cortexCppPort, janDataFolder) + start('jan', host, cortexJsPort, cortexCppPort, getJanDataFolderPath()) }) .then(createUserSpace) .then(migrate) diff --git a/electron/package.json b/electron/package.json index 78b084247..c003b1406 100644 --- a/electron/package.json +++ b/electron/package.json @@ -35,7 +35,8 @@ "docs", "scripts", "icons", - "themes" + "themes", + "package.json" ], "publish": [ { diff --git a/electron/utils/setup.ts b/electron/utils/setup.ts index 5efc198bf..a6297fd24 100644 --- a/electron/utils/setup.ts +++ b/electron/utils/setup.ts @@ -1,16 +1,26 @@ import { app } from 'electron' import Store from 'electron-store' +import { existsSync, readFileSync } from 'original-fs' +import { appResourcePath } from './path' +import { join } from 'path' const DEFAULT_WIDTH = 1000 const DEFAULT_HEIGHT = 800 const storage = new Store() -export const setupCore = async (cortexsoVersion: string) => { +export const setupCore = async () => { + let cortexVersion = 'N/A' + // Read package.json + const pkgPath = join(await appResourcePath(), 'package.json') + if(existsSync(pkgPath)) { + const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) + cortexVersion = pkg.dependencies['cortexso'] + } // Setup core api for main process global.core = { // Define appPath function for app to retrieve app path globally appPath: () => app.getPath('userData'), - cortexVersion: () => cortexsoVersion, + cortexVersion: () => cortexVersion, } } diff --git a/web/hooks/useThreads.ts b/web/hooks/useThreads.ts index 828bf82c5..54128d9dd 100644 --- a/web/hooks/useThreads.ts +++ b/web/hooks/useThreads.ts @@ -1,7 +1,6 @@ import { useCallback } from 'react' import { Assistant } from '@janhq/core' -import log from 'electron-log/renderer' import { useSetAtom } from 'jotai' @@ -49,7 +48,6 @@ const useThreads = () => { assistant.instructions = instructions } const thread = await createThread(assistant) - log.info('Create new thread result', thread) setThreads((threads) => [thread, ...threads]) setActiveThread(thread.id) return thread