diff --git a/core/src/types/api/index.ts b/core/src/types/api/index.ts index e1d1b28da9..bca11c0a89 100644 --- a/core/src/types/api/index.ts +++ b/core/src/types/api/index.ts @@ -55,6 +55,7 @@ export enum AppEvent { onSelectedText = 'onSelectedText', onDeepLink = 'onDeepLink', + onMainViewStateChange = 'onMainViewStateChange', } export enum DownloadRoute { diff --git a/electron/managers/window.ts b/electron/managers/window.ts index 3d5107b280..c9c43ea775 100644 --- a/electron/managers/window.ts +++ b/electron/managers/window.ts @@ -166,6 +166,15 @@ class WindowManager { }, 500) } + /** + * Send main view state to the main app. + */ + sendMainViewState(route: string) { + if (this.mainWindow && !this.mainWindow.isDestroyed()) { + this.mainWindow.webContents.send(AppEvent.onMainViewStateChange, route) + } + } + cleanUp(): void { if (!this.mainWindow?.isDestroyed()) { this.mainWindow?.close() diff --git a/electron/utils/menu.ts b/electron/utils/menu.ts index 3f838e5caa..553412fafa 100644 --- a/electron/utils/menu.ts +++ b/electron/utils/menu.ts @@ -3,6 +3,7 @@ import { app, Menu, shell, dialog } from 'electron' import { autoUpdater } from 'electron-updater' import { log } from '@janhq/core/node' const isMac = process.platform === 'darwin' +import { windowManager } from '../managers/window' const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [ { @@ -43,6 +44,14 @@ const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [ { role: 'hide' }, { role: 'hideOthers' }, { role: 'unhide' }, + { + label: `Settings`, + accelerator: 'CmdOrCtrl+,', + click: () => { + windowManager.showMainWindow() + windowManager.sendMainViewState('Settings') + }, + }, { type: 'separator' }, { role: 'quit' }, ], diff --git a/web/containers/Layout/index.tsx b/web/containers/Layout/index.tsx index 3b3f57a21b..8a3f417f44 100644 --- a/web/containers/Layout/index.tsx +++ b/web/containers/Layout/index.tsx @@ -46,6 +46,16 @@ const BaseLayout = () => { } }, [setMainViewState]) + useEffect(() => { + window.electronAPI?.onMainViewStateChange( + (_event: string, route: string) => { + if (route === 'Settings') { + setMainViewState(MainViewState.Settings) + } + } + ) + }, [setMainViewState]) + return (