Skip to content

Commit

Permalink
feat: Rearrange main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Jul 29, 2019
1 parent 881b845 commit 1b22932
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 34 deletions.
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ export default {
help: {
label: 'Help',
sourceCode: 'Source Code',
settings: 'Settings',
},
develop: {
develop: 'Develop',
'force-reload': 'Force Reload',
reload: 'Reload',
'toggle-dev-tools': 'Toggle DevTools',
'toggle-dev-tools': 'Toggle Developer Tools',
},
},
services: {
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
'application-menu': {
neuron: {
about: '关于{{app}}',
preferences: '设置...',
preferences: '偏好设置...',
quit: '退出{{app}}',
},
wallet: {
Expand Down Expand Up @@ -39,6 +39,7 @@ export default {
help: {
label: '帮助',
sourceCode: '源代码',
settings: '设置',
},
develop: {
develop: '开发',
Expand Down
86 changes: 54 additions & 32 deletions packages/neuron-wallet/src/utils/application-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import i18n from './i18n'
import AppController from '../controllers/app'
import WalletsService from '../services/wallets'

const isMac = process.platform === 'darwin'

const separator: MenuItemConstructorOptions = {
type: 'separator',
}
Expand Down Expand Up @@ -45,6 +47,7 @@ export const appMenuItem: MenuItemConstructorOptions = {
},
],
}

export const walletMenuItem: MenuItemConstructorOptions = {
id: 'wallet',
label: 'Wallet',
Expand Down Expand Up @@ -95,10 +98,6 @@ export const walletMenuItem: MenuItemConstructorOptions = {
walletsService.requestPassword(currentWallet.id, 'deleteWallet')
},
},
/**
* TODO: implement this menu item after alpha release
* { id: 'change-password', label: i18n.t('application-menu.wallet.change-password') },
*/
],
}

Expand All @@ -120,6 +119,7 @@ export const editMenuItem: MenuItemConstructorOptions = {
},
],
}

export const viewMenuItem: MenuItemConstructorOptions = {
id: 'view',
label: i18n.t('application-menu.view.label'),
Expand Down Expand Up @@ -154,28 +154,55 @@ export const windowMenuItem: MenuItemConstructorOptions = {
},
],
}

const helpSubmenu: MenuItemConstructorOptions[] = [
{
label: 'Nervos',
click: () => {
if (AppController) {
AppController.openWebsite()
}
},
},
{
label: i18n.t('application-menu.help.sourceCode'),
click: () => {
if (AppController) {
AppController.openRepository()
}
},
},
]
if (!isMac) {
helpSubmenu.push(separator)
helpSubmenu.push({
id: 'preference',
label: i18n.t('application-menu.help.settings'),
click: () => {
if (AppController) {
AppController.showPreference()
}
},
})
helpSubmenu.push({
id: 'about',
label: i18n.t('application-menu.neuron.about', {
app: app.getName(),
}),
role: 'about',
click: () => {
if (AppController) {
AppController.showAbout()
}
},
})
}

export const helpMenuItem: MenuItemConstructorOptions = {
id: 'help',
label: i18n.t('application-menu.help.label'),
role: 'help',
submenu: [
{
label: 'Nervos',
click: () => {
if (AppController) {
AppController.openWebsite()
}
},
},
{
label: i18n.t('application-menu.help.sourceCode'),
click: () => {
if (AppController) {
AppController.openRepository()
}
},
},
],
submenu: helpSubmenu,
}

export const developMenuItem: MenuItemConstructorOptions = {
Expand All @@ -197,17 +224,12 @@ export const developMenuItem: MenuItemConstructorOptions = {
],
}

export const applicationMenuTemplate = [
appMenuItem,
walletMenuItem,
editMenuItem,
viewMenuItem,
windowMenuItem,
helpMenuItem,
]
export const applicationMenuTemplate = env.isDevMode
? [walletMenuItem, editMenuItem, viewMenuItem, developMenuItem, windowMenuItem, helpMenuItem]
: [walletMenuItem, editMenuItem, viewMenuItem, windowMenuItem, helpMenuItem]

if (env.isDevMode) {
applicationMenuTemplate.push(developMenuItem)
if (isMac) {
applicationMenuTemplate.unshift(appMenuItem)
}

export const updateApplicationMenu = (wallets: Controller.Wallet[], id: string | null) => {
Expand Down

0 comments on commit 1b22932

Please sign in to comment.