From 65cea57b6195f998ccb0f664e7cdbd90ce298013 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Sun, 23 Jun 2024 22:21:14 +0530 Subject: Minor refactoring to not return menu where not needed --- src/helpers/userAgent-helpers.ts | 4 +-- src/index.ts | 6 ++-- src/webview/contextMenuBuilder.ts | 66 +++++++++++++-------------------------- 3 files changed, 26 insertions(+), 50 deletions(-) (limited to 'src') 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() { // eslint-disable-next-line prefer-destructuring cpuName = cpuName.split('(')[0]; } - return `Macintosh; ${cpuName} Mac OS X ${version.replaceAll('.', '_')}`; + return `Macintosh; ${cpuName} macOS ${version.replaceAll('.', '_')}`; } function windows() { @@ -33,7 +33,7 @@ function linux() { } export default function userAgent() { - let platformString = ''; + let platformString; if (isMac) { 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) => { // Quit when all windows are closed. app.on('window-all-closed', () => { - // On OS X it is common for applications and their menu bar - // to stay active until the user quits explicitly with Cmd + Q + // On macos it is common for applications and their menu bar to stay active until the user quits explicitly with Cmd + Q if ( retrieveSettingValue( 'runInBackground', @@ -746,8 +745,7 @@ app.on('before-quit', event => { }); app.on('activate', () => { - // On OS X it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. + // 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. if (mainWindow === null) { createWindow(); } 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 { addImageItems( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { const copyImage = new MenuItem({ label: this.stringTable.copyImage(), click: () => { @@ -718,8 +718,6 @@ export class ContextMenuBuilder { menu.append(downloadImage); } - - return menu; } /** @@ -728,7 +726,7 @@ export class ContextMenuBuilder { addCut( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { const webContents = this.getWebContents(); menu.append( new MenuItem({ @@ -738,8 +736,6 @@ export class ContextMenuBuilder { click: () => webContents.cut(), }), ); - - return menu; } /** @@ -748,7 +744,7 @@ export class ContextMenuBuilder { addCopy( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { const webContents = this.getWebContents(); menu.append( new MenuItem({ @@ -758,8 +754,6 @@ export class ContextMenuBuilder { click: () => webContents.copy(), }), ); - - return menu; } /** @@ -768,7 +762,7 @@ export class ContextMenuBuilder { addPaste( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { const webContents = this.getWebContents(); menu.append( new MenuItem({ @@ -778,14 +772,12 @@ export class ContextMenuBuilder { click: () => webContents.paste(), }), ); - - return menu; } addPastePlain( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { if ( menuInfo.editFlags.canPaste && !menuInfo.linkText && @@ -805,9 +797,8 @@ export class ContextMenuBuilder { /** * Adds a separator item. */ - addSeparator(menu: Electron.CrossProcessExports.Menu) { + addSeparator(menu: Electron.CrossProcessExports.Menu): void { menu.append(new MenuItem({ type: 'separator' })); - return menu; } /** @@ -817,18 +808,17 @@ export class ContextMenuBuilder { menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, needsSeparator = true, - ) { + ): void { const webContents = this.getWebContents(); - if (!this.debugMode) return menu; + if (!this.debugMode) return; if (needsSeparator) this.addSeparator(menu); - const inspect = new MenuItem({ - label: this.stringTable.inspectElement(), - click: () => webContents.inspectElement(menuInfo.x, menuInfo.y), - }); - - menu.append(inspect); - return menu; + menu.append( + new MenuItem({ + label: this.stringTable.inspectElement(), + click: () => webContents.inspectElement(menuInfo.x, menuInfo.y), + }), + ); } /** @@ -846,7 +836,7 @@ export class ContextMenuBuilder { (arg0: string): void; }, outputFormat: string = 'image/png', - ) { + ): void { let canvas: HTMLCanvasElement | null = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const img = new Image(); @@ -870,7 +860,7 @@ export class ContextMenuBuilder { /** * Adds the 'go back' menu item */ - goBack(menu: Electron.CrossProcessExports.Menu) { + goBack(menu: Electron.CrossProcessExports.Menu): void { const webContents = this.getWebContents(); menu.append( @@ -881,14 +871,12 @@ export class ContextMenuBuilder { click: () => webContents.goBack(), }), ); - - return menu; } /** * Adds the 'go forward' menu item */ - goForward(menu: Electron.CrossProcessExports.Menu) { + goForward(menu: Electron.CrossProcessExports.Menu): void { const webContents = this.getWebContents(); menu.append( new MenuItem({ @@ -898,8 +886,6 @@ export class ContextMenuBuilder { click: () => webContents.goForward(), }), ); - - return menu; } /** @@ -908,7 +894,7 @@ export class ContextMenuBuilder { copyPageUrl( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { menu.append( new MenuItem({ label: this.stringTable.copyPageUrl(), @@ -922,8 +908,6 @@ export class ContextMenuBuilder { }, }), ); - - return menu; } /** @@ -932,7 +916,7 @@ export class ContextMenuBuilder { goToHomePage( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { const baseURL = new window.URL(menuInfo.pageURL); menu.append( new MenuItem({ @@ -945,8 +929,6 @@ export class ContextMenuBuilder { }, }), ); - - return menu; } /** @@ -955,7 +937,7 @@ export class ContextMenuBuilder { openInBrowser( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { menu.append( new MenuItem({ label: this.stringTable.openInBrowser(), @@ -965,8 +947,6 @@ export class ContextMenuBuilder { }, }), ); - - return menu; } /** @@ -975,7 +955,7 @@ export class ContextMenuBuilder { openInFerdium( menu: Electron.CrossProcessExports.Menu, menuInfo: IContextMenuParams, - ) { + ): void { menu.append( new MenuItem({ label: this.stringTable.openInFerdium(), @@ -985,14 +965,12 @@ export class ContextMenuBuilder { }, }), ); - - return menu; } _sendNotificationOnClipboardEvent( isDisabled: boolean, notificationText: () => string, - ) { + ): void { if (isDisabled) { return; } -- cgit v1.2.3-54-g00ecf