* chore: expose fs apis * chore: correct electron import path * update download api Signed-off-by: James <james@jan.ai> * update chat_completion Signed-off-by: James <james@jan.ai> * fix electron import Signed-off-by: James <james@jan.ai> * feat: adding API support at 1337 (#991) Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> * feat: Add /chat/completion api and handler * chore: add todo for modelList * chore: read engine.json for openai chat_completion (#1030) Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> * refactor: move routes to shared node module * refactor: exported modules from core with types (#1172) * refactor: exported modules from core with types * fix: fix file reading args * refactor: fileManager handles * fix: app issues with server refactoring * refactor: shared server module (#1210) * chore: resolve main * chore: update makefile --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> Co-authored-by: NamH <NamNh0122@gmail.com> Co-authored-by: hiro <vuonghoainam.work@gmail.com>
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
import { app, ipcMain, shell, nativeTheme } from 'electron'
|
|
import { join } from 'path'
|
|
import { WindowManager } from './../managers/window'
|
|
import { userSpacePath } from './../utils/path'
|
|
import { AppRoute } from '@janhq/core'
|
|
import { getResourcePath } from './../utils/path'
|
|
import {
|
|
ExtensionManager,
|
|
ModuleManager,
|
|
} from '@janhq/core/node'
|
|
|
|
export function handleAppIPCs() {
|
|
/**
|
|
* Returns the version of the app.
|
|
* @param _event - The IPC event object.
|
|
* @returns The version of the app.
|
|
*/
|
|
ipcMain.handle(AppRoute.appVersion, async (_event) => {
|
|
return app.getVersion()
|
|
})
|
|
|
|
/**
|
|
* Handles the "openAppDirectory" IPC message by opening the app's user data directory.
|
|
* The `shell.openPath` method is used to open the directory in the user's default file explorer.
|
|
* @param _event - The IPC event object.
|
|
*/
|
|
ipcMain.handle(AppRoute.openAppDirectory, async (_event) => {
|
|
shell.openPath(userSpacePath)
|
|
})
|
|
|
|
/**
|
|
* Opens a URL in the user's default browser.
|
|
* @param _event - The IPC event object.
|
|
* @param url - The URL to open.
|
|
*/
|
|
ipcMain.handle(AppRoute.openExternalUrl, async (_event, url) => {
|
|
shell.openExternal(url)
|
|
})
|
|
|
|
/**
|
|
* Opens a URL in the user's default browser.
|
|
* @param _event - The IPC event object.
|
|
* @param url - The URL to open.
|
|
*/
|
|
ipcMain.handle(AppRoute.openFileExplore, async (_event, url) => {
|
|
shell.openPath(url)
|
|
})
|
|
|
|
/**
|
|
* Joins multiple paths together, respect to the current OS.
|
|
*/
|
|
ipcMain.handle(AppRoute.joinPath, async (_event, paths: string[]) =>
|
|
join(...paths)
|
|
)
|
|
|
|
/**
|
|
* Relaunches the app in production - reload window in development.
|
|
* @param _event - The IPC event object.
|
|
* @param url - The URL to reload.
|
|
*/
|
|
ipcMain.handle(AppRoute.relaunch, async (_event, url) => {
|
|
ModuleManager.instance.clearImportedModules()
|
|
|
|
if (app.isPackaged) {
|
|
app.relaunch()
|
|
app.exit()
|
|
} else {
|
|
for (const modulePath in ModuleManager.instance.requiredModules) {
|
|
delete require.cache[
|
|
require.resolve(join(userSpacePath, 'extensions', modulePath))
|
|
]
|
|
}
|
|
ExtensionManager.instance.setupExtensions()
|
|
WindowManager.instance.currentWindow?.reload()
|
|
}
|
|
})
|
|
}
|