Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased — desktop earnings while signed out

- Ask a linked Mac to sign in when its Darkbloom account session is signed out or expired, instead of showing "Loading settled earnings…" indefinitely on Earnings, Home's daily earnings chart and the Models earnings order.

## Unreleased — desktop hardware load

- Serve real whole-machine load to the desktop app over the authenticated loopback control API: per-core CPU load with the chip's tier and cluster layout (including M5 Super cores), GPU utilization and memory, ANE activity, memory use and pressure, thermal state, and Darkbloom's share of GPU time. Sampling runs in the desktop API process only while the app is looking, without root, and never reaches heartbeats, logs or the coordinator.
Expand Down
14 changes: 11 additions & 3 deletions desktop-app/src/renderer/features/Earnings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function Earnings({ backend }: { backend: BackendState }) {
const [window, setWindow] = useState<'7d' | '30d'>('7d');
const [metric, setMetric] = useState<InsightMetric>('earnings');
const [copied, setCopied] = useState(false);
const { data, error, refresh } = useInsights(backend.state!, window);
const { data, error, available, refresh } = useInsights(backend.state!, window);
const copy = async () => {
if (!data) return;
const rows = [
Expand Down Expand Up @@ -64,11 +64,19 @@ export function Earnings({ backend }: { backend: BackendState }) {
/>
{!data ? (
<div className="empty-state">
<h2>{backend.state?.linked ? 'Earnings insights' : 'Link your account'}</h2>
<h2>
{!backend.state?.linked
? 'Link your account'
: available
? 'Earnings insights'
: 'Sign in to see earnings'}
</h2>
<p>
{!backend.state?.linked
? 'Link this Mac to see earnings and lifetime milestones.'
: error || 'Loading settled earnings…'}
: !available
? 'Sign in to your Darkbloom account from the sidebar to load settled earnings.'
: error || 'Loading settled earnings…'}
</p>
{error && <Button onClick={() => void refresh()}>Try again</Button>}
</div>
Expand Down
10 changes: 8 additions & 2 deletions desktop-app/src/renderer/features/home/FleetEarnings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function FleetEarnings({
backend: BackendState;
onEarnings: () => void;
}) {
const { data, error } = useInsights(backend.state!);
const { data, error, available } = useInsights(backend.state!);
const week = backend.cloud?.week_micro_usd;
const complete = backend.cloud?.earnings_complete !== false;
const since = backend.cloud?.earnings_since
Expand Down Expand Up @@ -59,7 +59,13 @@ export function FleetEarnings({
<EarningsTimeline days={data.days} metric="earnings" partial={!data.history_complete} />
) : (
<p className={styles.emptyChart}>
{backend.state!.linked ? (error ? 'Unavailable' : 'Loading…') : 'Account not linked'}
{!backend.state!.linked
? 'Account not linked'
: !available
? 'Sign in to see earnings'
: error
? 'Unavailable'
: 'Loading…'}
</p>
)}
{data && error && (
Expand Down
7 changes: 6 additions & 1 deletion desktop-app/src/renderer/features/insights/useInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { Snapshot } from '../../../shared/contracts';
import { api } from '../../useBackend';
import { parseInsights, type ProviderInsights } from './types';

// Earnings are read with the account session (or legacy provider data). A linked Mac can be
// signed out, so callers use `available` rather than `linked` to tell sign-in from loading.
export function useInsights(state: Snapshot, window: '7d' | '30d' = '7d') {
const key = (state.account ? state.account.signed_in || state.account.legacy_data : state.linked)
? `${state.installation_id}:${state.account_revision || 'legacy'}:${window}`
Expand Down Expand Up @@ -49,5 +51,8 @@ export function useInsights(state: Snapshot, window: '7d' | '30d' = '7d') {
if (session.current === current) session.current = null;
};
}, [key, refresh, state.resource_revision]);
return snapshot.key === key ? { ...snapshot, refresh } : { data: null, error: null, refresh };
const available = key !== '';
return snapshot.key === key
? { ...snapshot, available, refresh }
: { data: null, error: null, available, refresh };
}
11 changes: 10 additions & 1 deletion desktop-app/src/renderer/features/models/ModelEarnings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@ export function ModelEarningsOrder({
earnings,
error,
linked,
available = true,
}: {
earnings: ModelEarnings;
error: string | null;
linked: boolean;
/** False when a linked Mac is signed out, so earnings cannot be read. */
available?: boolean;
}) {
return (
<div className="model-earnings-order" title={error ?? undefined}>
<span>Most earned · {earnings?.historyComplete === false ? 'Recent' : '30d'}</span>
{!earnings && (
<span className="muted">
{!linked ? 'Account not linked' : error ? 'Unavailable' : 'Loading…'}
{!linked
? 'Account not linked'
: !available
? 'Sign in to see earnings'
: error
? 'Unavailable'
: 'Loading…'}
</span>
)}
{!!earnings && !!error && <span className="muted">Last update</span>}
Expand Down
7 changes: 6 additions & 1 deletion desktop-app/src/renderer/features/models/Models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export function Models({
const earnings = useMemo(() => modelEarnings(insights.data), [insights.data]);
const ranked = useMemo(() => rankModels(state.models, earnings), [state.models, earnings]);
const order = (
<ModelEarningsOrder earnings={earnings} error={insights.error} linked={state.linked} />
<ModelEarningsOrder
earnings={earnings}
error={insights.error}
linked={state.linked}
available={insights.available}
/>
);
const actions = useModelActions(backend);
const mode = modelsMode(state);
Expand Down
34 changes: 34 additions & 0 deletions desktop-app/tests/earningsSignedOut.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @vitest-environment jsdom
import { afterEach, expect, it, vi } from 'vitest';
import { cleanup, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';
import { Earnings } from '../src/renderer/features/Earnings';
import { FleetEarnings } from '../src/renderer/features/home/FleetEarnings';
import { backendWith } from './onboardingFixtures';
import { poolSnapshot } from './modelsFixtures';

afterEach(cleanup);

// Signing out (or a dashboard session expiring) keeps the Mac's provider link.
const signedOut = () => ({
...poolSnapshot(),
linked: true,
account: { signed_in: false, legacy_data: false },
});

it('asks a linked but signed-out Mac to sign in instead of loading forever', () => {
render(<Earnings backend={backendWith(signedOut())} />);
expect(screen.getByRole('heading', { name: 'Sign in to see earnings' })).toBeVisible();
expect(screen.queryByText('Loading settled earnings…')).not.toBeInTheDocument();
cleanup();
render(<FleetEarnings backend={backendWith(signedOut())} onEarnings={vi.fn()} />);
expect(screen.getByText('Sign in to see earnings')).toBeVisible();
expect(screen.queryByText('Loading…')).not.toBeInTheDocument();
});

it('still shows loading while a signed-in account reads its earnings', () => {
const state = { ...signedOut(), account: { signed_in: true } };
render(<Earnings backend={backendWith(state)} />);
expect(screen.getByRole('heading', { name: 'Earnings insights' })).toBeVisible();
expect(screen.getByText('Loading settled earnings…')).toBeVisible();
});
Loading