diff --git a/packages/desktop/lib/electron/menus/edit.menu.ts b/packages/desktop/lib/electron/menus/edit.menu.ts index 735a2e3b3d..d91e001b3f 100644 --- a/packages/desktop/lib/electron/menus/edit.menu.ts +++ b/packages/desktop/lib/electron/menus/edit.menu.ts @@ -1,4 +1,4 @@ -import { MENU_STATE } from './menu-state.constant' +import { menuState } from './menu' interface MenuItem extends Electron.MenuItemConstructorOptions { selector: string @@ -8,20 +8,22 @@ const menuItem = ( role: NonNullable, accelerator: Electron.MenuItemConstructorOptions['accelerator'] ): MenuItem => ({ - label: MENU_STATE.strings[role], + label: menuState.strings[role], accelerator, selector: `${role}:`, }) -export const editMenu: Electron.MenuItemConstructorOptions = { - label: MENU_STATE.strings.edit, - submenu: [ - menuItem('undo', 'CmdOrCtrl+Z'), - menuItem('redo', 'Shift+CmdOrCtrl+Z'), - { type: 'separator' }, - menuItem('cut', 'CmdOrCtrl+X'), - menuItem('copy', 'CmdOrCtrl+C'), - menuItem('paste', 'CmdOrCtrl+V'), - menuItem('selectAll', 'CmdOrCtrl+A'), - ], +export function buildEditMenu(): Electron.MenuItemConstructorOptions { + return { + label: menuState.strings.edit, + submenu: [ + menuItem('undo', 'CmdOrCtrl+Z'), + menuItem('redo', 'Shift+CmdOrCtrl+Z'), + { type: 'separator' }, + menuItem('cut', 'CmdOrCtrl+X'), + menuItem('copy', 'CmdOrCtrl+C'), + menuItem('paste', 'CmdOrCtrl+V'), + menuItem('selectAll', 'CmdOrCtrl+A'), + ], + } } diff --git a/packages/desktop/lib/electron/menus/help.menu.ts b/packages/desktop/lib/electron/menus/help.menu.ts index 3925825532..8d5aedf1e8 100644 --- a/packages/desktop/lib/electron/menus/help.menu.ts +++ b/packages/desktop/lib/electron/menus/help.menu.ts @@ -1,4 +1,4 @@ -import { MENU_STATE } from './menu-state.constant' +import { menuState } from './menu' import { shell } from 'electron' import { DISCORD_URL, DOCUMENTATION_URL, ISSUE_REPORT_URL } from '@contexts/settings/constants' @@ -6,16 +6,18 @@ const menuItem = ( action: 'faq' | 'documentation' | 'discord' | 'reportAnIssue', url: string ): Electron.MenuItemConstructorOptions => ({ - label: MENU_STATE.strings[action], + label: menuState.strings[action], click: () => void shell.openExternal(url), }) -export const helpMenu: Electron.MenuItemConstructorOptions = { - label: MENU_STATE.strings.help, - submenu: [ - // menuItem('faq', FAQ_URL), - menuItem('documentation', DOCUMENTATION_URL), - menuItem('discord', DISCORD_URL), - menuItem('reportAnIssue', ISSUE_REPORT_URL), - ], +export function buildHelpMenu(): Electron.MenuItemConstructorOptions { + return { + label: menuState.strings.help, + submenu: [ + // menuItem('faq', FAQ_URL), + menuItem('documentation', DOCUMENTATION_URL), + menuItem('discord', DISCORD_URL), + menuItem('reportAnIssue', ISSUE_REPORT_URL), + ], + } } diff --git a/packages/desktop/lib/electron/menus/menu-state.constant.ts b/packages/desktop/lib/electron/menus/menu-state.constant.ts index 832f1fce1c..44b719670f 100644 --- a/packages/desktop/lib/electron/menus/menu-state.constant.ts +++ b/packages/desktop/lib/electron/menus/menu-state.constant.ts @@ -1,33 +1,36 @@ +import $ from '../../../../shared/src/locales/en.json' + export const MENU_STATE = { enabled: true, strings: { - about: 'About Bloom', - checkForUpdates: 'Check for Updates', - importThirdPartyProfiles: 'Import Third-Party Profiles', - settings: 'Settings', - security: 'Security', - advanced: 'Advanced', - errorLog: 'Error Log', - diagnostics: 'Diagnostics', - logout: 'Log Out', - hide: 'Hide', - hideOthers: 'Hide Others', - showAll: 'Show All', - quit: 'Quit', - edit: 'Edit', - undo: 'Undo', - redo: 'Redo', - cut: 'Cut', - copy: 'Copy', - paste: 'Paste', - selectAll: 'Select All', - wallet: 'Wallet', - addAccount: 'Add Account', - help: 'Help', - faq: 'FAQ', - documentation: 'Documentation', - discord: 'Discord', - reportAnIssue: 'Report an Issue', - version: 'Version {version}', + about: $.views.settings.about.title, + addAccount: $.actions.addAccount, + advanced: $.views.settings.advanced.title, + checkForUpdates: $.actions.checkForUpdates, + copy: $.actions.copy, + cut: $.actions.cut, + developerTools: $.general.developerTools, + diagnostics: $.views.settings.diagnostics.title, + discord: $.views.settings.discord.title, + documentation: $.views.settings.documentation.title, + edit: $.actions.edit, + errorLog: $.views.settings.errorLog.title, + faq: $.views.settings.faq.title, + help: $.general.help, + hide: $.actions.hide, + hideOthers: $.actions.hideOthers, + importThirdPartyProfiles: $.actions.importThirdPartyProfiles, + logout: $.views.dashboard.profileMenu.logout, + paste: $.actions.paste, + quit: $.actions.quit, + redo: $.actions.redo, + reportAnIssue: $.actions.reportAnIssue, + security: $.views.settings.security.title, + selectAll: $.actions.selectAll, + settings: $.views.settings.settings, + showAll: $.actions.showAll, + undo: $.actions.undo, + version: $.general.versionFull, + wallet: $.general.wallet, }, } diff --git a/packages/desktop/lib/electron/menus/menu.ts b/packages/desktop/lib/electron/menus/menu.ts index 44f2b3edc3..d964d044ce 100644 --- a/packages/desktop/lib/electron/menus/menu.ts +++ b/packages/desktop/lib/electron/menus/menu.ts @@ -2,9 +2,9 @@ import { app, ipcMain, Menu } from 'electron' import features from '@features/features' import { getOrInitWindow } from '../processes/main.process' import { MENU_STATE } from './menu-state.constant' -import { editMenu } from './edit.menu' -import { helpMenu } from './help.menu' -import { walletMenu } from './wallet.menu' +import { buildEditMenu } from './edit.menu' +import { buildHelpMenu } from './help.menu' +import { buildWalletMenu } from './wallet.menu' import { AboutWindow } from '../windows/about.window' interface MenuState { @@ -15,7 +15,7 @@ interface MenuState { loggedIn?: boolean } -let state: MenuState = MENU_STATE +export let menuState: MenuState = MENU_STATE function createMenu(): Electron.Menu { const template = buildTemplate() @@ -44,14 +44,14 @@ export function initMenu(): void { app.once('ready', () => { ipcMain.handle('menu-update', (e, args) => { - state = { ...state, ...args } + menuState = { ...menuState, ...args } mainMenu = createMenu() }) ipcMain.handle('menu-popup', () => { mainMenu.popup({ window: getOrInitWindow('main') }) }) - ipcMain.handle('menu-data', () => state) + ipcMain.handle('menu-data', () => menuState) handleWindowControls() mainMenu = createMenu() }) @@ -79,12 +79,12 @@ function buildTemplate(): Electron.MenuItemConstructorOptions[] { let firstMenuSubmenu: Electron.MenuItemConstructorOptions[] = getFirstSubmenuItems() if (!app.isPackaged || features?.electron?.developerTools?.enabled) { - firstMenuSubmenu = [...firstMenuSubmenu, roleMenuItem('Developer Tools', 'toggleDevTools')] + firstMenuSubmenu = [...firstMenuSubmenu, roleMenuItem(menuState.strings.developerTools, 'toggleDevTools')] } firstMenuSubmenu = [ ...firstMenuSubmenu, - commandMenuItem(state.strings.errorLog, 'menu-error-log'), + commandMenuItem(menuState.strings.errorLog, 'menu-error-log'), { type: 'separator' }, ] @@ -95,7 +95,7 @@ function buildTemplate(): Electron.MenuItemConstructorOptions[] { firstMenuSubmenu = [ ...firstMenuSubmenu, { - label: state.strings.quit, + label: menuState.strings.quit, accelerator: process.platform === 'win32' ? 'Alt+F4' : 'CmdOrCtrl+Q', click: function (): void { app.quit() @@ -108,14 +108,14 @@ function buildTemplate(): Electron.MenuItemConstructorOptions[] { submenu: firstMenuSubmenu, } - const template: Electron.MenuItemConstructorOptions[] = [firstMenu, editMenu] + const template: Electron.MenuItemConstructorOptions[] = [firstMenu, buildEditMenu()] // TODO: this doesn't work because the state is not updated when the user logs in - if (state.loggedIn) { - template.push(walletMenu) + if (menuState.loggedIn) { + template.push(buildWalletMenu()) } - template.push(helpMenu) + template.push(buildHelpMenu()) return template } @@ -123,33 +123,33 @@ function buildTemplate(): Electron.MenuItemConstructorOptions[] { function getFirstSubmenuItems(): Electron.MenuItemConstructorOptions[] { let menuItems: Electron.MenuItemConstructorOptions[] = [ { - label: `${state.strings.about} ${app.name}`, + label: `${menuState.strings.about} ${app.name}`, click: AboutWindow.open, - enabled: state.enabled, + enabled: menuState.enabled, }, commandMenuItem( - `${state.strings.checkForUpdates}...`, + `${menuState.strings.checkForUpdates}...`, 'menu-check-for-update', - app.isPackaged && state.enabled + app.isPackaged && menuState.enabled ), ] if (features?.electron?.importFromThirdParty?.enabled) { - menuItems.push(commandMenuItem(state.strings.importThirdPartyProfiles, 'import-third-party-profile')) + menuItems.push(commandMenuItem(menuState.strings.importThirdPartyProfiles, 'import-third-party-profile')) } menuItems = [ ...menuItems, { type: 'separator' }, - commandMenuItem(state.strings.settings, 'menu-navigate-settings'), + commandMenuItem(menuState.strings.settings, 'menu-navigate-settings'), { type: 'separator' }, - commandMenuItem(state.strings.diagnostics, 'menu-diagnostics'), + commandMenuItem(menuState.strings.diagnostics, 'menu-diagnostics'), ] return menuItems } function getDarwinSubmenuItems(): Electron.MenuItemConstructorOptions[] { return [ - roleMenuItem(`${state.strings.hide} ${app.name}`, 'hide'), - roleMenuItem(state.strings.hideOthers, 'hideOthers'), - roleMenuItem(state.strings.showAll, 'unhide'), + roleMenuItem(`${menuState.strings.hide} ${app.name}`, 'hide'), + roleMenuItem(menuState.strings.hideOthers, 'hideOthers'), + roleMenuItem(menuState.strings.showAll, 'unhide'), ] } diff --git a/packages/desktop/lib/electron/menus/wallet.menu.ts b/packages/desktop/lib/electron/menus/wallet.menu.ts index 1f70c36753..8f9929ed11 100644 --- a/packages/desktop/lib/electron/menus/wallet.menu.ts +++ b/packages/desktop/lib/electron/menus/wallet.menu.ts @@ -1,14 +1,16 @@ import { getOrInitWindow } from '../processes/main.process' -import { MENU_STATE } from './menu-state.constant' +import { menuState } from './menu' -export const walletMenu: Electron.MenuItemConstructorOptions = { - label: MENU_STATE.strings.wallet, - submenu: [ - { type: 'separator' }, - { - label: MENU_STATE.strings.logout, - click: (): void => getOrInitWindow('main').webContents.send('menu-logout'), - enabled: MENU_STATE.enabled, - }, - ], +export function buildWalletMenu(): Electron.MenuItemConstructorOptions { + return { + label: menuState.strings.wallet, + submenu: [ + { type: 'separator' }, + { + label: menuState.strings.logout, + click: (): void => getOrInitWindow('main').webContents.send('menu-logout'), + enabled: menuState.enabled, + }, + ], + } } diff --git a/packages/desktop/lib/helpers.ts b/packages/desktop/lib/helpers.ts index c5dcf6e312..975f778d0f 100644 --- a/packages/desktop/lib/helpers.ts +++ b/packages/desktop/lib/helpers.ts @@ -17,33 +17,34 @@ import { appVersionDetails } from '@core/app/stores' */ export const getLocalisedMenuItems = (): unknown => ({ about: localize('views.settings.about.title'), - checkForUpdates: localize('actions.checkForUpdates'), - importThirdPartyProfiles: localize('actions.importThirdPartyProfiles'), - settings: localize('views.settings.settings'), - security: localize('views.settings.security.title'), + addAccount: localize('actions.addAccount'), advanced: localize('views.settings.advanced.title'), - errorLog: localize('views.settings.errorLog.title'), + checkForUpdates: localize('actions.checkForUpdates'), + copy: localize('actions.copy'), + cut: localize('actions.cut'), + developerTools: localize('general.developerTools'), diagnostics: localize('views.settings.diagnostics.title'), - logout: localize('views.dashboard.profileMenu.logout'), + discord: localize('views.settings.discord.title'), + documentation: localize('views.settings.documentation.title'), + edit: localize('actions.edit'), + errorLog: localize('views.settings.errorLog.title'), + faq: localize('views.settings.faq.title'), + help: localize('general.help'), hide: localize('actions.hide'), hideOthers: localize('actions.hideOthers'), - showAll: localize('actions.showAll'), + importThirdPartyProfiles: localize('actions.importThirdPartyProfiles'), + logout: localize('views.dashboard.profileMenu.logout'), + paste: localize('actions.paste'), quit: localize('actions.quit'), - edit: localize('actions.edit'), - undo: localize('actions.undo'), redo: localize('actions.redo'), - cut: localize('actions.cut'), - copy: localize('actions.copy'), - paste: localize('actions.paste'), - selectAll: localize('actions.selectAll'), - wallet: localize('general.wallet'), - addAccount: localize('actions.addAccount'), - help: localize('general.help'), - faq: localize('views.settings.faq.title'), - documentation: localize('views.settings.documentation.title'), - discord: localize('views.settings.discord.title'), reportAnIssue: localize('actions.reportAnIssue'), + security: localize('views.settings.security.title'), + selectAll: localize('actions.selectAll'), + settings: localize('views.settings.settings'), + showAll: localize('actions.showAll'), + undo: localize('actions.undo'), version: localize('general.versionFull'), + wallet: localize('general.wallet'), }) export function registerMenuButtons(): void {