diff options
author | 2020-02-28 15:19:36 +0100 | |
---|---|---|
committer | 2020-02-28 15:19:36 +0100 | |
commit | 631b6530648b97feff3ed4fac08b34ca360e11f7 (patch) | |
tree | a47bb1ffb8104c8913ada031cf0a2d44caa79193 /src/lib/Menu.js | |
parent | Merge pull request #393 from getferdi/refactor/lock (diff) | |
parent | Pass missing lock state to _titleBarTemplateFactory (diff) | |
download | ferdium-app-631b6530648b97feff3ed4fac08b34ca360e11f7.tar.gz ferdium-app-631b6530648b97feff3ed4fac08b34ca360e11f7.tar.zst ferdium-app-631b6530648b97feff3ed4fac08b34ca360e11f7.zip |
Merge pull request #408 from getferdi/fix/lock-menu
Conditionally display Menu items based on lock state
Diffstat (limited to 'src/lib/Menu.js')
-rw-r--r-- | src/lib/Menu.js | 164 |
1 files changed, 94 insertions, 70 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index f66dab111..91e7c981a 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js | |||
@@ -300,7 +300,7 @@ function termsBase() { | |||
300 | return window.ferdi.stores.settings.all.app.server !== 'https://api.franzinfra.com' ? window.ferdi.stores.settings.all.app.server : 'https://meetfranz.com'; | 300 | return window.ferdi.stores.settings.all.app.server !== 'https://api.franzinfra.com' ? window.ferdi.stores.settings.all.app.server : 'https://meetfranz.com'; |
301 | } | 301 | } |
302 | 302 | ||
303 | const _templateFactory = intl => [ | 303 | const _templateFactory = (intl, locked) => [ |
304 | { | 304 | { |
305 | label: intl.formatMessage(menuItems.edit), | 305 | label: intl.formatMessage(menuItems.edit), |
306 | submenu: [ | 306 | submenu: [ |
@@ -351,6 +351,7 @@ const _templateFactory = intl => [ | |||
351 | }, | 351 | }, |
352 | { | 352 | { |
353 | label: intl.formatMessage(menuItems.view), | 353 | label: intl.formatMessage(menuItems.view), |
354 | visible: !locked, | ||
354 | submenu: [ | 355 | submenu: [ |
355 | { | 356 | { |
356 | type: 'separator', | 357 | type: 'separator', |
@@ -426,17 +427,18 @@ const _templateFactory = intl => [ | |||
426 | }, | 427 | }, |
427 | { | 428 | { |
428 | label: intl.formatMessage(menuItems.services), | 429 | label: intl.formatMessage(menuItems.services), |
430 | visible: !locked, | ||
429 | submenu: [], | 431 | submenu: [], |
430 | }, | 432 | }, |
431 | { | 433 | { |
432 | label: intl.formatMessage(menuItems.workspaces), | 434 | label: intl.formatMessage(menuItems.workspaces), |
433 | submenu: [], | 435 | submenu: [], |
434 | visible: workspaceStore.isFeatureEnabled, | 436 | visible: !locked && workspaceStore.isFeatureEnabled, |
435 | }, | 437 | }, |
436 | { | 438 | { |
437 | label: intl.formatMessage(menuItems.todos), | 439 | label: intl.formatMessage(menuItems.todos), |
438 | submenu: [], | 440 | submenu: [], |
439 | visible: todosStore.isFeatureEnabled, | 441 | visible: !locked && todosStore.isFeatureEnabled, |
440 | }, | 442 | }, |
441 | { | 443 | { |
442 | label: intl.formatMessage(menuItems.window), | 444 | label: intl.formatMessage(menuItems.window), |
@@ -465,7 +467,7 @@ const _templateFactory = intl => [ | |||
465 | click: () => { | 467 | click: () => { |
466 | announcementActions.show(); | 468 | announcementActions.show(); |
467 | }, | 469 | }, |
468 | visible: window.ferdi.stores.user.isLoggedIn && announcementsStore.areNewsAvailable, | 470 | visible: !locked && window.ferdi.stores.user.isLoggedIn && announcementsStore.areNewsAvailable, |
469 | }, | 471 | }, |
470 | { | 472 | { |
471 | type: 'separator', | 473 | type: 'separator', |
@@ -489,7 +491,7 @@ const _templateFactory = intl => [ | |||
489 | }, | 491 | }, |
490 | ]; | 492 | ]; |
491 | 493 | ||
492 | const _titleBarTemplateFactory = intl => [ | 494 | const _titleBarTemplateFactory = (intl, locked) => [ |
493 | { | 495 | { |
494 | label: intl.formatMessage(menuItems.edit), | 496 | label: intl.formatMessage(menuItems.edit), |
495 | accelerator: 'Alt+E', | 497 | accelerator: 'Alt+E', |
@@ -557,6 +559,7 @@ const _titleBarTemplateFactory = intl => [ | |||
557 | { | 559 | { |
558 | label: intl.formatMessage(menuItems.view), | 560 | label: intl.formatMessage(menuItems.view), |
559 | accelerator: 'Alt+V', | 561 | accelerator: 'Alt+V', |
562 | visible: !locked, | ||
560 | submenu: [ | 563 | submenu: [ |
561 | { | 564 | { |
562 | type: 'separator', | 565 | type: 'separator', |
@@ -649,18 +652,19 @@ const _titleBarTemplateFactory = intl => [ | |||
649 | { | 652 | { |
650 | label: intl.formatMessage(menuItems.services), | 653 | label: intl.formatMessage(menuItems.services), |
651 | accelerator: 'Alt+S', | 654 | accelerator: 'Alt+S', |
655 | visible: !locked, | ||
652 | submenu: [], | 656 | submenu: [], |
653 | }, | 657 | }, |
654 | { | 658 | { |
655 | label: intl.formatMessage(menuItems.workspaces), | 659 | label: intl.formatMessage(menuItems.workspaces), |
656 | accelerator: 'Alt+W', | 660 | accelerator: 'Alt+W', |
657 | submenu: [], | 661 | submenu: [], |
658 | visible: workspaceStore.isFeatureEnabled, | 662 | visible: !locked && workspaceStore.isFeatureEnabled, |
659 | }, | 663 | }, |
660 | { | 664 | { |
661 | label: intl.formatMessage(menuItems.todos), | 665 | label: intl.formatMessage(menuItems.todos), |
662 | submenu: [], | 666 | submenu: [], |
663 | visible: todosStore.isFeatureEnabled, | 667 | visible: !locked && todosStore.isFeatureEnabled, |
664 | }, | 668 | }, |
665 | { | 669 | { |
666 | label: intl.formatMessage(menuItems.window), | 670 | label: intl.formatMessage(menuItems.window), |
@@ -746,74 +750,90 @@ export default class FranzMenu { | |||
746 | } | 750 | } |
747 | 751 | ||
748 | const { intl } = window.ferdi; | 752 | const { intl } = window.ferdi; |
749 | const tpl = isMac ? _templateFactory(intl) : _titleBarTemplateFactory(intl); | 753 | const tpl = isMac |
754 | ? _templateFactory(intl, this.stores.settings.app.locked) | ||
755 | : _titleBarTemplateFactory(intl, this.stores.settings.app.locked); | ||
750 | const { actions } = this; | 756 | const { actions } = this; |
751 | 757 | ||
752 | tpl[1].submenu.push({ | 758 | if (this.stores.settings.app.locked) { |
753 | type: 'separator', | ||
754 | }, { | ||
755 | label: intl.formatMessage(menuItems.toggleDevTools), | ||
756 | accelerator: `${cmdKey}+Alt+I`, | ||
757 | click: (menuItem, browserWindow) => { | ||
758 | browserWindow.webContents.toggleDevTools(); | ||
759 | }, | ||
760 | }, { | ||
761 | label: intl.formatMessage(menuItems.toggleServiceDevTools), | ||
762 | accelerator: `${cmdKey}+Shift+Alt+I`, | ||
763 | click: () => { | ||
764 | this.actions.service.openDevToolsForActiveService(); | ||
765 | }, | ||
766 | enabled: this.stores.user.isLoggedIn && this.stores.services.enabled.length > 0, | ||
767 | }); | ||
768 | |||
769 | if (this.stores.features.features.isTodosEnabled) { | ||
770 | tpl[1].submenu.push({ | 759 | tpl[1].submenu.push({ |
771 | label: intl.formatMessage(menuItems.toggleTodosDevTools), | 760 | type: 'separator', |
772 | accelerator: `${cmdKey}+Shift+Alt+O`, | 761 | }, { |
762 | label: intl.formatMessage(menuItems.toggleDevTools), | ||
763 | accelerator: `${cmdKey}+Alt+I`, | ||
764 | click: (menuItem, browserWindow) => { | ||
765 | browserWindow.webContents.toggleDevTools(); | ||
766 | }, | ||
767 | }, { | ||
768 | label: intl.formatMessage(menuItems.toggleServiceDevTools), | ||
769 | accelerator: `${cmdKey}+Shift+Alt+I`, | ||
773 | click: () => { | 770 | click: () => { |
774 | const webview = document.querySelector('webview[partition="persist:todos"]'); | 771 | this.actions.service.openDevToolsForActiveService(); |
775 | if (webview) webview.openDevTools(); | ||
776 | }, | 772 | }, |
773 | enabled: this.stores.user.isLoggedIn && this.stores.services.enabled.length > 0, | ||
777 | }); | 774 | }); |
778 | } | ||
779 | 775 | ||
780 | tpl[1].submenu.unshift({ | 776 | if (this.stores.features.features.isTodosEnabled) { |
781 | label: intl.formatMessage(menuItems.reloadService), | 777 | tpl[1].submenu.push({ |
782 | id: 'reloadService', // TODO: needed? | 778 | label: intl.formatMessage(menuItems.toggleTodosDevTools), |
783 | accelerator: `${cmdKey}+R`, | 779 | accelerator: `${cmdKey}+Shift+Alt+O`, |
784 | click: () => { | 780 | click: () => { |
785 | if (this.stores.user.isLoggedIn | 781 | const webview = document.querySelector('webview[partition="persist:todos"]'); |
786 | && this.stores.services.enabled.length > 0) { | 782 | if (webview) webview.openDevTools(); |
787 | if (this.stores.services.active.recipe.id === CUSTOM_WEBSITE_ID) { | 783 | }, |
788 | this.stores.services.active.webview.reload(); | 784 | }); |
785 | } | ||
786 | |||
787 | tpl[1].submenu.unshift({ | ||
788 | label: intl.formatMessage(menuItems.reloadService), | ||
789 | id: 'reloadService', // TODO: needed? | ||
790 | accelerator: `${cmdKey}+R`, | ||
791 | click: () => { | ||
792 | if (this.stores.user.isLoggedIn | ||
793 | && this.stores.services.enabled.length > 0) { | ||
794 | if (this.stores.services.active.recipe.id === CUSTOM_WEBSITE_ID) { | ||
795 | this.stores.services.active.webview.reload(); | ||
796 | } else { | ||
797 | this.actions.service.reloadActive(); | ||
798 | } | ||
789 | } else { | 799 | } else { |
790 | this.actions.service.reloadActive(); | 800 | window.location.reload(); |
791 | } | 801 | } |
792 | } else { | 802 | }, |
803 | }, { | ||
804 | label: intl.formatMessage(menuItems.reloadFranz), | ||
805 | accelerator: `${cmdKey}+Shift+R`, | ||
806 | click: () => { | ||
793 | window.location.reload(); | 807 | window.location.reload(); |
808 | }, | ||
809 | }, { | ||
810 | type: 'separator', | ||
811 | }, { | ||
812 | label: intl.formatMessage(menuItems.lockFerdi), | ||
813 | accelerator: 'CmdOrCtrl+Shift+L', | ||
814 | enabled: this.stores.user.isLoggedIn && this.stores.settings.app.lockingFeatureEnabled, | ||
815 | click() { | ||
816 | actions.settings.update({ | ||
817 | type: 'app', | ||
818 | data: { | ||
819 | locked: true, | ||
820 | }, | ||
821 | }); | ||
794 | } | 822 | } |
795 | }, | 823 | }); |
796 | }, { | 824 | |
797 | label: intl.formatMessage(menuItems.reloadFranz), | 825 | if (serviceTpl.length > 0) { |
798 | accelerator: `${cmdKey}+Shift+R`, | 826 | tpl[3].submenu = serviceTpl; |
799 | click: () => { | 827 | } |
800 | window.location.reload(); | 828 | |
801 | }, | 829 | if (workspaceStore.isFeatureEnabled) { |
802 | }, { | 830 | tpl[4].submenu = this.workspacesMenu(); |
803 | type: 'separator', | 831 | } |
804 | }, { | 832 | |
805 | label: intl.formatMessage(menuItems.lockFerdi), | 833 | if (todosStore.isFeatureEnabled) { |
806 | accelerator: 'CmdOrCtrl+Shift+L', | 834 | tpl[5].submenu = this.todosMenu(); |
807 | enabled: this.stores.user.isLoggedIn && this.stores.settings.app.lockingFeatureEnabled, | 835 | } |
808 | click() { | 836 | } |
809 | actions.settings.update({ | ||
810 | type: 'app', | ||
811 | data: { | ||
812 | locked: true, | ||
813 | }, | ||
814 | }); | ||
815 | }, | ||
816 | }); | ||
817 | 837 | ||
818 | tpl.unshift({ | 838 | tpl.unshift({ |
819 | label: isMac ? app.name : intl.formatMessage(menuItems.file), | 839 | label: isMac ? app.name : intl.formatMessage(menuItems.file), |
@@ -833,15 +853,18 @@ export default class FranzMenu { | |||
833 | this.actions.ui.openSettings({ path: 'app' }); | 853 | this.actions.ui.openSettings({ path: 'app' }); |
834 | }, | 854 | }, |
835 | enabled: this.stores.user.isLoggedIn, | 855 | enabled: this.stores.user.isLoggedIn, |
856 | visible: !this.stores.settings.app.locked, | ||
836 | }, | 857 | }, |
837 | { | 858 | { |
838 | label: intl.formatMessage(menuItems.checkForUpdates), | 859 | label: intl.formatMessage(menuItems.checkForUpdates), |
860 | visible: !this.stores.settings.app.locked, | ||
839 | click: () => { | 861 | click: () => { |
840 | this.actions.app.checkForUpdates(); | 862 | this.actions.app.checkForUpdates(); |
841 | }, | 863 | }, |
842 | }, | 864 | }, |
843 | { | 865 | { |
844 | type: 'separator', | 866 | type: 'separator', |
867 | visible: !this.stores.settings.app.locked, | ||
845 | }, | 868 | }, |
846 | { | 869 | { |
847 | label: intl.formatMessage(menuItems.services), | 870 | label: intl.formatMessage(menuItems.services), |
@@ -921,6 +944,7 @@ export default class FranzMenu { | |||
921 | this.actions.ui.openSettings({ path: 'app' }); | 944 | this.actions.ui.openSettings({ path: 'app' }); |
922 | }, | 945 | }, |
923 | enabled: this.stores.user.isLoggedIn, | 946 | enabled: this.stores.user.isLoggedIn, |
947 | visible: !this.stores.settings.locked, | ||
924 | }, | 948 | }, |
925 | { | 949 | { |
926 | type: 'separator', | 950 | type: 'separator', |
@@ -952,14 +976,14 @@ export default class FranzMenu { | |||
952 | tpl[5].submenu = this.todosMenu(); | 976 | tpl[5].submenu = this.todosMenu(); |
953 | } | 977 | } |
954 | 978 | ||
955 | tpl[tpl.length - 1].submenu.push({ | 979 | if (!this.stores.settings.app.locked) { |
956 | type: 'separator', | 980 | tpl[tpl.length - 1].submenu.push({ |
957 | }, ...this.debugMenu()); | 981 | type: 'separator', |
958 | 982 | }, ...this.debugMenu()); | |
983 | } | ||
959 | this.currentTemplate = tpl; | 984 | this.currentTemplate = tpl; |
960 | const menu = Menu.buildFromTemplate(tpl); | 985 | const menu = Menu.buildFromTemplate(tpl); |
961 | const lockedMenu = new Menu(); | 986 | Menu.setApplicationMenu(menu); |
962 | Menu.setApplicationMenu(this.stores.user.isLoggedIn && this.stores.settings.app.locked ? lockedMenu : menu); | ||
963 | } | 987 | } |
964 | 988 | ||
965 | serviceTpl() { | 989 | serviceTpl() { |