From 013c0ce36e15a6cebd288190cc82687da09ebc0a Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 16 Jan 2024 11:42:55 +0700 Subject: [PATCH] fix: update server settings ref --- electron/handlers/app.ts | 51 +++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/electron/handlers/app.ts b/electron/handlers/app.ts index 2a84b0de9..ae4e31b73 100644 --- a/electron/handlers/app.ts +++ b/electron/handlers/app.ts @@ -4,7 +4,14 @@ import { WindowManager } from './../managers/window' import { getResourcePath, userSpacePath } from './../utils/path' import { AppRoute } from '@janhq/core' import { ModuleManager, init, log } from '@janhq/core/node' -import { startServer, stopServer } from '@janhq/server' +import { + startServer, + stopServer, + isCorsEnabled, + isVerboseEnabled, + getHost, + getPort, +} from '@janhq/server' export function handleAppIPCs() { /** @@ -51,19 +58,45 @@ export function handleAppIPCs() { /** * Start Jan API Server. */ - ipcMain.handle(AppRoute.startServer, async (_event) => - startServer( - app.isPackaged - ? join(getResourcePath(), 'docs', 'openapi', 'jan.yaml') - : undefined, - app.isPackaged ? join(getResourcePath(), 'docs', 'openapi') : undefined - ) + ipcMain.handle( + AppRoute.startServer, + async (_event, host, port, isCorsEnabled, isVerbose) => + startServer( + host, + port, + isCorsEnabled, + isVerbose, + app.isPackaged + ? join(getResourcePath(), 'docs', 'openapi', 'jan.yaml') + : undefined, + app.isPackaged ? join(getResourcePath(), 'docs', 'openapi') : undefined + ) ) /** * Stop Jan API Server. */ - ipcMain.handle(AppRoute.stopServer, async (_event) => stopServer()) + ipcMain.handle(AppRoute.stopServer, stopServer) + + /** + * Check if CORS is enabled. + */ + ipcMain.handle(AppRoute.isCorsEnabled, isCorsEnabled) + + /** + * Check if verbose logging is enabled. + */ + ipcMain.handle(AppRoute.isVerboseEnabled, isVerboseEnabled) + + /** + * Get the host setting. + */ + ipcMain.handle(AppRoute.getHost, getHost) + + /** + * Get the port setting. + */ + ipcMain.handle(AppRoute.getPort, getPort) /** * Relaunches the app in production - reload window in development.