diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Menu.js | 127 | ||||
-rw-r--r-- | src/lib/Tray.js | 8 | ||||
-rw-r--r-- | src/lib/analytics.js | 4 |
3 files changed, 98 insertions, 41 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index c378619ad..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() { |
@@ -239,16 +255,32 @@ const _templateFactory = intl => [ | |||
239 | }, | 255 | }, |
240 | { | 256 | { |
241 | label: intl.formatMessage(menuItems.resetZoom), | 257 | label: intl.formatMessage(menuItems.resetZoom), |
242 | role: 'resetzoom', | 258 | accelerator: 'Cmd+0', |
259 | click() { | ||
260 | getActiveWebview().setZoomLevel(0); | ||
261 | }, | ||
243 | }, | 262 | }, |
244 | { | 263 | { |
245 | label: intl.formatMessage(menuItems.zoomIn), | 264 | label: intl.formatMessage(menuItems.zoomIn), |
246 | // accelerator: 'Cmd+=', | 265 | accelerator: 'Cmd+plus', |
247 | role: 'zoomin', | 266 | click() { |
267 | const activeService = getActiveWebview(); | ||
268 | activeService.getZoomLevel((level) => { | ||
269 | // level 9 =~ +300% and setZoomLevel wouldnt zoom in further | ||
270 | if (level < 9) activeService.setZoomLevel(level + 1); | ||
271 | }); | ||
272 | }, | ||
248 | }, | 273 | }, |
249 | { | 274 | { |
250 | label: intl.formatMessage(menuItems.zoomOut), | 275 | label: intl.formatMessage(menuItems.zoomOut), |
251 | role: 'zoomout', | 276 | accelerator: 'Cmd+-', |
277 | click() { | ||
278 | const activeService = getActiveWebview(); | ||
279 | activeService.getZoomLevel((level) => { | ||
280 | // level -9 =~ -50% and setZoomLevel wouldnt zoom out further | ||
281 | if (level > -9) activeService.setZoomLevel(level - 1); | ||
282 | }); | ||
283 | }, | ||
252 | }, | 284 | }, |
253 | { | 285 | { |
254 | type: 'separator', | 286 | type: 'separator', |
@@ -392,10 +424,12 @@ const _titleBarTemplateFactory = intl => [ | |||
392 | }, | 424 | }, |
393 | { | 425 | { |
394 | label: intl.formatMessage(menuItems.zoomIn), | 426 | label: intl.formatMessage(menuItems.zoomIn), |
395 | accelerator: `${ctrlKey}+Plus`, | 427 | accelerator: `${ctrlKey}+=`, |
396 | click() { | 428 | click() { |
397 | getActiveWebview().getZoomLevel((zoomLevel) => { | 429 | const activeService = getActiveWebview(); |
398 | getActiveWebview().setZoomLevel(zoomLevel === 5 ? zoomLevel : zoomLevel + 1); | 430 | activeService.getZoomLevel((level) => { |
431 | // level 9 =~ +300% and setZoomLevel wouldnt zoom in further | ||
432 | if (level < 9) activeService.setZoomLevel(level + 1); | ||
399 | }); | 433 | }); |
400 | }, | 434 | }, |
401 | }, | 435 | }, |
@@ -403,8 +437,10 @@ const _titleBarTemplateFactory = intl => [ | |||
403 | label: intl.formatMessage(menuItems.zoomOut), | 437 | label: intl.formatMessage(menuItems.zoomOut), |
404 | accelerator: `${ctrlKey}+-`, | 438 | accelerator: `${ctrlKey}+-`, |
405 | click() { | 439 | click() { |
406 | getActiveWebview().getZoomLevel((zoomLevel) => { | 440 | const activeService = getActiveWebview(); |
407 | getActiveWebview().setZoomLevel(zoomLevel === -5 ? zoomLevel : zoomLevel - 1); | 441 | activeService.getZoomLevel((level) => { |
442 | // level -9 =~ -50% and setZoomLevel wouldnt zoom out further | ||
443 | if (level > -9) activeService.setZoomLevel(level - 1); | ||
408 | }); | 444 | }); |
409 | }, | 445 | }, |
410 | }, | 446 | }, |
@@ -499,13 +535,14 @@ export default class FranzMenu { | |||
499 | } | 535 | } |
500 | 536 | ||
501 | _build() { | 537 | _build() { |
502 | 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()); | ||
503 | 540 | ||
504 | if (window.franz === undefined) { | 541 | if (window.franz === undefined) { |
505 | return; | 542 | return; |
506 | } | 543 | } |
507 | 544 | ||
508 | const intl = window.franz.intl; | 545 | const { intl } = window.franz; |
509 | const tpl = isMac ? _templateFactory(intl) : _titleBarTemplateFactory(intl); | 546 | const tpl = isMac ? _templateFactory(intl) : _titleBarTemplateFactory(intl); |
510 | 547 | ||
511 | tpl[1].submenu.push({ | 548 | tpl[1].submenu.push({ |
@@ -663,17 +700,6 @@ export default class FranzMenu { | |||
663 | }, about); | 700 | }, about); |
664 | } | 701 | } |
665 | 702 | ||
666 | serviceTpl.unshift({ | ||
667 | label: intl.formatMessage(menuItems.addNewService), | ||
668 | accelerator: `${cmdKey}+N`, | ||
669 | click: () => { | ||
670 | this.actions.ui.openSettings({ path: 'recipes' }); | ||
671 | }, | ||
672 | enabled: this.stores.user.isLoggedIn, | ||
673 | }, { | ||
674 | type: 'separator', | ||
675 | }); | ||
676 | |||
677 | if (serviceTpl.length > 0) { | 703 | if (serviceTpl.length > 0) { |
678 | tpl[3].submenu = serviceTpl; | 704 | tpl[3].submenu = serviceTpl; |
679 | } | 705 | } |
@@ -683,22 +709,49 @@ export default class FranzMenu { | |||
683 | Menu.setApplicationMenu(menu); | 709 | Menu.setApplicationMenu(menu); |
684 | } | 710 | } |
685 | 711 | ||
686 | @computed get serviceTpl() { | 712 | serviceTpl() { |
687 | 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 = []; | ||
688 | 717 | ||
689 | if (this.stores.user.isLoggedIn) { | 718 | menu.push({ |
690 | return services.map((service, i) => ({ | 719 | label: intl.formatMessage(menuItems.addNewService), |
691 | label: this._getServiceName(service), | 720 | accelerator: `${cmdKey}+N`, |
692 | accelerator: i < 9 ? `${cmdKey}+${i + 1}` : null, | 721 | click: () => { |
693 | type: 'radio', | 722 | this.actions.ui.openSettings({ path: 'recipes' }); |
694 | checked: service.isActive, | 723 | }, |
695 | click: () => { | 724 | }, { |
696 | this.actions.service.setActive({ serviceId: service.id }); | 725 | type: 'separator', |
697 | }, | 726 | }, { |
698 | })); | 727 | label: intl.formatMessage(menuItems.activateNextService), |
699 | } | 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 | }))); | ||
700 | 753 | ||
701 | return []; | 754 | return menu; |
702 | } | 755 | } |
703 | 756 | ||
704 | _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') { |
diff --git a/src/lib/analytics.js b/src/lib/analytics.js index 7044e5bb7..0519192d1 100644 --- a/src/lib/analytics.js +++ b/src/lib/analytics.js | |||
@@ -37,7 +37,3 @@ export function gaEvent(category, action, label) { | |||
37 | 37 | ||
38 | debug('GA track event', category, action); | 38 | debug('GA track event', category, action); |
39 | } | 39 | } |
40 | |||
41 | setTimeout(() => { | ||
42 | ga('send', 'Ping'); | ||
43 | }, 1000 * 60 * 10); // Ping GA every 10 Minutes | ||