fix: broken jan build - add log trace (jan.log) (#3336)

This commit is contained in:
Louis 2024-08-10 15:33:11 +07:00 committed by GitHub
parent 6e4b6b09ae
commit 77422c3a7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 13 deletions

View File

@ -18,7 +18,7 @@ import { handleAppIPCs } from './handlers/native'
* Utils * Utils
**/ **/
import { setupMenu } from './utils/menu' import { setupMenu } from './utils/menu'
import { createUserSpace, getAppConfigurations } from './utils/path' import { createUserSpace, getJanDataFolderPath } from './utils/path'
import { migrate } from './utils/migration' import { migrate } from './utils/migration'
import { cleanUpAndQuit } from './utils/clean' import { cleanUpAndQuit } from './utils/clean'
import { setupCore } from './utils/setup' import { setupCore } from './utils/setup'
@ -34,8 +34,6 @@ const mainPath = join(rendererPath, 'index.html')
const mainUrl = 'http://localhost:3000' const mainUrl = 'http://localhost:3000'
import { dependencies } from './package.json'
const gotTheLock = app.requestSingleInstanceLock() const gotTheLock = app.requestSingleInstanceLock()
if (process.defaultApp) { if (process.defaultApp) {
@ -65,7 +63,11 @@ const host = '127.0.0.1'
app app
.whenReady() .whenReady()
.then(() => setupCore(dependencies['cortexso'] ?? 'Not found')) .then(() => {
const dataFolderPath = join(getJanDataFolderPath(), 'jan.log')
log.transports.file.resolvePathFn = () => dataFolderPath
})
.then(() => setupCore())
.then(() => { .then(() => {
if (!gotTheLock) { if (!gotTheLock) {
app.quit() app.quit()
@ -87,13 +89,11 @@ app
) )
} }
}) })
.then(() => killProcessesOnPort(cortexCppPort)) .then(() => killProcessesOnPort(cortexCppPort))
.then(() => killProcessesOnPort(cortexJsPort)) .then(() => killProcessesOnPort(cortexJsPort))
.then(() => { .then(() => {
const appConfiguration = getAppConfigurations() start('jan', host, cortexJsPort, cortexCppPort, getJanDataFolderPath())
const janDataFolder = appConfiguration.dataFolderPath
start('jan', host, cortexJsPort, cortexCppPort, janDataFolder)
}) })
.then(createUserSpace) .then(createUserSpace)
.then(migrate) .then(migrate)

View File

@ -35,7 +35,8 @@
"docs", "docs",
"scripts", "scripts",
"icons", "icons",
"themes" "themes",
"package.json"
], ],
"publish": [ "publish": [
{ {

View File

@ -1,16 +1,26 @@
import { app } from 'electron' import { app } from 'electron'
import Store from 'electron-store' 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_WIDTH = 1000
const DEFAULT_HEIGHT = 800 const DEFAULT_HEIGHT = 800
const storage = new Store() 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 // Setup core api for main process
global.core = { global.core = {
// Define appPath function for app to retrieve app path globally // Define appPath function for app to retrieve app path globally
appPath: () => app.getPath('userData'), appPath: () => app.getPath('userData'),
cortexVersion: () => cortexsoVersion, cortexVersion: () => cortexVersion,
} }
} }

View File

@ -1,7 +1,6 @@
import { useCallback } from 'react' import { useCallback } from 'react'
import { Assistant } from '@janhq/core' import { Assistant } from '@janhq/core'
import log from 'electron-log/renderer'
import { useSetAtom } from 'jotai' import { useSetAtom } from 'jotai'
@ -49,7 +48,6 @@ const useThreads = () => {
assistant.instructions = instructions assistant.instructions = instructions
} }
const thread = await createThread(assistant) const thread = await createThread(assistant)
log.info('Create new thread result', thread)
setThreads((threads) => [thread, ...threads]) setThreads((threads) => [thread, ...threads])
setActiveThread(thread.id) setActiveThread(thread.id)
return thread return thread