diff --git a/.github/workflows/jan-electron-linter-and-test.yml b/.github/workflows/jan-electron-linter-and-test.yml index f2ab23ee2..5ae64c4eb 100644 --- a/.github/workflows/jan-electron-linter-and-test.yml +++ b/.github/workflows/jan-electron-linter-and-test.yml @@ -200,6 +200,9 @@ jobs: # run: | # make update-playwright-config REPORT_PORTAL_URL=${{ secrets.REPORT_PORTAL_URL }} REPORT_PORTAL_API_KEY=${{ secrets.REPORT_PORTAL_API_KEY }} REPORT_PORTAL_PROJECT_NAME=${{ secrets.REPORT_PORTAL_PROJECT_NAME }} REPORT_PORTAL_LAUNCH_NAME="Jan App Windows" REPORT_PORTAL_DESCRIPTION="${{env.REPORT_PORTAL_DESCRIPTION}}" + - name: Setup node-gyp - distutils + run: pip3 install --upgrade setuptools + - name: Linter and test shell: powershell run: | diff --git a/electron/cortex-runner.ts b/electron/cortex-runner.ts deleted file mode 100644 index b370a8035..000000000 --- a/electron/cortex-runner.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { app } from 'electron' -import { join as joinPath } from 'path' - -import { platform } from 'os' - -const getPlatform = (): string => { - switch (platform()) { - case 'darwin': - case 'sunos': - return 'mac' - case 'win32': - return 'win' - default: - return 'linux' - } -} - -const resourceFolderName = getPlatform() === 'mac' ? 'Resources' : 'resources' - -const execPath = app.isPackaged - ? joinPath(app.getAppPath(), '..', '..', resourceFolderName, 'bin') - : joinPath(__dirname, '..', 'resources', getPlatform()) - -const cortexName = 'cortex' -const cortexBinaryName = - getPlatform() === 'win' ? `${cortexName}.exe` : cortexName - -export const cortexPath = `${joinPath(execPath, cortexBinaryName)}` diff --git a/electron/main.ts b/electron/main.ts index 6ff9cf0d9..ef916bb7f 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -1,8 +1,7 @@ import { app, BrowserWindow } from 'electron' import { join, resolve } from 'path' -import { exec, execSync, ChildProcess } from 'child_process' -import { cortexPath } from './cortex-runner' +import { execSync } from 'child_process' /** * Managers @@ -27,6 +26,8 @@ import { setupReactDevTool } from './utils/dev' import log from 'electron-log' +import { start } from 'cortexso' + const preloadPath = join(__dirname, 'preload.js') const rendererPath = join(__dirname, '..', 'renderer') const mainPath = join(rendererPath, 'index.html') @@ -56,8 +57,6 @@ log.info('Log from the main process') // replace all console.log to log Object.assign(console, log.functions) -let cortexService: ChildProcess | undefined = undefined - const cortexJsPort = 1338 const cortexCppPort = 3940 const host = '127.0.0.1' @@ -91,35 +90,9 @@ app .then(() => { const appConfiguration = getAppConfigurations() const janDataFolder = appConfiguration.data_folder - - const cortexParams: Record = { - '-n': 'jan', - '-a': host, - '-p': cortexJsPort.toString(), - '-ep': cortexCppPort.toString(), - '--dataFolder': janDataFolder, - } - - // add cortex parameters to the command - const command = Object.entries(cortexParams).reduce( - (acc, [key, value]) => `${acc} ${key} ${value}`, - `${cortexPath}` - ) - - log.info('Starting cortex with command:', command) - // init cortex - cortexService = exec(`${command}`, (error, stdout, stderr) => { - if (error) { - log.error(`error: ${error.message}`) - return - } - if (stderr) { - log.error(`stderr: ${stderr}`) - return - } - log.info(`stdout: ${stdout}`) - }) - }) + + start('jan', host, cortexJsPort, cortexCppPort, janDataFolder) +}) .then(createUserSpace) .then(migrate) .then(setupMenu) @@ -152,23 +125,9 @@ app.once('quit', async () => { app.once('window-all-closed', async () => { await stopApiServer() - await stopCortexService() cleanUpAndQuit() }) -async function stopCortexService() { - try { - const pid = cortexService?.pid - if (!pid) { - console.log('No cortex service to stop.') - return - } - process.kill(pid) - console.log(`Service with PID ${pid} has been terminated.`) - } catch (error) { - console.error('Error killing service:', error) - } -} async function stopApiServer() { // this function is not meant to be success. It will throw an error. diff --git a/electron/package.json b/electron/package.json index 62a15fd94..78b084247 100644 --- a/electron/package.json +++ b/electron/package.json @@ -88,10 +88,10 @@ "lint": "eslint . --ext \".js,.jsx,.ts,.tsx\"", "test:e2e": "playwright test --workers=1", "copy:assets": "rimraf --glob \"./pre-install/*.tgz\" && cpx \"../pre-install/*.tgz\" \"./pre-install\"", - "dev": "yarn copy:assets && yarn downloadcortex && tsc -p . && electron .", + "dev": "yarn copy:assets && tsc -p . && electron .", "compile": "tsc -p .", "start": "electron .", - "build:test": "yarn copy:assets && yarn downloadcortex && run-script-os", + "build:test": "yarn copy:assets && run-script-os", "build:test:darwin": "tsc -p . && electron-builder -p never -m --dir", "build:test:win32": "tsc -p . && electron-builder -p never -w --dir", "build:test:linux": "tsc -p . && electron-builder -p never -l --dir", @@ -99,7 +99,7 @@ "downloadcortex:linux": "CORTEX_VERSION=$(cat ./resources/version.txt) && echo https://github.com/janhq/cortex/releases/download/v${CORTEX_VERSION}/cortex-${CORTEX_VERSION}-amd64-linux.tar.gz && download https://github.com/janhq/cortex/releases/download/v${CORTEX_VERSION}/cortex-${CORTEX_VERSION}-amd64-linux.tar.gz -e -o ./resources/linux && rm -rf ./resources/linux/cortex-${CORTEX_VERSION}-amd64-linux.tar.gz && chmod +x ./resources/linux/cortex", "downloadcortex:darwin": "CORTEX_VERSION=$(cat ./resources/version.txt) && ARCH=$(node -e \"console.log(process.arch === 'arm64' ? 'arm64' : 'amd64')\") && echo https://github.com/janhq/cortex/releases/download/v${CORTEX_VERSION}/cortex-${CORTEX_VERSION}-${ARCH}-mac.tar.gz && download https://github.com/janhq/cortex/releases/download/v${CORTEX_VERSION}/cortex-${CORTEX_VERSION}-${ARCH}-mac.tar.gz -e -o ./resources/mac/ && rm -rf ./resources/mac/cortex-${CORTEX_VERSION}-${ARCH}-mac.tar.gz && chmod +x ./resources/mac/cortex", "downloadcortex:win32": "download.bat", - "build": "yarn copy:assets && yarn downloadcortex && run-script-os", + "build": "yarn copy:assets && run-script-os", "build:darwin": "tsc -p . && electron-builder -p never -m", "build:win32": "tsc -p . && electron-builder -p never -w", "build:linux": "tsc -p . && electron-builder -p never -l deb -l AppImage", @@ -121,7 +121,8 @@ "pacote": "^17.0.4", "request": "^2.88.2", "request-progress": "^3.0.0", - "@kirillvakalov/nut-tree__nut-js": "4.2.1-2" + "@kirillvakalov/nut-tree__nut-js": "4.2.1-2", + "cortexso": "v0.5.0-40" }, "devDependencies": { "@types/js-yaml": "4.0.9",