fix(menubar): invoke binary directly + correct currency subcommand (#32, #27)

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/<u>/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=<bin> param1=report
  Export CSV to Desktop | terminal=false shell=<bin> param1=export param2=-o param3=<HOME>/Desktop/codeburn-report.csv
  --US Dollar (USD) * | terminal=false refresh=true shell=<bin> param1=currency param2=--reset
  --British Pound (GBP) | terminal=false refresh=true shell=<bin> param1=currency param2=GBP
This commit is contained in:
mukunda katta 2026-04-14 23:11:32 -07:00
parent bd8ae2e971
commit ad733fe596

View file

@ -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`)