aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/Menu.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2019-03-12 14:04:13 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2019-03-12 14:04:13 +0100
commit9af01849f895230ae60a635c9756a5e206aa0fa1 (patch)
treeb0b99f324c1a2e8c52e1fadf1152efac6d1028d2 /src/lib/Menu.js
parentBump version to 5.0.1-beta.1 (diff)
parentMerge branch 'sergiughf-hotfix/update-electron' into develop (diff)
downloadferdium-app-9af01849f895230ae60a635c9756a5e206aa0fa1.tar.gz
ferdium-app-9af01849f895230ae60a635c9756a5e206aa0fa1.tar.zst
ferdium-app-9af01849f895230ae60a635c9756a5e206aa0fa1.zip
Merge branch 'develop' into release/5.0.1-beta.1
Diffstat (limited to 'src/lib/Menu.js')
-rw-r--r--src/lib/Menu.js91
1 files changed, 62 insertions, 29 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js
index dce8ab969..7a60c448f 100644
--- a/src/lib/Menu.js
+++ b/src/lib/Menu.js
@@ -1,5 +1,5 @@
1import { remote, shell } from 'electron'; 1import { remote, shell } from 'electron';
2import { observable, autorun, computed } from 'mobx'; 2import { observable, autorun } from 'mobx';
3import { defineMessages } from 'react-intl'; 3import { defineMessages } from 'react-intl';
4 4
5import { isMac, ctrlKey, cmdKey } from '../environment'; 5import { isMac, ctrlKey, cmdKey } from '../environment';
@@ -179,6 +179,22 @@ const menuItems = defineMessages({
179 id: 'menu.services.addNewService', 179 id: 'menu.services.addNewService',
180 defaultMessage: '!!!Add New Service...', 180 defaultMessage: '!!!Add New Service...',
181 }, 181 },
182 activateNextService: {
183 id: 'menu.services.setNextServiceActive',
184 defaultMessage: '!!!Activate next service...',
185 },
186 activatePreviousService: {
187 id: 'menu.services.activatePreviousService',
188 defaultMessage: '!!!Activate previous service...',
189 },
190 muteApp: {
191 id: 'sidebar.muteApp',
192 defaultMessage: '!!!Disable notifications & audio',
193 },
194 unmuteApp: {
195 id: 'sidebar.unmuteApp',
196 defaultMessage: '!!!Enable notifications & audio',
197 },
182}); 198});
183 199
184function getActiveWebview() { 200function getActiveWebview() {
@@ -408,7 +424,7 @@ const _titleBarTemplateFactory = intl => [
408 }, 424 },
409 { 425 {
410 label: intl.formatMessage(menuItems.zoomIn), 426 label: intl.formatMessage(menuItems.zoomIn),
411 accelerator: `${ctrlKey}+Plus`, 427 accelerator: `${ctrlKey}+=`,
412 click() { 428 click() {
413 const activeService = getActiveWebview(); 429 const activeService = getActiveWebview();
414 activeService.getZoomLevel((level) => { 430 activeService.getZoomLevel((level) => {
@@ -519,13 +535,14 @@ export default class FranzMenu {
519 } 535 }
520 536
521 _build() { 537 _build() {
522 const serviceTpl = Object.assign([], this.serviceTpl); // need to clone object so we don't modify computed (cached) object 538 // need to clone object so we don't modify computed (cached) object
539 const serviceTpl = Object.assign([], this.serviceTpl());
523 540
524 if (window.franz === undefined) { 541 if (window.franz === undefined) {
525 return; 542 return;
526 } 543 }
527 544
528 const intl = window.franz.intl; 545 const { intl } = window.franz;
529 const tpl = isMac ? _templateFactory(intl) : _titleBarTemplateFactory(intl); 546 const tpl = isMac ? _templateFactory(intl) : _titleBarTemplateFactory(intl);
530 547
531 tpl[1].submenu.push({ 548 tpl[1].submenu.push({
@@ -683,17 +700,6 @@ export default class FranzMenu {
683 }, about); 700 }, about);
684 } 701 }
685 702
686 serviceTpl.unshift({
687 label: intl.formatMessage(menuItems.addNewService),
688 accelerator: `${cmdKey}+N`,
689 click: () => {
690 this.actions.ui.openSettings({ path: 'recipes' });
691 },
692 enabled: this.stores.user.isLoggedIn,
693 }, {
694 type: 'separator',
695 });
696
697 if (serviceTpl.length > 0) { 703 if (serviceTpl.length > 0) {
698 tpl[3].submenu = serviceTpl; 704 tpl[3].submenu = serviceTpl;
699 } 705 }
@@ -703,22 +709,49 @@ export default class FranzMenu {
703 Menu.setApplicationMenu(menu); 709 Menu.setApplicationMenu(menu);
704 } 710 }
705 711
706 @computed get serviceTpl() { 712 serviceTpl() {
707 const services = this.stores.services.allDisplayed; 713 const { intl } = window.franz;
714 const { user, services, settings } = this.stores;
715 if (!user.isLoggedIn) return [];
716 const menu = [];
708 717
709 if (this.stores.user.isLoggedIn) { 718 menu.push({
710 return services.map((service, i) => ({ 719 label: intl.formatMessage(menuItems.addNewService),
711 label: this._getServiceName(service), 720 accelerator: `${cmdKey}+N`,
712 accelerator: i < 9 ? `${cmdKey}+${i + 1}` : null, 721 click: () => {
713 type: 'radio', 722 this.actions.ui.openSettings({ path: 'recipes' });
714 checked: service.isActive, 723 },
715 click: () => { 724 }, {
716 this.actions.service.setActive({ serviceId: service.id }); 725 type: 'separator',
717 }, 726 }, {
718 })); 727 label: intl.formatMessage(menuItems.activateNextService),
719 } 728 accelerator: `${cmdKey}+alt+right`,
729 click: () => this.actions.service.setActiveNext(),
730 }, {
731 label: intl.formatMessage(menuItems.activatePreviousService),
732 accelerator: `${cmdKey}+alt+left`,
733 click: () => this.actions.service.setActivePrev(),
734 }, {
735 label: intl.formatMessage(
736 settings.all.app.isAppMuted ? menuItems.unmuteApp : menuItems.muteApp,
737 ).replace('&', '&&'),
738 accelerator: `${cmdKey}+shift+m`,
739 click: () => this.actions.app.toggleMuteApp(),
740 }, {
741 type: 'separator',
742 });
743
744 services.allDisplayed.forEach((service, i) => (menu.push({
745 label: this._getServiceName(service),
746 accelerator: i < 9 ? `${cmdKey}+${i + 1}` : null,
747 type: 'radio',
748 checked: service.isActive,
749 click: () => {
750 this.actions.service.setActive({ serviceId: service.id });
751 },
752 })));
720 753
721 return []; 754 return menu;
722 } 755 }
723 756
724 _getServiceName(service) { 757 _getServiceName(service) {