From 152a4fe1dcd1805dfaa4eb1cdcbc4baf498f00dd Mon Sep 17 00:00:00 2001 From: Julian Dominguez-Schatz Date: Sun, 20 Oct 2024 21:05:55 -0400 Subject: [PATCH] Try 2 to fix IPC --- .../src/components/HelpMenu.tsx | 7 ++--- packages/desktop-client/src/util/help.ts | 19 ------------- .../desktop-client/src/util/router-tools.ts | 4 --- packages/desktop-electron/menu.ts | 16 +++-------- packages/loot-core/src/client/actions/app.ts | 27 ++++++++++++++++++- 5 files changed, 32 insertions(+), 41 deletions(-) delete mode 100644 packages/desktop-client/src/util/help.ts diff --git a/packages/desktop-client/src/components/HelpMenu.tsx b/packages/desktop-client/src/components/HelpMenu.tsx index b508d39d8d6..b4b92b85208 100644 --- a/packages/desktop-client/src/components/HelpMenu.tsx +++ b/packages/desktop-client/src/components/HelpMenu.tsx @@ -2,15 +2,13 @@ import { forwardRef, useRef } from 'react'; import { useHotkeys } from 'react-hotkeys-hook'; import { Trans, useTranslation } from 'react-i18next'; import { useDispatch } from 'react-redux'; -import { useLocation } from 'react-router-dom'; import { useToggle } from 'usehooks-ts'; +import { openDocsForCurrentPage } from 'loot-core/client/actions'; import { pushModal } from 'loot-core/client/actions/modals'; import { SvgHelp } from '../icons/v2/Help'; -import { getPageDocs } from '../util/help'; -import { openUrl } from '../util/router-tools'; import { Button } from './common/Button2'; import { Menu } from './common/Menu'; @@ -52,12 +50,11 @@ export const HelpMenu = () => { const menuButtonRef = useRef(null); const dispatch = useDispatch(); - const page = useLocation().pathname; const handleItemSelect = (item: HelpMenuItem) => { switch (item) { case 'docs': - openUrl(getPageDocs(page)); + dispatch(openDocsForCurrentPage()); break; case 'keyboard-shortcuts': dispatch(pushModal('keyboard-shortcuts')); diff --git a/packages/desktop-client/src/util/help.ts b/packages/desktop-client/src/util/help.ts deleted file mode 100644 index 0f11daf9159..00000000000 --- a/packages/desktop-client/src/util/help.ts +++ /dev/null @@ -1,19 +0,0 @@ -export const getPageDocs = (page: string) => { - switch (page) { - case '/budget': - return 'https://actualbudget.org/docs/getting-started/envelope-budgeting'; - case '/reports': - return 'https://actualbudget.org/docs/reports/'; - case '/schedules': - return 'https://actualbudget.org/docs/schedules'; - case '/payees': - return 'https://actualbudget.org/docs/transactions/payees'; - case '/rules': - return 'https://actualbudget.org/docs/budgeting/rules'; - case '/settings': - return 'https://actualbudget.org/docs/settings'; - default: - // All pages under /accounts, plus any missing pages - return 'https://actualbudget.org/docs'; - } -}; diff --git a/packages/desktop-client/src/util/router-tools.ts b/packages/desktop-client/src/util/router-tools.ts index b47386270e9..1bba51ee678 100644 --- a/packages/desktop-client/src/util/router-tools.ts +++ b/packages/desktop-client/src/util/router-tools.ts @@ -9,7 +9,3 @@ export function ExposeNavigate() { }, [navigate]); return null; } - -export function openUrl(url: string) { - window.open(url, '_blank', 'noopener,noreferrer'); -} diff --git a/packages/desktop-electron/menu.ts b/packages/desktop-electron/menu.ts index f9c57d18b5c..5897cd22d0b 100644 --- a/packages/desktop-electron/menu.ts +++ b/packages/desktop-electron/menu.ts @@ -1,11 +1,4 @@ -import { getPageDocs } from '@actual-app/web/src/util/help'; -import { - MenuItemConstructorOptions, - Menu, - ipcMain, - app, - shell, -} from 'electron'; +import { MenuItemConstructorOptions, Menu, ipcMain, app } from 'electron'; export function getMenu( isDev: boolean, @@ -175,11 +168,10 @@ export function getMenu( submenu: [ { label: 'Documentation', - async click(_menuItem, focusedWin) { - const page = await focusedWin?.webContents.executeJavaScript( - 'window.location.pathname', + click(_menuItem, focusedWin) { + focusedWin?.webContents.executeJavaScript( + 'window.__actionsForMenu && window.__actionsForMenu.openDocsForCurrentPage()', ); - shell.openExternal(getPageDocs(page)); }, }, { diff --git a/packages/loot-core/src/client/actions/app.ts b/packages/loot-core/src/client/actions/app.ts index e586f55dc69..4ef91c470b9 100644 --- a/packages/loot-core/src/client/actions/app.ts +++ b/packages/loot-core/src/client/actions/app.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { send } from '../../platform/client/fetch'; import * as constants from '../constants'; import type { @@ -52,3 +51,29 @@ export function reloadApp() { global.Actual.reload(); }; } + +const getPageDocs = (page: string) => { + switch (page) { + case '/budget': + return 'https://actualbudget.org/docs/getting-started/envelope-budgeting'; + case '/reports': + return 'https://actualbudget.org/docs/reports/'; + case '/schedules': + return 'https://actualbudget.org/docs/schedules'; + case '/payees': + return 'https://actualbudget.org/docs/transactions/payees'; + case '/rules': + return 'https://actualbudget.org/docs/budgeting/rules'; + case '/settings': + return 'https://actualbudget.org/docs/settings'; + default: + // All pages under /accounts, plus any missing pages + return 'https://actualbudget.org/docs'; + } +}; + +export function openDocsForCurrentPage() { + return () => { + global.Actual.openURLInBrowser(getPageDocs(window.location.pathname)); + }; +}