feat: add setting options to dropdown menu (#3554)

* feat: add setting options to dropdown menu

* chore: update comment
This commit is contained in:
Faisal Amir 2024-09-05 09:49:47 +07:00 committed by GitHub
parent 28c6ba10f1
commit e9b657ae4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 0 deletions

View File

@ -55,6 +55,7 @@ export enum AppEvent {
onSelectedText = 'onSelectedText',
onDeepLink = 'onDeepLink',
onMainViewStateChange = 'onMainViewStateChange',
}
export enum DownloadRoute {

View File

@ -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()

View File

@ -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' },
],

View File

@ -46,6 +46,16 @@ const BaseLayout = () => {
}
}, [setMainViewState])
useEffect(() => {
window.electronAPI?.onMainViewStateChange(
(_event: string, route: string) => {
if (route === 'Settings') {
setMainViewState(MainViewState.Settings)
}
}
)
}, [setMainViewState])
return (
<div
className={twMerge(