diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-03-08 15:28:35 +0100 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-03-08 15:28:35 +0100 |
commit | b6469566c2c88e8a61334d5d15a0f7c1afe08288 (patch) | |
tree | f42dd4962c74057c6432866205b16c9d78a1c07e /src/lib | |
parent | remove dev logs (diff) | |
parent | correctly update services submenu on language change (diff) | |
download | ferdium-app-b6469566c2c88e8a61334d5d15a0f7c1afe08288.tar.gz ferdium-app-b6469566c2c88e8a61334d5d15a0f7c1afe08288.tar.zst ferdium-app-b6469566c2c88e8a61334d5d15a0f7c1afe08288.zip |
fix merge conflicts with latest develop
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Menu.js | 138 |
1 files changed, 95 insertions, 43 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index c572bbb70..b21a62b4d 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'; |
@@ -181,6 +181,26 @@ const menuItems = defineMessages({ | |||
181 | id: 'menu.services.addNewService', | 181 | id: 'menu.services.addNewService', |
182 | defaultMessage: '!!!Add New Service...', | 182 | defaultMessage: '!!!Add New Service...', |
183 | }, | 183 | }, |
184 | addNewWorkspace: { | ||
185 | id: 'menu.workspaces.addNewWorkspace', | ||
186 | defaultMessage: '!!!Add New Workspace...', | ||
187 | }, | ||
188 | activateNextService: { | ||
189 | id: 'menu.services.setNextServiceActive', | ||
190 | defaultMessage: '!!!Activate next service...', | ||
191 | }, | ||
192 | activatePreviousService: { | ||
193 | id: 'menu.services.activatePreviousService', | ||
194 | defaultMessage: '!!!Activate previous service...', | ||
195 | }, | ||
196 | muteApp: { | ||
197 | id: 'sidebar.muteApp', | ||
198 | defaultMessage: '!!!Disable notifications & audio', | ||
199 | }, | ||
200 | unmuteApp: { | ||
201 | id: 'sidebar.unmuteApp', | ||
202 | defaultMessage: '!!!Enable notifications & audio', | ||
203 | }, | ||
184 | workspaces: { | 204 | workspaces: { |
185 | id: 'menu.workspaces', | 205 | id: 'menu.workspaces', |
186 | defaultMessage: '!!!Workspaces', | 206 | defaultMessage: '!!!Workspaces', |
@@ -189,10 +209,6 @@ const menuItems = defineMessages({ | |||
189 | id: 'menu.workspaces.defaultWorkspace', | 209 | id: 'menu.workspaces.defaultWorkspace', |
190 | defaultMessage: '!!!Default', | 210 | defaultMessage: '!!!Default', |
191 | }, | 211 | }, |
192 | addNewWorkspace: { | ||
193 | id: 'menu.workspaces.addNewWorkspace', | ||
194 | defaultMessage: '!!!Add New Workspace...', | ||
195 | }, | ||
196 | }); | 212 | }); |
197 | 213 | ||
198 | function getActiveWebview() { | 214 | function getActiveWebview() { |
@@ -253,16 +269,32 @@ const _templateFactory = intl => [ | |||
253 | }, | 269 | }, |
254 | { | 270 | { |
255 | label: intl.formatMessage(menuItems.resetZoom), | 271 | label: intl.formatMessage(menuItems.resetZoom), |
256 | role: 'resetzoom', | 272 | accelerator: 'Cmd+0', |
273 | click() { | ||
274 | getActiveWebview().setZoomLevel(0); | ||
275 | }, | ||
257 | }, | 276 | }, |
258 | { | 277 | { |
259 | label: intl.formatMessage(menuItems.zoomIn), | 278 | label: intl.formatMessage(menuItems.zoomIn), |
260 | // accelerator: 'Cmd+=', | 279 | accelerator: 'Cmd+plus', |
261 | role: 'zoomin', | 280 | click() { |
281 | const activeService = getActiveWebview(); | ||
282 | activeService.getZoomLevel((level) => { | ||
283 | // level 9 =~ +300% and setZoomLevel wouldnt zoom in further | ||
284 | if (level < 9) activeService.setZoomLevel(level + 1); | ||
285 | }); | ||
286 | }, | ||
262 | }, | 287 | }, |
263 | { | 288 | { |
264 | label: intl.formatMessage(menuItems.zoomOut), | 289 | label: intl.formatMessage(menuItems.zoomOut), |
265 | role: 'zoomout', | 290 | accelerator: 'Cmd+-', |
291 | click() { | ||
292 | const activeService = getActiveWebview(); | ||
293 | activeService.getZoomLevel((level) => { | ||
294 | // level -9 =~ -50% and setZoomLevel wouldnt zoom out further | ||
295 | if (level > -9) activeService.setZoomLevel(level - 1); | ||
296 | }); | ||
297 | }, | ||
266 | }, | 298 | }, |
267 | { | 299 | { |
268 | type: 'separator', | 300 | type: 'separator', |
@@ -410,10 +442,12 @@ const _titleBarTemplateFactory = intl => [ | |||
410 | }, | 442 | }, |
411 | { | 443 | { |
412 | label: intl.formatMessage(menuItems.zoomIn), | 444 | label: intl.formatMessage(menuItems.zoomIn), |
413 | accelerator: `${ctrlKey}+Plus`, | 445 | accelerator: `${ctrlKey}+=`, |
414 | click() { | 446 | click() { |
415 | getActiveWebview().getZoomLevel((zoomLevel) => { | 447 | const activeService = getActiveWebview(); |
416 | getActiveWebview().setZoomLevel(zoomLevel === 5 ? zoomLevel : zoomLevel + 1); | 448 | activeService.getZoomLevel((level) => { |
449 | // level 9 =~ +300% and setZoomLevel wouldnt zoom in further | ||
450 | if (level < 9) activeService.setZoomLevel(level + 1); | ||
417 | }); | 451 | }); |
418 | }, | 452 | }, |
419 | }, | 453 | }, |
@@ -421,8 +455,10 @@ const _titleBarTemplateFactory = intl => [ | |||
421 | label: intl.formatMessage(menuItems.zoomOut), | 455 | label: intl.formatMessage(menuItems.zoomOut), |
422 | accelerator: `${ctrlKey}+-`, | 456 | accelerator: `${ctrlKey}+-`, |
423 | click() { | 457 | click() { |
424 | getActiveWebview().getZoomLevel((zoomLevel) => { | 458 | const activeService = getActiveWebview(); |
425 | getActiveWebview().setZoomLevel(zoomLevel === -5 ? zoomLevel : zoomLevel - 1); | 459 | activeService.getZoomLevel((level) => { |
460 | // level -9 =~ -50% and setZoomLevel wouldnt zoom out further | ||
461 | if (level > -9) activeService.setZoomLevel(level - 1); | ||
426 | }); | 462 | }); |
427 | }, | 463 | }, |
428 | }, | 464 | }, |
@@ -518,14 +554,14 @@ export default class FranzMenu { | |||
518 | 554 | ||
519 | _build() { | 555 | _build() { |
520 | // need to clone object so we don't modify computed (cached) object | 556 | // need to clone object so we don't modify computed (cached) object |
521 | const serviceTpl = Object.assign([], this.serviceTpl); | 557 | const serviceTpl = Object.assign([], this.serviceTpl()); |
522 | const workspacesMenu = Object.assign([], this.workspacesMenu); | 558 | const workspacesMenu = Object.assign([], this.workspacesMenu()); |
523 | 559 | ||
524 | if (window.franz === undefined) { | 560 | if (window.franz === undefined) { |
525 | return; | 561 | return; |
526 | } | 562 | } |
527 | 563 | ||
528 | const intl = window.franz.intl; | 564 | const { intl } = window.franz; |
529 | const tpl = isMac ? _templateFactory(intl) : _titleBarTemplateFactory(intl); | 565 | const tpl = isMac ? _templateFactory(intl) : _titleBarTemplateFactory(intl); |
530 | 566 | ||
531 | tpl[1].submenu.push({ | 567 | tpl[1].submenu.push({ |
@@ -683,17 +719,6 @@ export default class FranzMenu { | |||
683 | }, about); | 719 | }, about); |
684 | } | 720 | } |
685 | 721 | ||
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) { | 722 | if (serviceTpl.length > 0) { |
698 | tpl[3].submenu = serviceTpl; | 723 | tpl[3].submenu = serviceTpl; |
699 | } | 724 | } |
@@ -705,25 +730,52 @@ export default class FranzMenu { | |||
705 | Menu.setApplicationMenu(menu); | 730 | Menu.setApplicationMenu(menu); |
706 | } | 731 | } |
707 | 732 | ||
708 | @computed get serviceTpl() { | 733 | serviceTpl() { |
709 | const services = this.stores.services.allDisplayed; | 734 | const { intl } = window.franz; |
735 | const { user, services, settings } = this.stores; | ||
736 | if (!user.isLoggedIn) return []; | ||
737 | const menu = []; | ||
710 | 738 | ||
711 | if (this.stores.user.isLoggedIn) { | 739 | menu.push({ |
712 | return services.map((service, i) => ({ | 740 | label: intl.formatMessage(menuItems.addNewService), |
713 | label: this._getServiceName(service), | 741 | accelerator: `${cmdKey}+N`, |
714 | accelerator: i < 9 ? `${cmdKey}+${i + 1}` : null, | 742 | click: () => { |
715 | type: 'radio', | 743 | this.actions.ui.openSettings({ path: 'recipes' }); |
716 | checked: service.isActive, | 744 | }, |
717 | click: () => { | 745 | }, { |
718 | this.actions.service.setActive({ serviceId: service.id }); | 746 | type: 'separator', |
719 | }, | 747 | }, { |
720 | })); | 748 | label: intl.formatMessage(menuItems.activateNextService), |
721 | } | 749 | accelerator: `${cmdKey}+alt+right`, |
750 | click: () => this.actions.service.setActiveNext(), | ||
751 | }, { | ||
752 | label: intl.formatMessage(menuItems.activatePreviousService), | ||
753 | accelerator: `${cmdKey}+alt+left`, | ||
754 | click: () => this.actions.service.setActivePrev(), | ||
755 | }, { | ||
756 | label: intl.formatMessage( | ||
757 | settings.all.app.isAppMuted ? menuItems.unmuteApp : menuItems.muteApp, | ||
758 | ).replace('&', '&&'), | ||
759 | accelerator: `${cmdKey}+shift+m`, | ||
760 | click: () => this.actions.app.toggleMuteApp(), | ||
761 | }, { | ||
762 | type: 'separator', | ||
763 | }); | ||
722 | 764 | ||
723 | return []; | 765 | services.allDisplayed.forEach((service, i) => (menu.push({ |
766 | label: this._getServiceName(service), | ||
767 | accelerator: i < 9 ? `${cmdKey}+${i + 1}` : null, | ||
768 | type: 'radio', | ||
769 | checked: service.isActive, | ||
770 | click: () => { | ||
771 | this.actions.service.setActive({ serviceId: service.id }); | ||
772 | }, | ||
773 | }))); | ||
774 | |||
775 | return menu; | ||
724 | } | 776 | } |
725 | 777 | ||
726 | @computed get workspacesMenu() { | 778 | workspacesMenu() { |
727 | const { workspaces, activeWorkspace } = workspacesState; | 779 | const { workspaces, activeWorkspace } = workspacesState; |
728 | const { intl } = window.franz; | 780 | const { intl } = window.franz; |
729 | const menu = []; | 781 | const menu = []; |