diff options
author | Vijay A <vraravam@users.noreply.github.com> | 2024-06-23 22:21:14 +0530 |
---|---|---|
committer | Vijay A <vraravam@users.noreply.github.com> | 2024-06-23 22:21:14 +0530 |
commit | 65cea57b6195f998ccb0f664e7cdbd90ce298013 (patch) | |
tree | 5133f59ccc69d82c7e053de90a03a3268a492af1 /src | |
parent | 6.7.5-nightly.15 [skip ci] (diff) | |
download | ferdium-app-65cea57b6195f998ccb0f664e7cdbd90ce298013.tar.gz ferdium-app-65cea57b6195f998ccb0f664e7cdbd90ce298013.tar.zst ferdium-app-65cea57b6195f998ccb0f664e7cdbd90ce298013.zip |
Minor refactoring to not return menu where not needed
Diffstat (limited to 'src')
-rw-r--r-- | src/helpers/userAgent-helpers.ts | 4 | ||||
-rw-r--r-- | src/index.ts | 6 | ||||
-rw-r--r-- | src/webview/contextMenuBuilder.ts | 66 |
3 files changed, 26 insertions, 50 deletions
diff --git a/src/helpers/userAgent-helpers.ts b/src/helpers/userAgent-helpers.ts index fd9b8c835..b5aa02432 100644 --- a/src/helpers/userAgent-helpers.ts +++ b/src/helpers/userAgent-helpers.ts | |||
@@ -17,7 +17,7 @@ function macOS() { | |||
17 | // eslint-disable-next-line prefer-destructuring | 17 | // eslint-disable-next-line prefer-destructuring |
18 | cpuName = cpuName.split('(')[0]; | 18 | cpuName = cpuName.split('(')[0]; |
19 | } | 19 | } |
20 | return `Macintosh; ${cpuName} Mac OS X ${version.replaceAll('.', '_')}`; | 20 | return `Macintosh; ${cpuName} macOS ${version.replaceAll('.', '_')}`; |
21 | } | 21 | } |
22 | 22 | ||
23 | function windows() { | 23 | function windows() { |
@@ -33,7 +33,7 @@ function linux() { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | export default function userAgent() { | 35 | export default function userAgent() { |
36 | let platformString = ''; | 36 | let platformString; |
37 | 37 | ||
38 | if (isMac) { | 38 | if (isMac) { |
39 | platformString = macOS(); | 39 | platformString = macOS(); |
diff --git a/src/index.ts b/src/index.ts index a602c994e..286b305c2 100644 --- a/src/index.ts +++ b/src/index.ts | |||
@@ -702,8 +702,7 @@ ipcMain.on('toggle-pause-download', (_e, data) => { | |||
702 | 702 | ||
703 | // Quit when all windows are closed. | 703 | // Quit when all windows are closed. |
704 | app.on('window-all-closed', () => { | 704 | app.on('window-all-closed', () => { |
705 | // On OS X it is common for applications and their menu bar | 705 | // On macos it is common for applications and their menu bar to stay active until the user quits explicitly with Cmd + Q |
706 | // to stay active until the user quits explicitly with Cmd + Q | ||
707 | if ( | 706 | if ( |
708 | retrieveSettingValue( | 707 | retrieveSettingValue( |
709 | 'runInBackground', | 708 | 'runInBackground', |
@@ -746,8 +745,7 @@ app.on('before-quit', event => { | |||
746 | }); | 745 | }); |
747 | 746 | ||
748 | app.on('activate', () => { | 747 | app.on('activate', () => { |
749 | // On OS X it's common to re-create a window in the app when the | 748 | // On macos it's common to re-create a window in the app when the dock icon is clicked and there are no other windows open. |
750 | // dock icon is clicked and there are no other windows open. | ||
751 | if (mainWindow === null) { | 749 | if (mainWindow === null) { |
752 | createWindow(); | 750 | createWindow(); |
753 | } else { | 751 | } else { |
diff --git a/src/webview/contextMenuBuilder.ts b/src/webview/contextMenuBuilder.ts index d92e18aa9..d68605963 100644 --- a/src/webview/contextMenuBuilder.ts +++ b/src/webview/contextMenuBuilder.ts | |||
@@ -643,7 +643,7 @@ export class ContextMenuBuilder { | |||
643 | addImageItems( | 643 | addImageItems( |
644 | menu: Electron.CrossProcessExports.Menu, | 644 | menu: Electron.CrossProcessExports.Menu, |
645 | menuInfo: IContextMenuParams, | 645 | menuInfo: IContextMenuParams, |
646 | ) { | 646 | ): void { |
647 | const copyImage = new MenuItem({ | 647 | const copyImage = new MenuItem({ |
648 | label: this.stringTable.copyImage(), | 648 | label: this.stringTable.copyImage(), |
649 | click: () => { | 649 | click: () => { |
@@ -718,8 +718,6 @@ export class ContextMenuBuilder { | |||
718 | 718 | ||
719 | menu.append(downloadImage); | 719 | menu.append(downloadImage); |
720 | } | 720 | } |
721 | |||
722 | return menu; | ||
723 | } | 721 | } |
724 | 722 | ||
725 | /** | 723 | /** |
@@ -728,7 +726,7 @@ export class ContextMenuBuilder { | |||
728 | addCut( | 726 | addCut( |
729 | menu: Electron.CrossProcessExports.Menu, | 727 | menu: Electron.CrossProcessExports.Menu, |
730 | menuInfo: IContextMenuParams, | 728 | menuInfo: IContextMenuParams, |
731 | ) { | 729 | ): void { |
732 | const webContents = this.getWebContents(); | 730 | const webContents = this.getWebContents(); |
733 | menu.append( | 731 | menu.append( |
734 | new MenuItem({ | 732 | new MenuItem({ |
@@ -738,8 +736,6 @@ export class ContextMenuBuilder { | |||
738 | click: () => webContents.cut(), | 736 | click: () => webContents.cut(), |
739 | }), | 737 | }), |
740 | ); | 738 | ); |
741 | |||
742 | return menu; | ||
743 | } | 739 | } |
744 | 740 | ||
745 | /** | 741 | /** |
@@ -748,7 +744,7 @@ export class ContextMenuBuilder { | |||
748 | addCopy( | 744 | addCopy( |
749 | menu: Electron.CrossProcessExports.Menu, | 745 | menu: Electron.CrossProcessExports.Menu, |
750 | menuInfo: IContextMenuParams, | 746 | menuInfo: IContextMenuParams, |
751 | ) { | 747 | ): void { |
752 | const webContents = this.getWebContents(); | 748 | const webContents = this.getWebContents(); |
753 | menu.append( | 749 | menu.append( |
754 | new MenuItem({ | 750 | new MenuItem({ |
@@ -758,8 +754,6 @@ export class ContextMenuBuilder { | |||
758 | click: () => webContents.copy(), | 754 | click: () => webContents.copy(), |
759 | }), | 755 | }), |
760 | ); | 756 | ); |
761 | |||
762 | return menu; | ||
763 | } | 757 | } |
764 | 758 | ||
765 | /** | 759 | /** |
@@ -768,7 +762,7 @@ export class ContextMenuBuilder { | |||
768 | addPaste( | 762 | addPaste( |
769 | menu: Electron.CrossProcessExports.Menu, | 763 | menu: Electron.CrossProcessExports.Menu, |
770 | menuInfo: IContextMenuParams, | 764 | menuInfo: IContextMenuParams, |
771 | ) { | 765 | ): void { |
772 | const webContents = this.getWebContents(); | 766 | const webContents = this.getWebContents(); |
773 | menu.append( | 767 | menu.append( |
774 | new MenuItem({ | 768 | new MenuItem({ |
@@ -778,14 +772,12 @@ export class ContextMenuBuilder { | |||
778 | click: () => webContents.paste(), | 772 | click: () => webContents.paste(), |
779 | }), | 773 | }), |
780 | ); | 774 | ); |
781 | |||
782 | return menu; | ||
783 | } | 775 | } |
784 | 776 | ||
785 | addPastePlain( | 777 | addPastePlain( |
786 | menu: Electron.CrossProcessExports.Menu, | 778 | menu: Electron.CrossProcessExports.Menu, |
787 | menuInfo: IContextMenuParams, | 779 | menuInfo: IContextMenuParams, |
788 | ) { | 780 | ): void { |
789 | if ( | 781 | if ( |
790 | menuInfo.editFlags.canPaste && | 782 | menuInfo.editFlags.canPaste && |
791 | !menuInfo.linkText && | 783 | !menuInfo.linkText && |
@@ -805,9 +797,8 @@ export class ContextMenuBuilder { | |||
805 | /** | 797 | /** |
806 | * Adds a separator item. | 798 | * Adds a separator item. |
807 | */ | 799 | */ |
808 | addSeparator(menu: Electron.CrossProcessExports.Menu) { | 800 | addSeparator(menu: Electron.CrossProcessExports.Menu): void { |
809 | menu.append(new MenuItem({ type: 'separator' })); | 801 | menu.append(new MenuItem({ type: 'separator' })); |
810 | return menu; | ||
811 | } | 802 | } |
812 | 803 | ||
813 | /** | 804 | /** |
@@ -817,18 +808,17 @@ export class ContextMenuBuilder { | |||
817 | menu: Electron.CrossProcessExports.Menu, | 808 | menu: Electron.CrossProcessExports.Menu, |
818 | menuInfo: IContextMenuParams, | 809 | menuInfo: IContextMenuParams, |
819 | needsSeparator = true, | 810 | needsSeparator = true, |
820 | ) { | 811 | ): void { |
821 | const webContents = this.getWebContents(); | 812 | const webContents = this.getWebContents(); |
822 | if (!this.debugMode) return menu; | 813 | if (!this.debugMode) return; |
823 | if (needsSeparator) this.addSeparator(menu); | 814 | if (needsSeparator) this.addSeparator(menu); |
824 | 815 | ||
825 | const inspect = new MenuItem({ | 816 | menu.append( |
826 | label: this.stringTable.inspectElement(), | 817 | new MenuItem({ |
827 | click: () => webContents.inspectElement(menuInfo.x, menuInfo.y), | 818 | label: this.stringTable.inspectElement(), |
828 | }); | 819 | click: () => webContents.inspectElement(menuInfo.x, menuInfo.y), |
829 | 820 | }), | |
830 | menu.append(inspect); | 821 | ); |
831 | return menu; | ||
832 | } | 822 | } |
833 | 823 | ||
834 | /** | 824 | /** |
@@ -846,7 +836,7 @@ export class ContextMenuBuilder { | |||
846 | (arg0: string): void; | 836 | (arg0: string): void; |
847 | }, | 837 | }, |
848 | outputFormat: string = 'image/png', | 838 | outputFormat: string = 'image/png', |
849 | ) { | 839 | ): void { |
850 | let canvas: HTMLCanvasElement | null = document.createElement('canvas'); | 840 | let canvas: HTMLCanvasElement | null = document.createElement('canvas'); |
851 | const ctx = canvas.getContext('2d'); | 841 | const ctx = canvas.getContext('2d'); |
852 | const img = new Image(); | 842 | const img = new Image(); |
@@ -870,7 +860,7 @@ export class ContextMenuBuilder { | |||
870 | /** | 860 | /** |
871 | * Adds the 'go back' menu item | 861 | * Adds the 'go back' menu item |
872 | */ | 862 | */ |
873 | goBack(menu: Electron.CrossProcessExports.Menu) { | 863 | goBack(menu: Electron.CrossProcessExports.Menu): void { |
874 | const webContents = this.getWebContents(); | 864 | const webContents = this.getWebContents(); |
875 | 865 | ||
876 | menu.append( | 866 | menu.append( |
@@ -881,14 +871,12 @@ export class ContextMenuBuilder { | |||
881 | click: () => webContents.goBack(), | 871 | click: () => webContents.goBack(), |
882 | }), | 872 | }), |
883 | ); | 873 | ); |
884 | |||
885 | return menu; | ||
886 | } | 874 | } |
887 | 875 | ||
888 | /** | 876 | /** |
889 | * Adds the 'go forward' menu item | 877 | * Adds the 'go forward' menu item |
890 | */ | 878 | */ |
891 | goForward(menu: Electron.CrossProcessExports.Menu) { | 879 | goForward(menu: Electron.CrossProcessExports.Menu): void { |
892 | const webContents = this.getWebContents(); | 880 | const webContents = this.getWebContents(); |
893 | menu.append( | 881 | menu.append( |
894 | new MenuItem({ | 882 | new MenuItem({ |
@@ -898,8 +886,6 @@ export class ContextMenuBuilder { | |||
898 | click: () => webContents.goForward(), | 886 | click: () => webContents.goForward(), |
899 | }), | 887 | }), |
900 | ); | 888 | ); |
901 | |||
902 | return menu; | ||
903 | } | 889 | } |
904 | 890 | ||
905 | /** | 891 | /** |
@@ -908,7 +894,7 @@ export class ContextMenuBuilder { | |||
908 | copyPageUrl( | 894 | copyPageUrl( |
909 | menu: Electron.CrossProcessExports.Menu, | 895 | menu: Electron.CrossProcessExports.Menu, |
910 | menuInfo: IContextMenuParams, | 896 | menuInfo: IContextMenuParams, |
911 | ) { | 897 | ): void { |
912 | menu.append( | 898 | menu.append( |
913 | new MenuItem({ | 899 | new MenuItem({ |
914 | label: this.stringTable.copyPageUrl(), | 900 | label: this.stringTable.copyPageUrl(), |
@@ -922,8 +908,6 @@ export class ContextMenuBuilder { | |||
922 | }, | 908 | }, |
923 | }), | 909 | }), |
924 | ); | 910 | ); |
925 | |||
926 | return menu; | ||
927 | } | 911 | } |
928 | 912 | ||
929 | /** | 913 | /** |
@@ -932,7 +916,7 @@ export class ContextMenuBuilder { | |||
932 | goToHomePage( | 916 | goToHomePage( |
933 | menu: Electron.CrossProcessExports.Menu, | 917 | menu: Electron.CrossProcessExports.Menu, |
934 | menuInfo: IContextMenuParams, | 918 | menuInfo: IContextMenuParams, |
935 | ) { | 919 | ): void { |
936 | const baseURL = new window.URL(menuInfo.pageURL); | 920 | const baseURL = new window.URL(menuInfo.pageURL); |
937 | menu.append( | 921 | menu.append( |
938 | new MenuItem({ | 922 | new MenuItem({ |
@@ -945,8 +929,6 @@ export class ContextMenuBuilder { | |||
945 | }, | 929 | }, |
946 | }), | 930 | }), |
947 | ); | 931 | ); |
948 | |||
949 | return menu; | ||
950 | } | 932 | } |
951 | 933 | ||
952 | /** | 934 | /** |
@@ -955,7 +937,7 @@ export class ContextMenuBuilder { | |||
955 | openInBrowser( | 937 | openInBrowser( |
956 | menu: Electron.CrossProcessExports.Menu, | 938 | menu: Electron.CrossProcessExports.Menu, |
957 | menuInfo: IContextMenuParams, | 939 | menuInfo: IContextMenuParams, |
958 | ) { | 940 | ): void { |
959 | menu.append( | 941 | menu.append( |
960 | new MenuItem({ | 942 | new MenuItem({ |
961 | label: this.stringTable.openInBrowser(), | 943 | label: this.stringTable.openInBrowser(), |
@@ -965,8 +947,6 @@ export class ContextMenuBuilder { | |||
965 | }, | 947 | }, |
966 | }), | 948 | }), |
967 | ); | 949 | ); |
968 | |||
969 | return menu; | ||
970 | } | 950 | } |
971 | 951 | ||
972 | /** | 952 | /** |
@@ -975,7 +955,7 @@ export class ContextMenuBuilder { | |||
975 | openInFerdium( | 955 | openInFerdium( |
976 | menu: Electron.CrossProcessExports.Menu, | 956 | menu: Electron.CrossProcessExports.Menu, |
977 | menuInfo: IContextMenuParams, | 957 | menuInfo: IContextMenuParams, |
978 | ) { | 958 | ): void { |
979 | menu.append( | 959 | menu.append( |
980 | new MenuItem({ | 960 | new MenuItem({ |
981 | label: this.stringTable.openInFerdium(), | 961 | label: this.stringTable.openInFerdium(), |
@@ -985,14 +965,12 @@ export class ContextMenuBuilder { | |||
985 | }, | 965 | }, |
986 | }), | 966 | }), |
987 | ); | 967 | ); |
988 | |||
989 | return menu; | ||
990 | } | 968 | } |
991 | 969 | ||
992 | _sendNotificationOnClipboardEvent( | 970 | _sendNotificationOnClipboardEvent( |
993 | isDisabled: boolean, | 971 | isDisabled: boolean, |
994 | notificationText: () => string, | 972 | notificationText: () => string, |
995 | ) { | 973 | ): void { |
996 | if (isDisabled) { | 974 | if (isDisabled) { |
997 | return; | 975 | return; |
998 | } | 976 | } |