1 import { type BrowserWindow, Menu, type MenuItemConstructorOptions, app, shell } from 'electron';
2 import { c } from 'ttag';
4 import { PASS_APP_NAME } from '@proton/shared/lib/constants';
6 import { uninstallProton } from '../uninstallers/macos/uninstall';
7 import { isMac, isProdEnv } from '../utils/platform';
9 type MenuKey = 'app' | 'file' | 'edit' | 'view' | 'window';
10 type MenuProps = MenuItemConstructorOptions & { key: MenuKey };
12 type MenuInsertProps = {
15 otherOsEntries?: MenuItemConstructorOptions[];
16 macEntries?: MenuItemConstructorOptions[];
17 allOSEntries?: MenuItemConstructorOptions[];
20 const insertInMenu = ({ menu, key, otherOsEntries, macEntries, allOSEntries }: MenuInsertProps) => {
21 const editIndex = menu.findIndex((item) => item.key === key);
22 if (!editIndex) return;
24 const submenu = menu[editIndex].submenu as MenuItemConstructorOptions[];
25 if (isMac && macEntries) {
26 menu[editIndex].submenu = [...submenu, ...macEntries];
27 } else if (!isMac && otherOsEntries) {
28 menu[editIndex].submenu = [...submenu, ...otherOsEntries];
31 menu[editIndex].submenu = [...submenu, ...(allOSEntries ?? [])];
34 export const setApplicationMenu = (mainWindow: BrowserWindow) => {
35 const temp: MenuProps[] = [
37 label: c('Menu').t`File`,
41 label: c('App menu').t`Show logs`,
43 click: () => shell.openPath(app.getPath('logs')),
51 label: c('Menu').t`Edit`,
56 { type: 'separator' },
60 { role: 'pasteAndMatchStyle', accelerator: isMac ? 'Cmd+Shift+V' : 'Ctrl+Shift+V' },
61 { role: 'selectAll' },
65 label: c('Menu').t`View`,
69 label: c('App menu').t`Reload`,
70 accelerator: isMac ? 'Cmd+R' : 'Ctrl+R',
71 click: () => mainWindow.webContents.reload(),
74 label: c('App menu').t`Force Reload`,
75 accelerator: isMac ? 'Cmd+Shift+R' : 'Ctrl+Shift+R',
76 click: () => mainWindow.webContents.reloadIgnoringCache(),
78 { type: 'separator' },
79 { role: 'resetZoom' },
82 { type: 'separator' },
83 { role: 'togglefullscreen' },
87 label: c('Menu').t`Window`,
89 submenu: [{ role: 'minimize' }, { role: 'close' }, { role: 'zoom' }],
99 { type: 'separator' },
101 { role: 'hideOthers' },
103 { type: 'separator' },
105 label: c('App menu').t`Start ${PASS_APP_NAME} at login`,
107 checked: app.getLoginItemSettings().openAtLogin,
109 app.setLoginItemSettings({ openAtLogin: !app.getLoginItemSettings().openAtLogin });
113 label: c('App menu').t`Uninstall ${PASS_APP_NAME}`,
115 click: () => uninstallProton(),
117 { type: 'separator' },
123 const submenu = temp[0].submenu as MenuItemConstructorOptions[];
124 temp[0].submenu = [...submenu, { type: 'separator' }, { role: 'services' }];
131 otherOsEntries: [{ role: 'delete' }, { type: 'separator' }, { role: 'selectAll' }],
133 { role: 'pasteAndMatchStyle' },
135 { role: 'selectAll' },
136 { type: 'separator' },
138 label: c('App menu').t`Speech`,
139 submenu: [{ role: 'startSpeaking' }, { role: 'stopSpeaking' }],
144 if (!isProdEnv() || Boolean(process.env.PASS_DEBUG)) {
149 { type: 'separator' },
151 label: c('App menu').t`Toggle developers tools`,
152 accelerator: isMac ? 'Cmd+Alt+I' : 'Ctrl+Shift+I',
153 click: () => mainWindow.webContents.toggleDevTools(),
159 Menu.setApplicationMenu(Menu.buildFromTemplate(temp));