From ad733fe596861fe2f2b67d5a420835c0916fcb80 Mon Sep 17 00:00:00 2001 From: mukunda katta Date: Tue, 14 Apr 2026 23:11:32 -0700 Subject: [PATCH] fix(menubar): invoke binary directly + correct currency subcommand (#32, #27) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The two menubar action items were built as `bash -c "cd ~/codeburn && npx tsx src/cli.ts ..."`, which: 1. assumes a `~/codeburn` source checkout that npm-installed users don't have, and 2. interacts badly with how SwiftBar serialises `param2=` on long quoted strings — only the `cd` half ends up reaching `bash -c`, so the `npx tsx` fallback runs from `$HOME` and fails with `ERR_MODULE_NOT_FOUND: /Users//src/cli.ts`. Replace with the resolved `${bin}` plus separate `paramN=` args, which SwiftBar/xbar deliver as discrete argv entries — no shell quoting, no checkout assumption. While here, fix the currency submenu the same way: the items were emitting `${bin} config currency XXX`, but the real CLI subcommand defined in `src/cli.ts` is `codeburn currency [code]` (with `--reset` for USD). The previous form silently failed on click. That's #27. Closes #32 Closes #27 Verified by running `npm run build` (clean) + `npm test -- --run` (28/28 pass), and inspecting the rendered output of `codeburn status --format menubar` to confirm the action lines now look like: Open Full Report | terminal=true shell= param1=report Export CSV to Desktop | terminal=false shell= param1=export param2=-o param3=/Desktop/codeburn-report.csv --US Dollar (USD) * | terminal=false refresh=true shell= param1=currency param2=--reset --British Pound (GBP) | terminal=false refresh=true shell= param1=currency param2=GBP --- src/menubar.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/menubar.ts b/src/menubar.ts index 503939a..0e52f3c 100644 --- a/src/menubar.ts +++ b/src/menubar.ts @@ -151,8 +151,12 @@ export function renderMenubarFormat( lines.push('---') const home = process.env.HOME ?? '~' const bin = getCodeburnBin() - lines.push(`Open Full Report | terminal=true shell=/bin/bash param1=-c param2="cd '${home}/codeburn' && npx tsx src/cli.ts report; echo ''; echo 'Press any key to close...'; read -n1"`) - lines.push(`Export CSV to Desktop | terminal=false shell=/bin/bash param1=-c param2="cd '${home}/codeburn' && npx tsx src/cli.ts export -o '${home}/Desktop/codeburn-report.csv' 2>/dev/null"`) + // Invoke the resolved `codeburn` binary directly. SwiftBar/xbar deliver + // each `paramN=` value as its own argv entry, so there's no shell + // quoting involved — and we don't ship the user to a `~/codeburn` + // checkout that only exists when running from a dev clone (#32). + lines.push(`Open Full Report | terminal=true shell=${bin} param1=report`) + lines.push(`Export CSV to Desktop | terminal=false shell=${bin} param1=export param2=-o param3=${home}/Desktop/codeburn-report.csv`) // Currency submenu -- common currencies as clickable items. // Clicking one runs 'codeburn config currency XXX' and refreshes the plugin. @@ -179,10 +183,14 @@ export function renderMenubarFormat( lines.push(`Currency: ${activeCurrency} | size=14`) for (const { code, name } of currencies) { const check = code === activeCurrency ? ' *' : '' - const cmd = code === 'USD' - ? `${bin} config currency --reset` - : `${bin} config currency ${code}` - lines.push(`--${name} (${code})${check} | terminal=false refresh=true shell=/bin/bash param1=-c param2="${cmd}"`) + // The real CLI subcommand is `codeburn currency [code]` (with `--reset` + // for USD), not `codeburn config currency` — the latter doesn't exist + // and silently fails when SwiftBar runs it. Fixes #27. + if (code === 'USD') { + lines.push(`--${name} (${code})${check} | terminal=false refresh=true shell=${bin} param1=currency param2=--reset`) + } else { + lines.push(`--${name} (${code})${check} | terminal=false refresh=true shell=${bin} param1=currency param2=${code}`) + } } lines.push(`Refresh | refresh=true`)