Skip to content

Commit

Permalink
fix: broken jan build - add log trace (jan.log) (#3336)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo authored Aug 10, 2024
1 parent 6e4b6b0 commit 77422c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
16 changes: 8 additions & 8 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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) {
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"docs",
"scripts",
"icons",
"themes"
"themes",
"package.json"
],
"publish": [
{
Expand Down
14 changes: 12 additions & 2 deletions electron/utils/setup.ts
Original file line number Diff line number Diff line change
@@ -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,
}
}

Expand Down
2 changes: 0 additions & 2 deletions web/hooks/useThreads.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback } from 'react'

import { Assistant } from '@janhq/core'
import log from 'electron-log/renderer'

import { useSetAtom } from 'jotai'

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 77422c3

Please sign in to comment.