* feat: desktop revamp * feat: refactor system monitor * fix linter CI * remove unused import component * added responsive and resizeable component * responsive and resizeable local server page * finalize responsive and resizeable component * fix scroll custom ui * remove react scroll to bottom from modal troubleshoot * fix modal troubleshoot ui * fix setting gpu list * text area custom scroll bar * fix padding message input * cleanup classname * update inference engine model dropdown * update loader style * update quick ask ui * prepare theme provider * update dark theme * remove update hotkey list model and navigation * fix: cleanup hardcode classname * fix: update feedback * Set native theme electron * update destop ui revamp from feedback * update button icon component insider icon chat input message * update model dropdown ui * update tranaparent baclground * update logo model provider * fix: set background material acrylic support to blur background windows * fix: update tranparent left and right panel * fix: linter CI * update app using frameless window * styling custom style minimize, maximize and close app * temporary hidden maximize window * fix: responsive left and right panel * fix: enable click outside when leftpanel responsive * fix: remove unused import * update transparent variable css windows * fix: ui import model * feat: Support Theme system (#2946) * feat: update support theme system * update select component * feat: add theme folder in root project * fix: padding left and right center panel * fix: update padding left and right * chore: migrate themes * fix: rmdirsync error * chore: update gitignore * fix: cp recursive * fix: files electron package json * fix: migration * fix: update fgit ignore --------- Co-authored-by: Louis <louis@jan.ai> * fix: update feedback missing state when refrash app * fix: error test CI * chore: refactor useLoadThemes * chore: cleanup unused vars * fix: revert back menubar windows * fix minor ui * fix: minor ui --------- Co-authored-by: Louis <louis@jan.ai>
207 lines
5.7 KiB
TypeScript
207 lines
5.7 KiB
TypeScript
import { app, ipcMain, dialog, shell, nativeTheme, screen } from 'electron'
|
|
import { join } from 'path'
|
|
import { windowManager } from '../managers/window'
|
|
import {
|
|
ModuleManager,
|
|
getJanDataFolderPath,
|
|
getJanExtensionsPath,
|
|
init,
|
|
AppEvent,
|
|
NativeRoute,
|
|
SelectFileProp,
|
|
} from '@janhq/core/node'
|
|
import { SelectFileOption } from '@janhq/core'
|
|
import { menu } from '../utils/menu'
|
|
|
|
const isMac = process.platform === 'darwin'
|
|
|
|
export function handleAppIPCs() {
|
|
/**
|
|
* 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(NativeRoute.openAppDirectory, async (_event) => {
|
|
shell.openPath(getJanDataFolderPath())
|
|
})
|
|
|
|
/**
|
|
* Handles the "setNativeThemeLight" IPC message by setting the native theme source to "light".
|
|
* This will change the appearance of the app to the light theme.
|
|
*/
|
|
ipcMain.handle(NativeRoute.setNativeThemeLight, () => {
|
|
nativeTheme.themeSource = 'light'
|
|
})
|
|
|
|
ipcMain.handle(NativeRoute.setCloseApp, () => {
|
|
windowManager.mainWindow?.close()
|
|
})
|
|
|
|
ipcMain.handle(NativeRoute.setMinimizeApp, () => {
|
|
windowManager.mainWindow?.minimize()
|
|
})
|
|
|
|
ipcMain.handle(NativeRoute.setMaximizeApp, async () => {
|
|
if (windowManager.mainWindow?.isMaximized()) {
|
|
// const bounds = await getBounds()
|
|
// windowManager.mainWindow?.setSize(bounds.width, bounds.height)
|
|
// windowManager.mainWindow?.setPosition(Number(bounds.x), Number(bounds.y))
|
|
windowManager.mainWindow.restore()
|
|
} else {
|
|
windowManager.mainWindow?.maximize()
|
|
}
|
|
})
|
|
|
|
/**
|
|
* Handles the "setNativeThemeDark" IPC message by setting the native theme source to "dark".
|
|
* This will change the appearance of the app to the dark theme.
|
|
*/
|
|
ipcMain.handle(NativeRoute.setNativeThemeDark, () => {
|
|
nativeTheme.themeSource = 'dark'
|
|
})
|
|
|
|
/**
|
|
* Opens a URL in the user's default browser.
|
|
* @param _event - The IPC event object.
|
|
* @param url - The URL to open.
|
|
*/
|
|
ipcMain.handle(NativeRoute.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(NativeRoute.openFileExplore, async (_event, url) => {
|
|
shell.openPath(url)
|
|
})
|
|
|
|
/**
|
|
* Relaunches the app in production - reload window in development.
|
|
* @param _event - The IPC event object.
|
|
* @param url - The URL to reload.
|
|
*/
|
|
ipcMain.handle(NativeRoute.relaunch, async (_event) => {
|
|
ModuleManager.instance.clearImportedModules()
|
|
|
|
if (app.isPackaged) {
|
|
app.relaunch()
|
|
app.exit()
|
|
} else {
|
|
for (const modulePath in ModuleManager.instance.requiredModules) {
|
|
delete require.cache[
|
|
require.resolve(join(getJanExtensionsPath(), modulePath))
|
|
]
|
|
}
|
|
init({
|
|
// Function to check from the main process that user wants to install a extension
|
|
confirmInstall: async (_extensions: string[]) => {
|
|
return true
|
|
},
|
|
// Path to install extension to
|
|
extensionsPath: getJanExtensionsPath(),
|
|
})
|
|
windowManager.mainWindow?.reload()
|
|
}
|
|
})
|
|
|
|
ipcMain.handle(NativeRoute.selectDirectory, async () => {
|
|
const mainWindow = windowManager.mainWindow
|
|
if (!mainWindow) {
|
|
console.error('No main window found')
|
|
return
|
|
}
|
|
const { canceled, filePaths } = await dialog.showOpenDialog(mainWindow, {
|
|
title: 'Select a folder',
|
|
buttonLabel: 'Select Folder',
|
|
properties: ['openDirectory', 'createDirectory'],
|
|
})
|
|
if (canceled) {
|
|
return
|
|
} else {
|
|
return filePaths[0]
|
|
}
|
|
})
|
|
|
|
ipcMain.handle(
|
|
NativeRoute.selectFiles,
|
|
async (_event, option?: SelectFileOption) => {
|
|
const mainWindow = windowManager.mainWindow
|
|
if (!mainWindow) {
|
|
console.error('No main window found')
|
|
return
|
|
}
|
|
|
|
const title = option?.title ?? 'Select files'
|
|
const buttonLabel = option?.buttonLabel ?? 'Select'
|
|
const props: SelectFileProp[] = ['openFile']
|
|
|
|
if (option?.allowMultiple) {
|
|
props.push('multiSelections')
|
|
}
|
|
|
|
if (option?.selectDirectory) {
|
|
props.push('openDirectory')
|
|
}
|
|
console.debug(`Select files with props: ${props}`)
|
|
const { canceled, filePaths } = await dialog.showOpenDialog(mainWindow, {
|
|
title,
|
|
buttonLabel,
|
|
properties: props,
|
|
filters: option?.filters,
|
|
})
|
|
|
|
if (canceled) return
|
|
|
|
return filePaths
|
|
}
|
|
)
|
|
|
|
ipcMain.handle(
|
|
NativeRoute.hideQuickAskWindow,
|
|
async (): Promise<void> => windowManager.hideQuickAskWindow()
|
|
)
|
|
|
|
ipcMain.handle(
|
|
NativeRoute.sendQuickAskInput,
|
|
async (_event, input: string): Promise<void> => {
|
|
windowManager.mainWindow?.webContents.send(
|
|
AppEvent.onUserSubmitQuickAsk,
|
|
input
|
|
)
|
|
}
|
|
)
|
|
|
|
ipcMain.handle(NativeRoute.showOpenMenu, function (e, args) {
|
|
if (!isMac && windowManager.mainWindow) {
|
|
menu.popup({
|
|
window: windowManager.mainWindow,
|
|
x: args.x,
|
|
y: args.y,
|
|
})
|
|
}
|
|
})
|
|
|
|
ipcMain.handle(
|
|
NativeRoute.hideMainWindow,
|
|
async (): Promise<void> => windowManager.hideMainWindow()
|
|
)
|
|
|
|
ipcMain.handle(
|
|
NativeRoute.showMainWindow,
|
|
async (): Promise<void> => windowManager.showMainWindow()
|
|
)
|
|
|
|
ipcMain.handle(
|
|
NativeRoute.quickAskSizeUpdated,
|
|
async (_event, heightOffset: number): Promise<void> =>
|
|
windowManager.expandQuickAskWindow(heightOffset)
|
|
)
|
|
|
|
ipcMain.handle(NativeRoute.ackDeepLink, async (_event): Promise<void> => {
|
|
windowManager.ackDeepLink()
|
|
})
|
|
}
|