chore: add cortex version (#3318)

This commit is contained in:
NamH 2024-08-09 14:25:15 +07:00 committed by GitHub
parent 3de4eab2a0
commit 60587649c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 44 additions and 16 deletions

View File

@ -9,13 +9,19 @@ import {
} from '@janhq/core/node'
import { menu } from '../utils/menu'
import { join } from 'path'
import { getAppConfigurations, getJanDataFolderPath, legacyDataPath, updateAppConfiguration } from './../utils/path'
import {
getAppConfigurations,
getJanDataFolderPath,
legacyDataPath,
updateAppConfiguration,
} from './../utils/path'
import {
readdirSync,
writeFileSync,
readFileSync,
existsSync,
mkdirSync,
lstatSync,
} from 'fs'
import { dump, load } from 'js-yaml'
const isMac = process.platform === 'darwin'
@ -224,7 +230,6 @@ export function handleAppIPCs() {
})
ipcMain.handle(NativeRoute.syncModelFileToCortex, async (_event) => {
// Read models from legacy data folder
const janModelFolderPath = join(legacyDataPath(), 'models')
const allModelFolders = readdirSync(janModelFolderPath)
@ -242,9 +247,20 @@ export function handleAppIPCs() {
for (const modelName of allModelFolders) {
const modelFolderPath = join(janModelFolderPath, modelName)
// check if exist and is a directory
if (!existsSync(modelFolderPath)) {
console.debug(`Model folder ${modelFolderPath} does not exist`)
continue
}
// check if it is a directory
if (!lstatSync(modelFolderPath).isDirectory()) {
console.debug(`${modelFolderPath} is not a directory`)
continue
}
try {
const filesInModelFolder = readdirSync(modelFolderPath)
const destinationPath = join(destinationFolderPath, modelName)
const modelJsonFullPath = join(
@ -252,6 +268,10 @@ export function handleAppIPCs() {
modelName,
'model.json'
)
if (!existsSync(modelJsonFullPath)) {
console.error(`Model json file not found in ${modelName}`)
continue
}
const model = JSON.parse(readFileSync(modelJsonFullPath, 'utf-8'))
const fileNames: string[] = model.sources.map((x: any) => x.filename)
@ -438,13 +458,17 @@ export function handleAppIPCs() {
// Migrate models
const janModelsPath = join(path, 'models')
if (existsSync(janModelsPath)) {
const modelYamls = readdirSync(janModelsPath).filter((x) =>
x.endsWith('.yaml') || x.endsWith('.yml')
const modelYamls = readdirSync(janModelsPath).filter(
(x) => x.endsWith('.yaml') || x.endsWith('.yml')
)
for(const yaml of modelYamls) {
for (const yaml of modelYamls) {
const modelPath = join(janModelsPath, yaml)
const model = load(readFileSync(modelPath, 'utf-8')) as any
if('files' in model && Array.isArray(model.files) && model.files.length > 0) {
if (
'files' in model &&
Array.isArray(model.files) &&
model.files.length > 0
) {
model.files[0] = model.files[0].replace(currentJanDataFolder, path)
}
writeFileSync(modelPath, dump(model))

View File

@ -34,6 +34,8 @@ const mainPath = join(rendererPath, 'index.html')
const mainUrl = 'http://localhost:3000'
import { dependencies } from './package.json'
const gotTheLock = app.requestSingleInstanceLock()
if (process.defaultApp) {
@ -52,7 +54,7 @@ const createMainWindow = () => {
}
log.initialize()
log.info('Log from the main process')
log.info('Starting jan from main thread..')
// replace all console.log to log
Object.assign(console, log.functions)
@ -63,7 +65,7 @@ const host = '127.0.0.1'
app
.whenReady()
.then(setupCore)
.then(() => setupCore(dependencies['cortexso'] ?? 'Not found'))
.then(() => {
if (!gotTheLock) {
app.quit()
@ -90,9 +92,9 @@ app
.then(() => {
const appConfiguration = getAppConfigurations()
const janDataFolder = appConfiguration.dataFolderPath
start('jan', host, cortexJsPort, cortexCppPort, janDataFolder)
})
})
.then(createUserSpace)
.then(migrate)
.then(setupMenu)
@ -128,7 +130,6 @@ app.once('window-all-closed', async () => {
cleanUpAndQuit()
})
async function stopApiServer() {
// this function is not meant to be success. It will throw an error.
try {

View File

@ -1,5 +1,6 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"target": "es5",
"module": "commonjs",
"noImplicitAny": true,

View File

@ -12,7 +12,7 @@ const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [
click: () =>
dialog.showMessageBox({
title: `Jan`,
message: `Jan Version v${app.getVersion()}\n\nCopyright © 2024 Jan`,
message: `Jan Version v${app.getVersion()}\nCortex Version ${global.core.cortexVersion()}\n\nCopyright © 2024 Jan`,
}),
},
{
@ -33,7 +33,9 @@ const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [
}
})
.catch((error) => {
console.error('Error checking for updates:' + JSON.stringify(error))
console.error(
'Error checking for updates:' + JSON.stringify(error)
)
}),
},
{ type: 'separator' },

View File

@ -1,16 +1,16 @@
import { app } from 'electron'
import Store from 'electron-store'
const DEFAULT_WIDTH = 1000
const DEFAULT_HEIGHT = 800
const storage = new Store()
export const setupCore = async () => {
export const setupCore = async (cortexsoVersion: string) => {
// Setup core api for main process
global.core = {
// Define appPath function for app to retrieve app path globally
appPath: () => app.getPath('userData'),
cortexVersion: () => cortexsoVersion,
}
}