Skip to content

Commit

Permalink
feat: add setting options to dropdown menu (janhq#3554)
Browse files Browse the repository at this point in the history
* feat: add setting options to dropdown menu

* chore: update comment
  • Loading branch information
urmauur authored Sep 5, 2024
1 parent 28c6ba1 commit e9b657a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/types/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export enum AppEvent {
onSelectedText = 'onSelectedText',

onDeepLink = 'onDeepLink',
onMainViewStateChange = 'onMainViewStateChange',
}

export enum DownloadRoute {
Expand Down
9 changes: 9 additions & 0 deletions electron/managers/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions electron/utils/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)[] = [
{
Expand Down Expand Up @@ -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' },
],
Expand Down
10 changes: 10 additions & 0 deletions web/containers/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e9b657a

Please sign in to comment.