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

View File

@ -34,6 +34,8 @@ 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) {
@ -52,7 +54,7 @@ const createMainWindow = () => {
} }
log.initialize() log.initialize()
log.info('Log from the main process') log.info('Starting jan from main thread..')
// replace all console.log to log // replace all console.log to log
Object.assign(console, log.functions) Object.assign(console, log.functions)
@ -63,7 +65,7 @@ const host = '127.0.0.1'
app app
.whenReady() .whenReady()
.then(setupCore) .then(() => setupCore(dependencies['cortexso'] ?? 'Not found'))
.then(() => { .then(() => {
if (!gotTheLock) { if (!gotTheLock) {
app.quit() app.quit()
@ -92,7 +94,7 @@ app
const janDataFolder = appConfiguration.dataFolderPath const janDataFolder = appConfiguration.dataFolderPath
start('jan', host, cortexJsPort, cortexCppPort, janDataFolder) start('jan', host, cortexJsPort, cortexCppPort, janDataFolder)
}) })
.then(createUserSpace) .then(createUserSpace)
.then(migrate) .then(migrate)
.then(setupMenu) .then(setupMenu)
@ -128,7 +130,6 @@ app.once('window-all-closed', async () => {
cleanUpAndQuit() cleanUpAndQuit()
}) })
async function stopApiServer() { async function stopApiServer() {
// this function is not meant to be success. It will throw an error. // this function is not meant to be success. It will throw an error.
try { try {

View File

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

View File

@ -12,7 +12,7 @@ const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [
click: () => click: () =>
dialog.showMessageBox({ dialog.showMessageBox({
title: `Jan`, 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) => { .catch((error) => {
console.error('Error checking for updates:' + JSON.stringify(error)) console.error(
'Error checking for updates:' + JSON.stringify(error)
)
}), }),
}, },
{ type: 'separator' }, { type: 'separator' },

View File

@ -1,16 +1,16 @@
import { app } from 'electron' import { app } from 'electron'
import Store from 'electron-store' import Store from 'electron-store'
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 () => { export const setupCore = async (cortexsoVersion: string) => {
// 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,
} }
} }