Skip to content

A local-first personal finance app

:electron: Hide the Electron menu (#5847)

Michael Clark7a886810bc69
diff --git a/package.json b/package.json
index a919f04e57..73266e933c 100644
--- a/package.json
+++ b/package.json
@@ -45,7 +45,7 @@
"playwright": "yarn workspace @actual-app/web run playwright",
"vrt": "yarn workspaces foreach --all --parallel --verbose run vrt",
"vrt:docker": "./bin/run-vrt",
- "rebuild-electron": "./node_modules/.bin/electron-rebuild -f -m ./packages/loot-core",
+ "rebuild-electron": "./node_modules/.bin/electron-rebuild -m ./packages/loot-core",
"rebuild-node": "yarn workspace loot-core rebuild",
"lint": "prettier --check . && eslint . --max-warnings 0",
"lint:fix": "prettier --check --write . && eslint . --max-warnings 0 --fix",
diff --git a/packages/desktop-client/src/browser-preload.browser.js b/packages/desktop-client/src/browser-preload.browser.js
index 31e828fdf6..cf1aadcc6d 100644
--- a/packages/desktop-client/src/browser-preload.browser.js
+++ b/packages/desktop-client/src/browser-preload.browser.js
@@ -178,7 +178,6 @@ global.Actual = {
// Wait for the app to reload
await new Promise(() => {});
},
- updateAppMenu: () => {},
ipcConnect: () => {},
getServerSocket: async () => {
@@ -191,35 +190,3 @@ global.Actual = {
moveBudgetDirectory: () => {},
};
-
-function inputFocused(e) {
- return (
- e.target.tagName === 'INPUT' ||
- e.target.tagName === 'TEXTAREA' ||
- e.target.isContentEditable
- );
-}
-
-document.addEventListener('keydown', e => {
- if (e.metaKey || e.ctrlKey) {
- // Cmd/Ctrl+o
- if (e.key === 'o') {
- e.preventDefault();
- window.__actionsForMenu.closeBudget();
- }
- // Cmd/Ctrl+z
- else if (e.key.toLowerCase() === 'z') {
- if (inputFocused(e)) {
- return;
- }
- e.preventDefault();
- if (e.shiftKey) {
- // Redo
- window.__actionsForMenu.redo();
- } else {
- // Undo
- window.__actionsForMenu.undo();
- }
- }
- }
-});
diff --git a/packages/desktop-client/src/components/App.tsx b/packages/desktop-client/src/components/App.tsx
index be885168d0..64e9947a2b 100644
--- a/packages/desktop-client/src/components/App.tsx
+++ b/packages/desktop-client/src/components/App.tsx
@@ -135,10 +135,6 @@ function AppInner() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dispatch, showErrorBoundary]);
- useEffect(() => {
- global.Actual.updateAppMenu(budgetId);
- }, [budgetId]);
-
useEffect(() => {
if (userData?.tokenExpired) {
dispatch(
diff --git a/packages/desktop-client/src/components/Titlebar.tsx b/packages/desktop-client/src/components/Titlebar.tsx
index cb64f2e084..623d2273c7 100644
--- a/packages/desktop-client/src/components/Titlebar.tsx
+++ b/packages/desktop-client/src/components/Titlebar.tsx
@@ -20,10 +20,7 @@ import { View } from '@actual-app/components/view';
import { css } from '@emotion/css';
import { listen } from 'loot-core/platform/client/fetch';
-import {
- isDevelopmentEnvironment,
- isElectron,
-} from 'loot-core/shared/environment';
+import { isDevelopmentEnvironment } from 'loot-core/shared/environment';
import * as Platform from 'loot-core/shared/platform';
import { AccountSyncCheck } from './accounts/AccountSyncCheck';
@@ -352,7 +349,7 @@ export function Titlebar({ style }: TitlebarProps) {
<PrivacyButton />
{serverURL ? <SyncButton /> : null}
<LoggedInUser />
- {!isElectron() && <HelpMenu />}
+ <HelpMenu />
</SpaceBetween>
</View>
);
diff --git a/packages/desktop-client/src/components/sidebar/BudgetName.tsx b/packages/desktop-client/src/components/sidebar/BudgetName.tsx
index c02c28681e..f79f3009d6 100644
--- a/packages/desktop-client/src/components/sidebar/BudgetName.tsx
+++ b/packages/desktop-client/src/components/sidebar/BudgetName.tsx
@@ -11,12 +11,14 @@ import { Text } from '@actual-app/components/text';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
+import { isElectron } from 'loot-core/shared/environment';
import * as Platform from 'loot-core/shared/platform';
import { closeBudget } from '@desktop-client/budgetfiles/budgetfilesSlice';
import { useContextMenu } from '@desktop-client/hooks/useContextMenu';
import { useMetadataPref } from '@desktop-client/hooks/useMetadataPref';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
+import { pushModal } from '@desktop-client/modals/modalsSlice';
import { useDispatch } from '@desktop-client/redux';
type BudgetNameProps = {
@@ -73,6 +75,15 @@ function EditableBudgetName() {
case 'settings':
navigate('/settings');
break;
+ case 'loadBackup':
+ if (isElectron()) {
+ dispatch(
+ pushModal({
+ modal: { name: 'load-backup', options: {} },
+ }),
+ );
+ }
+ break;
case 'close':
dispatch(closeBudget());
break;
@@ -83,8 +94,9 @@ function EditableBudgetName() {
const items = [
{ name: 'rename', text: t('Rename budget') },
{ name: 'settings', text: t('Settings') },
+ isElectron() ? { name: 'loadBackup', text: t('Load Backup…') } : null,
{ name: 'close', text: t('Switch file') },
- ];
+ ].filter(item => item !== null);
if (editing) {
return (
diff --git a/packages/desktop-client/src/index.tsx b/packages/desktop-client/src/index.tsx
index c08c0f7876..f6a1cf9f6d 100644
--- a/packages/desktop-client/src/index.tsx
+++ b/packages/desktop-client/src/index.tsx
@@ -62,11 +62,12 @@ async function uploadFile(filename: string, contents: ArrayBuffer) {
});
}
-function inputFocused() {
+function inputFocused(e: KeyboardEvent) {
+ const target = e.target as HTMLElement | null;
return (
- window.document.activeElement.tagName === 'INPUT' ||
- window.document.activeElement.tagName === 'TEXTAREA' ||
- (window.document.activeElement as HTMLElement).isContentEditable
+ target?.tagName === 'INPUT' ||
+ target?.tagName === 'TEXTAREA' ||
+ target?.isContentEditable === true
);
}
@@ -76,7 +77,6 @@ window.__actionsForMenu = {
undo,
redo,
appFocused,
- inputFocused,
uploadFile,
};
@@ -104,7 +104,6 @@ declare global {
undo: typeof undo;
redo: typeof redo;
appFocused: typeof appFocused;
- inputFocused: typeof inputFocused;
uploadFile: typeof uploadFile;
};
@@ -113,3 +112,27 @@ declare global {
$q: typeof q;
}
}
+
+document.addEventListener('keydown', e => {
+ if (e.metaKey || e.ctrlKey) {
+ // Cmd/Ctrl+o
+ if (e.key === 'o') {
+ e.preventDefault();
+ window.__actionsForMenu.closeBudget();
+ }
+ // Cmd/Ctrl+z
+ else if (e.key.toLowerCase() === 'z') {
+ if (inputFocused(e)) {
+ return;
+ }
+ e.preventDefault();
+ if (e.shiftKey) {
+ // Redo
+ window.__actionsForMenu.redo();
+ } else {
+ // Undo
+ window.__actionsForMenu.undo();
+ }
+ }
+ }
+});
diff --git a/packages/desktop-electron/e2e/__screenshots__/onboarding.test.ts/Onboarding-checks-the-page-visuals-1-linux.png b/packages/desktop-electron/e2e/__screenshots__/onboarding.test.ts/Onboarding-checks-the-page-visuals-1-linux.png
index 53632abffc..8867f84e5d 100644
Binary files a/packages/desktop-electron/e2e/__screenshots__/onboarding.test.ts/Onboarding-checks-the-page-visuals-1-linux.png and b/packages/desktop-electron/e2e/__screenshots__/onboarding.test.ts/Onboarding-checks-the-page-visuals-1-linux.png differ
diff --git a/packages/desktop-electron/e2e/__screenshots__/onboarding.test.ts/Onboarding-checks-the-page-visuals-2-linux.png b/packages/desktop-electron/e2e/__screenshots__/onboarding.test.ts/Onboarding-checks-the-page-visuals-2-linux.png
index be88ddd16b..a47989fd0e 100644
Binary files a/packages/desktop-electron/e2e/__screenshots__/onboarding.test.ts/Onboarding-checks-the-page-visuals-2-linux.png and b/packages/desktop-electron/e2e/__screenshots__/onboarding.test.ts/Onboarding-checks-the-page-visuals-2-linux.png differ
diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts
index bf80202bd1..eec9555867 100644
--- a/packages/desktop-electron/index.ts
+++ b/packages/desktop-electron/index.ts
@@ -346,6 +346,7 @@ async function createWindow() {
contextIsolation: true,
preload: __dirname + '/preload.js',
},
+ autoHideMenuBar: true, // Alt key shows the menu
});
win.setBackgroundColor('#E8ECF0');
@@ -368,7 +369,6 @@ async function createWindow() {
win.on('closed', () => {
clientWin = null;
- updateMenu();
unlistenToState();
});
@@ -409,12 +409,7 @@ async function createWindow() {
}
});
- if (process.platform === 'win32') {
- Menu.setApplicationMenu(null);
- win.setMenu(getMenu(isDev, createWindow));
- } else {
- Menu.setApplicationMenu(getMenu(isDev, createWindow));
- }
+ Menu.setApplicationMenu(getMenu());
clientWin = win;
@@ -430,37 +425,6 @@ function isExternalUrl(url: string) {
return !url.includes('localhost:') && !url.includes('app://');
}
-function updateMenu(budgetId?: string) {
- const isBudgetOpen = !!budgetId;
- const menu = getMenu(isDev, createWindow, budgetId);
- const file = menu.items.filter(item => item.label === 'File')[0];
- const fileItems = file.submenu?.items || [];
- fileItems
- .filter(item => item.label === 'Load Backup...')
- .forEach(item => {
- item.enabled = isBudgetOpen;
- });
-
- const tools = menu.items.filter(item => item.label === 'Tools')[0];
- tools.submenu?.items.forEach(item => {
- item.enabled = isBudgetOpen;
- });
-
- const edit = menu.items.filter(item => item.label === 'Edit')[0];
- const editItems = edit.submenu?.items || [];
- editItems
- .filter(item => item.label === 'Undo' || item.label === 'Redo')
- .map(item => (item.enabled = isBudgetOpen));
-
- if (process.platform === 'win32') {
- if (clientWin) {
- clientWin.setMenu(menu);
- }
- } else {
- Menu.setApplicationMenu(menu);
- }
-}
-
app.setAppUserModelId('com.actualbudget.actual');
app.on('ready', async () => {
@@ -651,21 +615,6 @@ ipcMain.on('message', (_event, msg) => {
serverProcess.postMessage(msg.args);
});
-ipcMain.on('screenshot', () => {
- if (isDev) {
- const width = 1100;
-
- // This is for the main screenshot inside the frame
- if (clientWin) {
- clientWin.setSize(width, Math.floor(width * (427 / 623)));
- }
- }
-});
-
-ipcMain.on('update-menu', (_event, budgetId?: string) => {
- updateMenu(budgetId);
-});
-
ipcMain.on('set-theme', (_event, theme: string) => {
const obj = { theme };
if (clientWin) {
diff --git a/packages/desktop-electron/menu.ts b/packages/desktop-electron/menu.ts
index bd7bee524d..2568b086da 100644
--- a/packages/desktop-electron/menu.ts
+++ b/packages/desktop-electron/menu.ts
@@ -1,110 +1,19 @@
-import {
- MenuItemConstructorOptions,
- Menu,
- ipcMain,
- app,
- BrowserWindow,
-} from 'electron';
+import { MenuItemConstructorOptions, Menu, BrowserWindow } from 'electron';
-export function getMenu(
- isDev: boolean,
- createWindow: () => Promise<void>,
- budgetId: string | undefined = undefined,
-) {
+export function getMenu() {
const template: MenuItemConstructorOptions[] = [
{
- label: 'File',
+ label: 'File', // Kept purely for the keyboard shortcuts in Electron. Some shortcuts only work if they are in a menu (toggle devtools cannot be triggered in pure js).
submenu: [
{
- label: 'Load Backup...',
- enabled: false,
- click(_item, focusedWindow) {
- if (focusedWindow && budgetId) {
- const browserWindow = focusedWindow as BrowserWindow;
- if (browserWindow.webContents.getTitle() === 'Actual') {
- browserWindow.webContents.executeJavaScript(
- `__actionsForMenu.replaceModal({ modal: { name: 'load-backup', options: { budgetId: '${budgetId}' } } })`,
- );
- }
- }
- },
- },
- {
- type: 'separator',
- },
- {
- label: 'Manage files...',
- accelerator: 'CmdOrCtrl+O',
+ label: 'Exit',
click(_item, focusedWindow) {
if (focusedWindow) {
const browserWindow = focusedWindow as BrowserWindow;
- if (browserWindow.webContents.getTitle() === 'Actual') {
- browserWindow.webContents.executeJavaScript(
- '__actionsForMenu.closeBudget()',
- );
- } else {
- focusedWindow.close();
- }
- } else {
- // The default page is the budget list
- createWindow();
- }
- },
- },
- ],
- },
- {
- label: 'Edit',
- submenu: [
- {
- label: 'Undo',
- enabled: false,
- accelerator: 'CmdOrCtrl+Z',
- click: function (_menuItem, focusedWin) {
- // Undo
- if (focusedWin) {
- const browserWindow = focusedWin as BrowserWindow;
- browserWindow.webContents.executeJavaScript(
- '__actionsForMenu.undo()',
- );
- }
- },
- },
- {
- label: 'Redo',
- enabled: false,
- accelerator: 'Shift+CmdOrCtrl+Z',
- click: function (_menuItem, focusedWin) {
- // Redo
- if (focusedWin) {
- const browserWindow = focusedWin as BrowserWindow;
- browserWindow.webContents.executeJavaScript(
- '__actionsForMenu.redo()',
- );
+ browserWindow.close();
}
},
},
- {
- type: 'separator',
- },
- {
- role: 'cut',
- },
- {
- role: 'copy',
- },
- {
- role: 'paste',
- },
- {
- role: 'pasteAndMatchStyle',
- },
- {
- role: 'delete',
- },
- {
- role: 'selectAll',
- },
],
},
{
@@ -131,11 +40,9 @@ export function getMenu(
}
},
},
- isDev
- ? {
- type: 'separator',
- }
- : { label: 'hidden', visible: false },
+ {
+ type: 'separator',
+ },
{
role: 'resetZoom',
},
@@ -153,157 +60,7 @@ export function getMenu(
},
],
},
- {
- label: 'Tools',
- submenu: [
- {
- label: 'Find schedules',
- enabled: false,
- click: function (_menuItem, focusedWin) {
- if (focusedWin) {
- const browserWindow = focusedWin as BrowserWindow;
- browserWindow.webContents.executeJavaScript(
- 'window.__actionsForMenu && window.__actionsForMenu.pushModal({ modal: { name: "schedules-discover" } })',
- );
- }
- },
- },
- ],
- },
- {
- role: 'window',
- submenu: [
- {
- role: 'minimize',
- },
- ],
- },
- {
- role: 'help',
- submenu: [
- {
- label: 'Documentation',
- click(_menuItem, focusedWin) {
- if (focusedWin) {
- const browserWindow = focusedWin as BrowserWindow;
- browserWindow.webContents.executeJavaScript(
- 'window.open("https://actualbudget.org/docs", "_blank")',
- );
- }
- },
- },
- {
- label: 'Community Support (Discord)',
- click(_menuItem, focusedWin) {
- if (focusedWin) {
- const browserWindow = focusedWin as BrowserWindow;
- browserWindow.webContents.executeJavaScript(
- 'window.open("https://discord.gg/pRYNYr4W5A", "_blank")',
- );
- }
- },
- },
- {
- label: 'Keyboard Shortcuts',
- accelerator: '?',
- enabled: !!budgetId,
- click: function (_menuItem, focusedWin) {
- if (focusedWin) {
- const browserWindow = focusedWin as BrowserWindow;
- browserWindow.webContents.executeJavaScript(
- 'window.__actionsForMenu && !window.__actionsForMenu.inputFocused() && window.__actionsForMenu.pushModal({ modal: { name: "keyboard-shortcuts" } })',
- );
- }
- },
- },
- ],
- },
];
- if (process.platform === 'darwin') {
- const name = app.getName();
- template.unshift({
- label: name,
- submenu: [
- isDev
- ? {
- label: 'Screenshot',
- click() {
- ipcMain.emit('screenshot');
- },
- }
- : { label: 'hidden', visible: false },
- {
- type: 'separator',
- },
- {
- role: 'services',
- submenu: [],
- },
- {
- type: 'separator',
- },
- {
- role: 'hide',
- },
- {
- role: 'hideOthers',
- },
- {
- role: 'unhide',
- },
- {
- type: 'separator',
- },
- {
- role: 'quit',
- },
- ],
- });
- // Edit menu.
- const editIdx = template.findIndex(t => t.label === 'Edit');
- (template[editIdx].submenu as MenuItemConstructorOptions[]).push(
- {
- type: 'separator',
- },
- {
- label: 'Speech',
- submenu: [
- {
- role: 'startSpeaking',
- },
- {
- role: 'stopSpeaking',
- },
- ],
- },
- );
- // Window menu.
- const windowIdx = template.findIndex(t => t.role === 'window');
- template[windowIdx].submenu = [
- {
- label: 'Close',
- accelerator: 'CmdOrCtrl+W',
- role: 'close',
- },
- {
- label: 'Minimize',
- accelerator: 'CmdOrCtrl+M',
- role: 'minimize',
- },
- {
- label: 'Zoom',
- role: 'zoom',
- },
- {
- type: 'separator',
- },
- {
- label: 'Bring All to Front',
- role: 'front',
- },
- ];
- }
-
return Menu.buildFromTemplate(template);
}
diff --git a/packages/desktop-electron/preload.ts b/packages/desktop-electron/preload.ts
index 2381b6cad2..d2de5078b9 100644
--- a/packages/desktop-electron/preload.ts
+++ b/packages/desktop-electron/preload.ts
@@ -69,10 +69,6 @@ contextBridge.exposeInMainWorld('Actual', {
ipcRenderer.on(type, handler);
},
- updateAppMenu: (budgetId?: string) => {
- ipcRenderer.send('update-menu', budgetId);
- },
-
// No auto-updates in the desktop app
isUpdateReadyForDownload: () => false,
waitForUpdateReadyForDownload: () => new Promise<void>(() => {}),
diff --git a/packages/loot-core/typings/window.ts b/packages/loot-core/typings/window.ts
index cd08d2ccc3..e057dfce02 100644
--- a/packages/loot-core/typings/window.ts
+++ b/packages/loot-core/typings/window.ts
@@ -27,7 +27,6 @@ type Actual = {
newDirectory: string,
) => Promise<void>;
applyAppUpdate: () => Promise<void>;
- updateAppMenu: (budgetId: string) => void;
ipcConnect: (callback: (client) => void) => void;
getServerSocket: () => Promise<Worker | null>;
setTheme: (theme: string) => void;
diff --git a/upcoming-release-notes/5847.md b/upcoming-release-notes/5847.md
new file mode 100644
index 0000000000..eb93946709
--- /dev/null
+++ b/upcoming-release-notes/5847.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [MikesGlitch]
+---
+
+Hide desktop app menu by default & move menu items to app for consistency with Web.