diff options
author | Amine Mouafik <amine@mouafik.fr> | 2020-02-27 03:12:36 +0100 |
---|---|---|
committer | Amine Mouafik <amine@mouafik.fr> | 2020-02-27 03:12:36 +0100 |
commit | ce9e4d272ae28b7bd3c52aaf746829ea24ff6641 (patch) | |
tree | cd5a3fedc61ba762ebd0080c7b49eb7eec8e3bee /src | |
parent | Implement user.css and user.js (#401) (diff) | |
download | ferdium-app-ce9e4d272ae28b7bd3c52aaf746829ea24ff6641.tar.gz ferdium-app-ce9e4d272ae28b7bd3c52aaf746829ea24ff6641.tar.zst ferdium-app-ce9e4d272ae28b7bd3c52aaf746829ea24ff6641.zip |
Conditionally display Menu items based on lock state
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Menu.js | 163 |
1 files changed, 92 insertions, 71 deletions
diff --git a/src/lib/Menu.js b/src/lib/Menu.js index f2669a106..cd2ebaef5 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,83 +750,97 @@ 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 ? _templateFactory(intl, this.stores.settings.app.locked) : _titleBarTemplateFactory(intl); |
750 | const { actions } = this; | 754 | const { actions } = this; |
751 | 755 | ||
752 | tpl[1].submenu.push({ | 756 | 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({ | 757 | tpl[1].submenu.push({ |
771 | label: intl.formatMessage(menuItems.toggleTodosDevTools), | 758 | type: 'separator', |
772 | accelerator: `${cmdKey}+Shift+Alt+O`, | 759 | }, { |
760 | label: intl.formatMessage(menuItems.toggleDevTools), | ||
761 | accelerator: `${cmdKey}+Alt+I`, | ||
762 | click: (menuItem, browserWindow) => { | ||
763 | browserWindow.webContents.toggleDevTools(); | ||
764 | }, | ||
765 | }, { | ||
766 | label: intl.formatMessage(menuItems.toggleServiceDevTools), | ||
767 | accelerator: `${cmdKey}+Shift+Alt+I`, | ||
773 | click: () => { | 768 | click: () => { |
774 | const webview = document.querySelector('webview[partition="persist:todos"]'); | 769 | this.actions.service.openDevToolsForActiveService(); |
775 | if (webview) webview.openDevTools(); | ||
776 | }, | 770 | }, |
771 | enabled: this.stores.user.isLoggedIn && this.stores.services.enabled.length > 0, | ||
777 | }); | 772 | }); |
778 | } | ||
779 | 773 | ||
780 | tpl[1].submenu.unshift({ | 774 | if (this.stores.features.features.isTodosEnabled) { |
781 | label: intl.formatMessage(menuItems.reloadService), | 775 | tpl[1].submenu.push({ |
782 | id: 'reloadService', // TODO: needed? | 776 | label: intl.formatMessage(menuItems.toggleTodosDevTools), |
783 | accelerator: `${cmdKey}+R`, | 777 | accelerator: `${cmdKey}+Shift+Alt+O`, |
784 | click: () => { | 778 | click: () => { |
785 | if (this.stores.user.isLoggedIn | 779 | const webview = document.querySelector('webview[partition="persist:todos"]'); |
786 | && this.stores.services.enabled.length > 0) { | 780 | if (webview) webview.openDevTools(); |
787 | if (this.stores.services.active.recipe.id === CUSTOM_WEBSITE_ID) { | 781 | }, |
788 | this.stores.services.active.webview.reload(); | 782 | }); |
783 | } | ||
784 | |||
785 | tpl[1].submenu.unshift({ | ||
786 | label: intl.formatMessage(menuItems.reloadService), | ||
787 | id: 'reloadService', // TODO: needed? | ||
788 | accelerator: `${cmdKey}+R`, | ||
789 | click: () => { | ||
790 | if (this.stores.user.isLoggedIn | ||
791 | && this.stores.services.enabled.length > 0) { | ||
792 | if (this.stores.services.active.recipe.id === CUSTOM_WEBSITE_ID) { | ||
793 | this.stores.services.active.webview.reload(); | ||
794 | } else { | ||
795 | this.actions.service.reloadActive(); | ||
796 | } | ||
789 | } else { | 797 | } else { |
790 | this.actions.service.reloadActive(); | 798 | window.location.reload(); |
791 | } | 799 | } |
792 | } else { | 800 | }, |
801 | }, { | ||
802 | label: intl.formatMessage(menuItems.reloadFranz), | ||
803 | accelerator: `${cmdKey}+Shift+R`, | ||
804 | click: () => { | ||
793 | window.location.reload(); | 805 | window.location.reload(); |
794 | } | 806 | }, |
795 | }, | 807 | }, { |
796 | }, { | 808 | type: 'separator', |
797 | label: intl.formatMessage(menuItems.reloadFranz), | 809 | }, { |
798 | accelerator: `${cmdKey}+Shift+R`, | 810 | label: intl.formatMessage(menuItems.lockFerdi), |
799 | click: () => { | 811 | accelerator: 'CmdOrCtrl+Shift+L', |
800 | window.location.reload(); | 812 | enabled: this.stores.user.isLoggedIn && this.stores.settings.app.lockingFeatureEnabled, |
801 | }, | 813 | click() { |
802 | }, { | 814 | // Disable lock first - otherwise the application might not update correctly |
803 | type: 'separator', | ||
804 | }, { | ||
805 | label: intl.formatMessage(menuItems.lockFerdi), | ||
806 | accelerator: 'CmdOrCtrl+Shift+L', | ||
807 | enabled: this.stores.user.isLoggedIn && this.stores.settings.app.lockingFeatureEnabled, | ||
808 | click() { | ||
809 | // Disable lock first - otherwise the application might not update correctly | ||
810 | actions.settings.update({ | ||
811 | type: 'app', | ||
812 | data: { | ||
813 | locked: false, | ||
814 | }, | ||
815 | }); | ||
816 | setTimeout(() => { | ||
817 | actions.settings.update({ | 815 | actions.settings.update({ |
818 | type: 'app', | 816 | type: 'app', |
819 | data: { | 817 | data: { |
820 | locked: true, | 818 | locked: false, |
821 | }, | 819 | }, |
822 | }); | 820 | }); |
823 | }, 0); | 821 | setTimeout(() => { |
824 | }, | 822 | actions.settings.update({ |
825 | }); | 823 | type: 'app', |
824 | data: { | ||
825 | locked: true, | ||
826 | }, | ||
827 | }); | ||
828 | }, 0); | ||
829 | }, | ||
830 | }); | ||
831 | |||
832 | if (serviceTpl.length > 0) { | ||
833 | tpl[3].submenu = serviceTpl; | ||
834 | } | ||
835 | |||
836 | if (workspaceStore.isFeatureEnabled) { | ||
837 | tpl[4].submenu = this.workspacesMenu(); | ||
838 | } | ||
839 | |||
840 | if (todosStore.isFeatureEnabled) { | ||
841 | tpl[5].submenu = this.todosMenu(); | ||
842 | } | ||
843 | } | ||
826 | 844 | ||
827 | tpl.unshift({ | 845 | tpl.unshift({ |
828 | label: isMac ? app.name : intl.formatMessage(menuItems.file), | 846 | label: isMac ? app.name : intl.formatMessage(menuItems.file), |
@@ -842,15 +860,18 @@ export default class FranzMenu { | |||
842 | this.actions.ui.openSettings({ path: 'app' }); | 860 | this.actions.ui.openSettings({ path: 'app' }); |
843 | }, | 861 | }, |
844 | enabled: this.stores.user.isLoggedIn, | 862 | enabled: this.stores.user.isLoggedIn, |
863 | visible: !this.stores.settings.app.locked, | ||
845 | }, | 864 | }, |
846 | { | 865 | { |
847 | label: intl.formatMessage(menuItems.checkForUpdates), | 866 | label: intl.formatMessage(menuItems.checkForUpdates), |
867 | visible: !this.stores.settings.app.locked, | ||
848 | click: () => { | 868 | click: () => { |
849 | this.actions.app.checkForUpdates(); | 869 | this.actions.app.checkForUpdates(); |
850 | }, | 870 | }, |
851 | }, | 871 | }, |
852 | { | 872 | { |
853 | type: 'separator', | 873 | type: 'separator', |
874 | visible: !this.stores.settings.app.locked, | ||
854 | }, | 875 | }, |
855 | { | 876 | { |
856 | label: intl.formatMessage(menuItems.services), | 877 | label: intl.formatMessage(menuItems.services), |
@@ -930,6 +951,7 @@ export default class FranzMenu { | |||
930 | this.actions.ui.openSettings({ path: 'app' }); | 951 | this.actions.ui.openSettings({ path: 'app' }); |
931 | }, | 952 | }, |
932 | enabled: this.stores.user.isLoggedIn, | 953 | enabled: this.stores.user.isLoggedIn, |
954 | visible: !this.stores.settings.locked, | ||
933 | }, | 955 | }, |
934 | { | 956 | { |
935 | type: 'separator', | 957 | type: 'separator', |
@@ -967,8 +989,7 @@ export default class FranzMenu { | |||
967 | 989 | ||
968 | this.currentTemplate = tpl; | 990 | this.currentTemplate = tpl; |
969 | const menu = Menu.buildFromTemplate(tpl); | 991 | const menu = Menu.buildFromTemplate(tpl); |
970 | const lockedMenu = Menu.buildFromTemplate([]); | 992 | Menu.setApplicationMenu(menu); |
971 | Menu.setApplicationMenu(this.stores.user.isLoggedIn && this.stores.settings.app.locked ? lockedMenu : menu); | ||
972 | } | 993 | } |
973 | 994 | ||
974 | serviceTpl() { | 995 | serviceTpl() { |