mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 10:43:47 +00:00
Some checks are pending
Tests / desktop (push) Waiting to run
Tests / test (22) (push) Waiting to run
Tests / test (22.13.0) (push) Waiting to run
CI / semgrep (push) Waiting to run
Tests / test (24) (push) Waiting to run
Tests / test (26) (push) Waiting to run
Tests / test-platforms (macos-latest) (push) Waiting to run
Tests / test-platforms (windows-latest) (push) Waiting to run
* feat(windows): configure the menu bar and Capacity Dock as a Plugins card Windows now configures its tray companion from a card on the Plugins page, the same place macOS does, instead of two switches in the sidebar corner. - WindowsCompanionCard mirrors the macOS MenuBarCard: Install/Reinstall, Update, Open (show the tray popover), Settings (opens the desktop Menu bar settings pane), Quit (stop without uninstalling), Uninstall, plus the Capacity Dock toggle, a Running dot, the version, and an info popup. - MenubarCompanion.status() now reports installed/running/version/outdated/ canInstall, and new discrete install/open/quit/uninstall actions back the card. uninstall only forgets the tray once the CLI removal succeeds, and a cancelled elevation prompt is treated as a no-op rather than a failure. - isNewerVersion sorts a dev build below any release, so a staged release still lights Update and a dev build never does. - codeburn menubar --uninstall reads the product code from the install marker or the uninstall registry and runs msiexec /x. - Remove the bespoke sidebar CompanionSwitches and their dead CSS. - A dev-only CODEBURN_MENUBAR_RESOURCES override lets the tray install run without packaging; the CLI still validates the staged path in full. * feat(desktop): fold the Capacity Dock settings into the Menu bar pane One tray rail entry instead of two: MenuBarPane and CapacityDockPane render together in the Menu bar pane with a clear gap between the two cards, so the card's Settings button opens both. Drops the now-unreachable 'dock' pane value. * fix(desktop): stop the Spend cost-flow Sankey from re-rendering forever The label-fit effect measured the already-truncated text, so a capped label read as short, un-capped, overflowed the cap, and re-capped without end (Maximum update depth exceeded). It now estimates each label from its full name via data-name, and caps only tighten per layout, so the measure, cap and remeasure cycle is guaranteed to settle instead of oscillating. * feat(desktop): bundle Inter and JetBrains Mono for one UI on every OS The app used each platform's system font (SF Pro on macOS, Segoe UI on Windows), so the two looked different. Bundle Inter for text and JetBrains Mono for figures and lead the --sans and --mono stacks with them, keeping the per-locale CJK fallbacks, so Windows and macOS render the same faces. * desktop: gate tray installed state on support; drop strings and channels the sidebar switches left behind
250 lines
10 KiB
TypeScript
250 lines
10 KiB
TypeScript
import { useEffect, useRef, useState } from 'react'
|
|
import type { CSSProperties } from 'react'
|
|
import { Icon } from '../components/icons'
|
|
import { t } from '../i18n'
|
|
import { codeburn } from '../lib/ipc'
|
|
import type { CompanionStatus } from '../lib/types'
|
|
import { MenuBarAboutModal } from './MenuBarAbout'
|
|
import styles from './Plugins.module.css'
|
|
import menubarArt from '../assets/menubar-card-art.jpg'
|
|
import menubarArtLight from '../assets/menubar-card-art-light.jpg'
|
|
|
|
/**
|
|
* The Windows tray app ("Menu bar") and the Capacity Dock rail it draws, as one card on the
|
|
* Plugins page, so Windows configures its companion the same place macOS does (MenuBarCard).
|
|
* The discrete actions map to windows/ semantics: Install/Reinstall stages and runs the bundled
|
|
* MSI; Open shows the tray popover (a bare relaunch); Quit stops the process without uninstalling
|
|
* or dropping launch-at-login; Uninstall runs msiexec /x; Settings opens the desktop app's own
|
|
* Menu bar pane (the tray's settings live there on Windows, not in a separate window). Update is
|
|
* the same Install path against a newer bundled MSI, not the tray's own GitHub self-updater,
|
|
* which the Windows distribution policy leaves off.
|
|
*/
|
|
const POLL_MS = 4000
|
|
|
|
type Action = 'install' | 'open' | 'dock' | 'quit' | 'uninstall' | 'update'
|
|
|
|
/** Polls only while mounted and visible, and never sets state to a value equal to the one held,
|
|
* so a still machine re-renders zero times. Mirrors the macOS card's hook. */
|
|
function useCompanionStatus(): [CompanionStatus | null, (next: CompanionStatus) => void, () => void] {
|
|
const [status, setStatus] = useState<CompanionStatus | null>(null)
|
|
const held = useRef<string>('')
|
|
|
|
const apply = (next: CompanionStatus) => {
|
|
const key = JSON.stringify(next)
|
|
if (key === held.current) return
|
|
held.current = key
|
|
setStatus(next)
|
|
}
|
|
|
|
const refresh = () => {
|
|
void codeburn?.companionStatus?.().then(apply).catch(() => {})
|
|
}
|
|
|
|
useEffect(() => {
|
|
let live = true
|
|
const tick = () => {
|
|
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
|
|
void codeburn?.companionStatus?.().then(next => { if (live) apply(next) }).catch(() => {})
|
|
}
|
|
tick()
|
|
const timer = setInterval(tick, POLL_MS)
|
|
return () => { live = false; clearInterval(timer) }
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [])
|
|
|
|
return [status, apply, refresh]
|
|
}
|
|
|
|
export function WindowsCompanionCard({ onOpenSettings, art = menubarArt, artLight = menubarArtLight }: {
|
|
onOpenSettings?: () => void
|
|
art?: string
|
|
artLight?: string
|
|
} = {}) {
|
|
const [status, apply, refresh] = useCompanionStatus()
|
|
const [busy, setBusy] = useState<Action | null>(null)
|
|
const [error, setError] = useState<string | null>(null)
|
|
// Quit and Uninstall confirm in the card, the same way removing a plugin does on this page.
|
|
const [confirming, setConfirming] = useState<'quit' | 'uninstall' | null>(null)
|
|
const [about, setAbout] = useState(false)
|
|
|
|
if (!status?.supported) return null
|
|
|
|
const act = async (kind: Action, call: () => Promise<void>) => {
|
|
if (busy) return
|
|
setBusy(kind)
|
|
setError(null)
|
|
try {
|
|
await call()
|
|
} catch {
|
|
setError(t('plugins.menuBar.errorGeneric'))
|
|
} finally {
|
|
setBusy(null)
|
|
setConfirming(null)
|
|
refresh()
|
|
}
|
|
}
|
|
|
|
const install = (kind: 'install' | 'update') => act(kind, async () => {
|
|
const result = await codeburn.companionInstall?.()
|
|
if (!result) return
|
|
apply(result.status)
|
|
if (!result.ok) setError(result.error ?? t('plugins.menuBar.errorInstall'))
|
|
})
|
|
|
|
const open = () => act('open', async () => {
|
|
const next = await codeburn.companionOpen?.()
|
|
if (next) apply(next)
|
|
})
|
|
|
|
const toggleDock = () => act('dock', async () => {
|
|
const next = await codeburn.companionSetDock?.(!status.sidebar)
|
|
if (next) apply(next)
|
|
})
|
|
|
|
const quit = () => act('quit', async () => {
|
|
const result = await codeburn.companionQuit?.()
|
|
if (!result) return
|
|
apply(result.status)
|
|
if (!result.ok) setError(result.error ?? t('plugins.menuBar.errorQuit'))
|
|
})
|
|
|
|
const uninstall = () => act('uninstall', async () => {
|
|
const result = await codeburn.companionUninstall?.()
|
|
if (!result) return
|
|
apply(result.status)
|
|
if (!result.ok) setError(result.error ?? t('plugins.menuBar.errorUninstall'))
|
|
})
|
|
|
|
const restartHint = status.restartRequired ? t('shell.sidebar.restartRequired') : ''
|
|
|
|
return (
|
|
<div
|
|
className={`${styles.row} ${styles.art} ${styles.companionCard}`}
|
|
style={{
|
|
'--card-art': `url(${art})`,
|
|
'--card-art-light': `url(${artLight})`,
|
|
'--art-light-wash': .84,
|
|
} as CSSProperties}
|
|
data-status="loaded"
|
|
>
|
|
<div className={`${styles.info} ${styles.menubarInfo}`}>
|
|
<div className={styles.nameRow}>
|
|
<div className={styles.name}>{t('plugins.menuBar.name')}</div>
|
|
<button
|
|
type="button"
|
|
className={`ov-info ${styles.infoDot}`}
|
|
aria-label={t('plugins.menuBar.aboutAria')}
|
|
onClick={() => setAbout(true)}
|
|
>
|
|
<Icon name="info" />
|
|
</button>
|
|
</div>
|
|
<div className={`${styles.reason} ${styles.reasonFull}`}>
|
|
{t('shell.sidebar.menuBarHint')}
|
|
</div>
|
|
{/* One note row, always present, so the card is the same height in every state. An error
|
|
answers something the person just pressed, so it wins over the restart hint. */}
|
|
<div className={styles.note} data-kind={error ? 'error' : 'hint'} title={error ?? undefined}>
|
|
{error ?? restartHint}
|
|
</div>
|
|
<div className={styles.caps}>
|
|
{status.running && (
|
|
<span className={styles.running}><span className={styles.runningDot} />{t('plugins.menuBar.running')}</span>
|
|
)}
|
|
{status.version && <span>v{status.version}</span>}
|
|
</div>
|
|
</div>
|
|
<div className={styles.controls}>
|
|
{status.installed && (
|
|
<label className={styles.dockToggle}>
|
|
<span>{t('plugins.menuBar.capacityDock')}</span>
|
|
<button
|
|
type="button"
|
|
role="switch"
|
|
aria-checked={status.sidebar}
|
|
aria-label={t('plugins.menuBar.capacityDock')}
|
|
disabled={busy !== null || !status.running || status.restartRequired}
|
|
title={status.running ? t('plugins.menuBar.dockShowTitle') : t('plugins.menuBar.dockOpenTitle')}
|
|
className={status.sidebar ? 'switch sm on' : 'switch sm'}
|
|
onClick={toggleDock}
|
|
>
|
|
<span className="switch-knob" />
|
|
</button>
|
|
</label>
|
|
)}
|
|
<div className={styles.actions}>
|
|
{status.installed ? (
|
|
<>
|
|
{status.outdated && status.canInstall && (
|
|
<button className={`btnp ${styles.primary}`} onClick={() => install('update')} disabled={busy !== null}>
|
|
{busy === 'update' ? `${t('plugins.menuBar.updating')}…` : t('plugins.menuBar.update')}
|
|
</button>
|
|
)}
|
|
{/* No window to bring forward while it is up, so Open shows only while it is down;
|
|
Settings and Quit while it is up. Uninstall shows in both. */}
|
|
{!status.running && (
|
|
<button
|
|
type="button"
|
|
className={`btnp ${styles.iconBtn}`}
|
|
aria-label={t('plugins.menuBar.openAria')}
|
|
title={t('plugins.menuBar.openTitle')}
|
|
disabled={busy !== null || status.restartRequired}
|
|
onClick={open}
|
|
>
|
|
<Icon name="arrow-up-right" />
|
|
</button>
|
|
)}
|
|
{status.running && onOpenSettings && (
|
|
<button
|
|
type="button"
|
|
className={`btnp ${styles.iconBtn}`}
|
|
aria-label={t('plugins.menuBar.settingsAria')}
|
|
title={t('plugins.menuBar.settingsTitle')}
|
|
disabled={busy !== null}
|
|
onClick={onOpenSettings}
|
|
>
|
|
<Icon name="settings" />
|
|
</button>
|
|
)}
|
|
{/* Destructive, so a light guard: the first click arms the icon (it swaps to a
|
|
check), a second confirms, and moving focus away disarms it. */}
|
|
{status.running && (
|
|
<button
|
|
type="button"
|
|
className={confirming === 'quit' ? `btnp ${styles.iconBtn} ${styles.confirming}` : `btnp ${styles.iconBtn}`}
|
|
aria-label={confirming === 'quit' ? t('plugins.menuBar.confirmQuit') : t('plugins.menuBar.quit')}
|
|
title={confirming === 'quit' ? t('plugins.menuBar.clickAgainQuit') : t('plugins.menuBar.quit')}
|
|
disabled={busy !== null}
|
|
onClick={() => (confirming === 'quit' ? quit() : setConfirming('quit'))}
|
|
onBlur={() => setConfirming(current => (current === 'quit' ? null : current))}
|
|
>
|
|
<Icon name={confirming === 'quit' ? 'circle-check' : 'x'} />
|
|
</button>
|
|
)}
|
|
{status.canInstall && (
|
|
<button
|
|
type="button"
|
|
className={confirming === 'uninstall' ? `btnp ${styles.iconBtn} ${styles.confirming}` : `btnp ${styles.iconBtn}`}
|
|
aria-label={confirming === 'uninstall' ? t('plugins.menuBar.confirmUninstall') : t('plugins.menuBar.uninstall')}
|
|
title={confirming === 'uninstall' ? t('plugins.menuBar.clickAgainUninstall') : t('plugins.menuBar.uninstall')}
|
|
disabled={busy !== null}
|
|
onClick={() => (confirming === 'uninstall' ? uninstall() : setConfirming('uninstall'))}
|
|
onBlur={() => setConfirming(current => (current === 'uninstall' ? null : current))}
|
|
>
|
|
<Icon name={confirming === 'uninstall' ? 'circle-check' : 'trash-2'} />
|
|
</button>
|
|
)}
|
|
</>
|
|
) : status.canInstall ? (
|
|
<button className={`btnp ${styles.primary}`} onClick={() => install('install')} disabled={busy !== null}>
|
|
{busy === 'install' ? `${t('plugins.menuBar.installing')}…` : t('plugins.menuBar.install')}
|
|
</button>
|
|
) : (
|
|
<span className={styles.website}>{t('plugins.menuBar.website')}</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
{about && <MenuBarAboutModal onClose={() => setAbout(false)} />}
|
|
</div>
|
|
)
|
|
}
|