diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-11 12:00:07 +0200 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-04-11 12:00:07 +0200 |
commit | e43d6bd80b3d76aae627fa8174eea98c14016549 (patch) | |
tree | de1d0a3ba10100ce68d0cb1ed618095e362fe573 /src/lib/Menu.js | |
parent | implements basic release announcement feature (diff) | |
parent | handle deleted services that are attached to workspaces (diff) | |
download | ferdium-app-e43d6bd80b3d76aae627fa8174eea98c14016549.tar.gz ferdium-app-e43d6bd80b3d76aae627fa8174eea98c14016549.tar.zst ferdium-app-e43d6bd80b3d76aae627fa8174eea98c14016549.zip |
merge-in workspace feature
Diffstat (limited to 'src/lib/Menu.js')
-rw-r--r-- | src/lib/Menu.js | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index 70f3b2877..46a347237 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js | |||
@@ -3,6 +3,9 @@ import { observable, autorun } from 'mobx'; | |||
3 | import { defineMessages } from 'react-intl'; | 3 | import { defineMessages } from 'react-intl'; |
4 | 4 | ||
5 | import { isMac, ctrlKey, cmdKey } from '../environment'; | 5 | import { isMac, ctrlKey, cmdKey } from '../environment'; |
6 | import { GA_CATEGORY_WORKSPACES, workspaceStore } from '../features/workspaces/index'; | ||
7 | import { workspaceActions } from '../features/workspaces/actions'; | ||
8 | import { gaEvent } from './analytics'; | ||
6 | 9 | ||
7 | const { app, Menu, dialog } = remote; | 10 | const { app, Menu, dialog } = remote; |
8 | 11 | ||
@@ -183,6 +186,18 @@ const menuItems = defineMessages({ | |||
183 | id: 'menu.services.addNewService', | 186 | id: 'menu.services.addNewService', |
184 | defaultMessage: '!!!Add New Service...', | 187 | defaultMessage: '!!!Add New Service...', |
185 | }, | 188 | }, |
189 | addNewWorkspace: { | ||
190 | id: 'menu.workspaces.addNewWorkspace', | ||
191 | defaultMessage: '!!!Add New Workspace...', | ||
192 | }, | ||
193 | openWorkspaceDrawer: { | ||
194 | id: 'menu.workspaces.openWorkspaceDrawer', | ||
195 | defaultMessage: '!!!Open workspace drawer', | ||
196 | }, | ||
197 | closeWorkspaceDrawer: { | ||
198 | id: 'menu.workspaces.closeWorkspaceDrawer', | ||
199 | defaultMessage: '!!!Close workspace drawer', | ||
200 | }, | ||
186 | activateNextService: { | 201 | activateNextService: { |
187 | id: 'menu.services.setNextServiceActive', | 202 | id: 'menu.services.setNextServiceActive', |
188 | defaultMessage: '!!!Activate next service...', | 203 | defaultMessage: '!!!Activate next service...', |
@@ -199,6 +214,14 @@ const menuItems = defineMessages({ | |||
199 | id: 'sidebar.unmuteApp', | 214 | id: 'sidebar.unmuteApp', |
200 | defaultMessage: '!!!Enable notifications & audio', | 215 | defaultMessage: '!!!Enable notifications & audio', |
201 | }, | 216 | }, |
217 | workspaces: { | ||
218 | id: 'menu.workspaces', | ||
219 | defaultMessage: '!!!Workspaces', | ||
220 | }, | ||
221 | defaultWorkspace: { | ||
222 | id: 'menu.workspaces.defaultWorkspace', | ||
223 | defaultMessage: '!!!Default', | ||
224 | }, | ||
202 | }); | 225 | }); |
203 | 226 | ||
204 | function getActiveWebview() { | 227 | function getActiveWebview() { |
@@ -302,6 +325,11 @@ const _templateFactory = intl => [ | |||
302 | submenu: [], | 325 | submenu: [], |
303 | }, | 326 | }, |
304 | { | 327 | { |
328 | label: intl.formatMessage(menuItems.workspaces), | ||
329 | submenu: [], | ||
330 | visible: workspaceStore.isFeatureEnabled, | ||
331 | }, | ||
332 | { | ||
305 | label: intl.formatMessage(menuItems.window), | 333 | label: intl.formatMessage(menuItems.window), |
306 | role: 'window', | 334 | role: 'window', |
307 | submenu: [ | 335 | submenu: [ |
@@ -679,7 +707,7 @@ export default class FranzMenu { | |||
679 | }, | 707 | }, |
680 | ); | 708 | ); |
681 | 709 | ||
682 | tpl[4].submenu.unshift(about, { | 710 | tpl[5].submenu.unshift(about, { |
683 | type: 'separator', | 711 | type: 'separator', |
684 | }); | 712 | }); |
685 | } else { | 713 | } else { |
@@ -714,6 +742,10 @@ export default class FranzMenu { | |||
714 | tpl[3].submenu = serviceTpl; | 742 | tpl[3].submenu = serviceTpl; |
715 | } | 743 | } |
716 | 744 | ||
745 | if (workspaceStore.isFeatureEnabled) { | ||
746 | tpl[4].submenu = this.workspacesMenu(); | ||
747 | } | ||
748 | |||
717 | this.currentTemplate = tpl; | 749 | this.currentTemplate = tpl; |
718 | const menu = Menu.buildFromTemplate(tpl); | 750 | const menu = Menu.buildFromTemplate(tpl); |
719 | Menu.setApplicationMenu(menu); | 751 | Menu.setApplicationMenu(menu); |
@@ -764,6 +796,66 @@ export default class FranzMenu { | |||
764 | return menu; | 796 | return menu; |
765 | } | 797 | } |
766 | 798 | ||
799 | workspacesMenu() { | ||
800 | const { workspaces, activeWorkspace, isWorkspaceDrawerOpen } = workspaceStore; | ||
801 | const { intl } = window.franz; | ||
802 | const menu = []; | ||
803 | |||
804 | // Add new workspace item: | ||
805 | menu.push({ | ||
806 | label: intl.formatMessage(menuItems.addNewWorkspace), | ||
807 | accelerator: `${cmdKey}+Shift+N`, | ||
808 | click: () => { | ||
809 | workspaceActions.openWorkspaceSettings(); | ||
810 | }, | ||
811 | enabled: this.stores.user.isLoggedIn, | ||
812 | }); | ||
813 | |||
814 | // Open workspace drawer: | ||
815 | const drawerLabel = ( | ||
816 | isWorkspaceDrawerOpen ? menuItems.closeWorkspaceDrawer : menuItems.openWorkspaceDrawer | ||
817 | ); | ||
818 | menu.push({ | ||
819 | label: intl.formatMessage(drawerLabel), | ||
820 | accelerator: `${cmdKey}+D`, | ||
821 | click: () => { | ||
822 | workspaceActions.toggleWorkspaceDrawer(); | ||
823 | gaEvent(GA_CATEGORY_WORKSPACES, 'toggleDrawer', 'menu'); | ||
824 | }, | ||
825 | enabled: this.stores.user.isLoggedIn, | ||
826 | }, { | ||
827 | type: 'separator', | ||
828 | }); | ||
829 | |||
830 | // Default workspace | ||
831 | menu.push({ | ||
832 | label: intl.formatMessage(menuItems.defaultWorkspace), | ||
833 | accelerator: `${cmdKey}+Alt+0`, | ||
834 | type: 'radio', | ||
835 | checked: !activeWorkspace, | ||
836 | click: () => { | ||
837 | workspaceActions.deactivate(); | ||
838 | gaEvent(GA_CATEGORY_WORKSPACES, 'switch', 'menu'); | ||
839 | }, | ||
840 | }); | ||
841 | |||
842 | // Workspace items | ||
843 | if (this.stores.user.isPremium) { | ||
844 | workspaces.forEach((workspace, i) => menu.push({ | ||
845 | label: workspace.name, | ||
846 | accelerator: i < 9 ? `${cmdKey}+Alt+${i + 1}` : null, | ||
847 | type: 'radio', | ||
848 | checked: activeWorkspace ? workspace.id === activeWorkspace.id : false, | ||
849 | click: () => { | ||
850 | workspaceActions.activate({ workspace }); | ||
851 | gaEvent(GA_CATEGORY_WORKSPACES, 'switch', 'menu'); | ||
852 | }, | ||
853 | })); | ||
854 | } | ||
855 | |||
856 | return menu; | ||
857 | } | ||
858 | |||
767 | _getServiceName(service) { | 859 | _getServiceName(service) { |
768 | if (service.name) { | 860 | if (service.name) { |
769 | return service.name; | 861 | return service.name; |