Skip to content

Commit

Permalink
Minor refactoring to not return menu where not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
vraravam committed Jun 23, 2024
1 parent 46bf680 commit 65cea57
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/helpers/userAgent-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -33,7 +33,7 @@ function linux() {
}

export default function userAgent() {
let platformString = '';
let platformString;

if (isMac) {
platformString = macOS();
Expand Down
6 changes: 2 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand Down
66 changes: 22 additions & 44 deletions src/webview/contextMenuBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ export class ContextMenuBuilder {
addImageItems(
menu: Electron.CrossProcessExports.Menu,
menuInfo: IContextMenuParams,
) {
): void {
const copyImage = new MenuItem({
label: this.stringTable.copyImage(),
click: () => {
Expand Down Expand Up @@ -718,8 +718,6 @@ export class ContextMenuBuilder {

menu.append(downloadImage);
}

return menu;
}

/**
Expand All @@ -728,7 +726,7 @@ export class ContextMenuBuilder {
addCut(
menu: Electron.CrossProcessExports.Menu,
menuInfo: IContextMenuParams,
) {
): void {
const webContents = this.getWebContents();
menu.append(
new MenuItem({
Expand All @@ -738,8 +736,6 @@ export class ContextMenuBuilder {
click: () => webContents.cut(),
}),
);

return menu;
}

/**
Expand All @@ -748,7 +744,7 @@ export class ContextMenuBuilder {
addCopy(
menu: Electron.CrossProcessExports.Menu,
menuInfo: IContextMenuParams,
) {
): void {
const webContents = this.getWebContents();
menu.append(
new MenuItem({
Expand All @@ -758,8 +754,6 @@ export class ContextMenuBuilder {
click: () => webContents.copy(),
}),
);

return menu;
}

/**
Expand All @@ -768,7 +762,7 @@ export class ContextMenuBuilder {
addPaste(
menu: Electron.CrossProcessExports.Menu,
menuInfo: IContextMenuParams,
) {
): void {
const webContents = this.getWebContents();
menu.append(
new MenuItem({
Expand All @@ -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 &&
Expand All @@ -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;
}

/**
Expand All @@ -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),
}),
);
}

/**
Expand All @@ -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();
Expand All @@ -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(
Expand All @@ -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({
Expand All @@ -898,8 +886,6 @@ export class ContextMenuBuilder {
click: () => webContents.goForward(),
}),
);

return menu;
}

/**
Expand All @@ -908,7 +894,7 @@ export class ContextMenuBuilder {
copyPageUrl(
menu: Electron.CrossProcessExports.Menu,
menuInfo: IContextMenuParams,
) {
): void {
menu.append(
new MenuItem({
label: this.stringTable.copyPageUrl(),
Expand All @@ -922,8 +908,6 @@ export class ContextMenuBuilder {
},
}),
);

return menu;
}

/**
Expand All @@ -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({
Expand All @@ -945,8 +929,6 @@ export class ContextMenuBuilder {
},
}),
);

return menu;
}

/**
Expand All @@ -955,7 +937,7 @@ export class ContextMenuBuilder {
openInBrowser(
menu: Electron.CrossProcessExports.Menu,
menuInfo: IContextMenuParams,
) {
): void {
menu.append(
new MenuItem({
label: this.stringTable.openInBrowser(),
Expand All @@ -965,8 +947,6 @@ export class ContextMenuBuilder {
},
}),
);

return menu;
}

/**
Expand All @@ -975,7 +955,7 @@ export class ContextMenuBuilder {
openInFerdium(
menu: Electron.CrossProcessExports.Menu,
menuInfo: IContextMenuParams,
) {
): void {
menu.append(
new MenuItem({
label: this.stringTable.openInFerdium(),
Expand All @@ -985,14 +965,12 @@ export class ContextMenuBuilder {
},
}),
);

return menu;
}

_sendNotificationOnClipboardEvent(
isDisabled: boolean,
notificationText: () => string,
) {
): void {
if (isDisabled) {
return;
}
Expand Down

0 comments on commit 65cea57

Please sign in to comment.