Skip to content

Commit

Permalink
format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
traviskuhl committed May 22, 2024
1 parent 33b7acc commit e155b8b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 112 deletions.
203 changes: 91 additions & 112 deletions apps/desktop/src/main/menu/menu.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,44 @@
import {
app,
Menu,
shell,
BrowserWindow,
MenuItemConstructorOptions,
} from 'electron';
import { app, Menu, shell, BrowserWindow, MenuItemConstructorOptions } from 'electron'

interface DarwinMenuItemConstructorOptions extends MenuItemConstructorOptions {
selector?: string;
submenu?: DarwinMenuItemConstructorOptions[] | Menu;
selector?: string
submenu?: DarwinMenuItemConstructorOptions[] | Menu
}

export default class MenuBuilder {
mainWindow: BrowserWindow;
mainWindow: BrowserWindow

constructor(mainWindow: BrowserWindow) {
this.mainWindow = mainWindow;
this.mainWindow = mainWindow
}

buildMenu(): Menu {
if (
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
) {
this.setupDevelopmentEnvironment();
if (process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true') {
this.setupDevelopmentEnvironment()
}

const template =
process.platform === 'darwin'
? this.buildDarwinTemplate()
: this.buildDefaultTemplate();
process.platform === 'darwin' ? this.buildDarwinTemplate() : this.buildDefaultTemplate()

const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)

return menu;
return menu
}

setupDevelopmentEnvironment(): void {
this.mainWindow.webContents.on('context-menu', (_, props) => {
const { x, y } = props;
const { x, y } = props

Menu.buildFromTemplate([
{
label: 'Inspect element',
click: () => {
this.mainWindow.webContents.inspectElement(x, y);
},
},
]).popup({ window: this.mainWindow });
});
this.mainWindow.webContents.inspectElement(x, y)
}
}
]).popup({ window: this.mainWindow })
})
}

buildDarwinTemplate(): MenuItemConstructorOptions[] {
Expand All @@ -58,32 +47,32 @@ export default class MenuBuilder {
submenu: [
{
label: 'About ElectronReact',
selector: 'orderFrontStandardAboutPanel:',
selector: 'orderFrontStandardAboutPanel:'
},
{ type: 'separator' },
{ label: 'Services', submenu: [] },
{ type: 'separator' },
{
label: 'Hide ElectronReact',
accelerator: 'Command+H',
selector: 'hide:',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:',
selector: 'hideOtherApplications:'
},
{ label: 'Show All', selector: 'unhideAllApplications:' },
{ type: 'separator' },
{
label: 'Quit',
accelerator: 'Command+Q',
click: () => {
app.quit();
},
},
],
};
app.quit()
}
}
]
}
const subMenuEdit: DarwinMenuItemConstructorOptions = {
label: 'Edit',
submenu: [
Expand All @@ -96,100 +85,97 @@ export default class MenuBuilder {
{
label: 'Select All',
accelerator: 'Command+A',
selector: 'selectAll:',
},
],
};
selector: 'selectAll:'
}
]
}
const subMenuViewDev: MenuItemConstructorOptions = {
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: () => {
this.mainWindow.webContents.reload();
},
this.mainWindow.webContents.reload()
}
},
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
},
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen())
}
},
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: () => {
this.mainWindow.webContents.toggleDevTools();
},
},
],
};
this.mainWindow.webContents.toggleDevTools()
}
}
]
}
const subMenuViewProd: MenuItemConstructorOptions = {
label: 'View',
submenu: [
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: () => {
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen());
},
},
],
};
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen())
}
}
]
}
const subMenuWindow: DarwinMenuItemConstructorOptions = {
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:',
selector: 'performMiniaturize:'
},
{ label: 'Close', accelerator: 'Command+W', selector: 'performClose:' },
{ type: 'separator' },
{ label: 'Bring All to Front', selector: 'arrangeInFront:' },
],
};
{ label: 'Bring All to Front', selector: 'arrangeInFront:' }
]
}
const subMenuHelp: MenuItemConstructorOptions = {
label: 'Help',
submenu: [
{
label: 'Learn More',
click() {
shell.openExternal('https://electronjs.org');
},
shell.openExternal('https://electronjs.org')
}
},
{
label: 'Documentation',
click() {
shell.openExternal(
'https://github.com/electron/electron/tree/main/docs#readme',
);
},
shell.openExternal('https://github.com/electron/electron/tree/main/docs#readme')
}
},
{
label: 'Community Discussions',
click() {
shell.openExternal('https://www.electronjs.org/community');
},
shell.openExternal('https://www.electronjs.org/community')
}
},
{
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/electron/electron/issues');
},
},
],
};
shell.openExternal('https://github.com/electron/electron/issues')
}
}
]
}

const subMenuView =
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'
? subMenuViewDev
: subMenuViewProd;
: subMenuViewProd

return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp]
}

buildDefaultTemplate() {
Expand All @@ -199,92 +185,85 @@ export default class MenuBuilder {
submenu: [
{
label: '&Open',
accelerator: 'Ctrl+O',
accelerator: 'Ctrl+O'
},
{
label: '&Close',
accelerator: 'Ctrl+W',
click: () => {
this.mainWindow.close();
},
},
],
this.mainWindow.close()
}
}
]
},
{
label: '&View',
submenu:
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true'
? [
{
label: '&Reload',
accelerator: 'Ctrl+R',
click: () => {
this.mainWindow.webContents.reload();
},
this.mainWindow.webContents.reload()
}
},
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen(),
);
},
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen())
}
},
{
label: 'Toggle &Developer Tools',
accelerator: 'Alt+Ctrl+I',
click: () => {
this.mainWindow.webContents.toggleDevTools();
},
},
this.mainWindow.webContents.toggleDevTools()
}
}
]
: [
{
label: 'Toggle &Full Screen',
accelerator: 'F11',
click: () => {
this.mainWindow.setFullScreen(
!this.mainWindow.isFullScreen(),
);
},
},
],
this.mainWindow.setFullScreen(!this.mainWindow.isFullScreen())
}
}
]
},
{
label: 'Help',
submenu: [
{
label: 'Learn More',
click() {
shell.openExternal('https://electronjs.org');
},
shell.openExternal('https://electronjs.org')
}
},
{
label: 'Documentation',
click() {
shell.openExternal(
'https://github.com/electron/electron/tree/main/docs#readme',
);
},
shell.openExternal('https://github.com/electron/electron/tree/main/docs#readme')
}
},
{
label: 'Community Discussions',
click() {
shell.openExternal('https://www.electronjs.org/community');
},
shell.openExternal('https://www.electronjs.org/community')
}
},
{
label: 'Search Issues',
click() {
shell.openExternal('https://github.com/electron/electron/issues');
},
},
],
},
];
shell.openExternal('https://github.com/electron/electron/issues')
}
}
]
}
]

return templateDefault;
return templateDefault
}
}
File renamed without changes.

0 comments on commit e155b8b

Please sign in to comment.