diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Menu.js | 91 | ||||
-rw-r--r-- | src/lib/Tray.js | 8 |
2 files changed, 70 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 @@ | |||
1 | import { remote, shell } from 'electron'; | 1 | import { remote, shell } from 'electron'; |
2 | import { observable, autorun, computed } from 'mobx'; | 2 | 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'; |
@@ -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 | ||
184 | function getActiveWebview() { | 200 | function 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) { |
diff --git a/src/lib/Tray.js b/src/lib/Tray.js index 669b02709..192e24796 100644 --- a/src/lib/Tray.js +++ b/src/lib/Tray.js | |||
@@ -22,7 +22,11 @@ export default class TrayIcon { | |||
22 | { | 22 | { |
23 | label: 'Show Franz', | 23 | label: 'Show Franz', |
24 | click() { | 24 | click() { |
25 | if (app.mainWindow.isMinimized()) { | ||
26 | app.mainWindow.restore(); | ||
27 | } | ||
25 | app.mainWindow.show(); | 28 | app.mainWindow.show(); |
29 | app.mainWindow.focus(); | ||
26 | }, | 30 | }, |
27 | }, { | 31 | }, { |
28 | label: 'Quit Franz', | 32 | label: 'Quit Franz', |
@@ -36,7 +40,11 @@ export default class TrayIcon { | |||
36 | this.trayIcon.setContextMenu(trayMenu); | 40 | this.trayIcon.setContextMenu(trayMenu); |
37 | 41 | ||
38 | this.trayIcon.on('click', () => { | 42 | this.trayIcon.on('click', () => { |
43 | if (app.mainWindow.isMinimized()) { | ||
44 | app.mainWindow.restore(); | ||
45 | } | ||
39 | app.mainWindow.show(); | 46 | app.mainWindow.show(); |
47 | app.mainWindow.focus(); | ||
40 | }); | 48 | }); |
41 | 49 | ||
42 | if (process.platform === 'darwin') { | 50 | if (process.platform === 'darwin') { |