Milestone 7: the app normal people install (macOS)
A Tauri menu-bar app runs the same sync engine as `lunesync run`. It connects from the website with no code typed (lune://join and lune://pair links), shows status in the menu bar, and lets a person resolve held secrets, held big changes and kept-both notes side by side. Uninstall shares and hands over first, then removes only what Lune created. Releases are signed on the hub that holds the key (`lunehub release keygen/publish`); other hubs `release import` them. Apps verify the signature and the signed version. Clients older than the previous release are asked to update and keep saving locally. A device can now be on several hubs at once (own and workplace), each with its own key; the CLI takes --team when it matters. The supervisor and status summary moved into core, shared by the CLI and the app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
318
web/src/desktop/main.tsx
Normal file
318
web/src/desktop/main.tsx
Normal file
@@ -0,0 +1,318 @@
|
||||
// The Lune window in the Mac app: connect this Mac, see each vault plainly, and make the few decisions only a person
|
||||
// can (a held big change, a possible secret, a note changed in two places). Talks to the app, not to the hub.
|
||||
import { StrictMode, useCallback, useEffect, useState } from 'react';
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import '../styles.css';
|
||||
import './desktop.css';
|
||||
import moon from './moon.svg';
|
||||
|
||||
type Level = 'current' | 'behind' | 'offline' | 'secret';
|
||||
|
||||
interface VaultStatus {
|
||||
name: string;
|
||||
path: string;
|
||||
team: string | null;
|
||||
level: Level;
|
||||
headline: string;
|
||||
last_synced: number | null;
|
||||
waiting: number;
|
||||
read_only: boolean;
|
||||
running: boolean;
|
||||
held: { message: string; removed: number; rewritten: number; total: number }[];
|
||||
secrets: { path: string; found: string[] }[];
|
||||
tidy: { note: string; copy: string; label: string }[];
|
||||
case_clashes: string[];
|
||||
}
|
||||
|
||||
interface Overview {
|
||||
version: string;
|
||||
connected: boolean;
|
||||
teams: string[];
|
||||
device: string;
|
||||
folder: string;
|
||||
level: Level;
|
||||
summary: string;
|
||||
vaults: VaultStatus[];
|
||||
pending: { kind: 'join' | 'pair'; hub: string } | null;
|
||||
update: string | null;
|
||||
recent: string[];
|
||||
}
|
||||
|
||||
interface Comparison {
|
||||
note: string;
|
||||
copy: string;
|
||||
label: string;
|
||||
copy_is_mine: boolean;
|
||||
note_text: string | null;
|
||||
copy_text: string | null;
|
||||
}
|
||||
|
||||
const host = (url: string | null) => (url ? url.replace(/^https?:\/\//, '') : '');
|
||||
const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
||||
|
||||
function Dot({ level }: { level: Level }) {
|
||||
return <span className={`dot dot-${level}`} aria-hidden="true" />;
|
||||
}
|
||||
|
||||
/** Connecting: from the link the website opened (no code), or a hub address and code typed by hand. */
|
||||
function Connect({ o, done, cancel }: { o: Overview; done: (msg: string) => void; cancel?: () => void }) {
|
||||
const [name, setName] = useState(o.device);
|
||||
const [folder, setFolder] = useState(o.folder);
|
||||
const [hubUrl, setHubUrl] = useState('');
|
||||
const [code, setCode] = useState('');
|
||||
const [manual, setManual] = useState(!!cancel && !o.pending);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const fromLink = o.pending && !manual;
|
||||
|
||||
const submit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setError('');
|
||||
try {
|
||||
done(await invoke<string>('connect', { name, folder, hubUrl: fromLink ? null : hubUrl, code: fromLink ? null : code }));
|
||||
} catch (err) {
|
||||
setError(String(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const pick = async () => {
|
||||
const path = await invoke<string | null>('choose_folder');
|
||||
if (path) setFolder(path);
|
||||
};
|
||||
|
||||
if (!o.pending && !manual) {
|
||||
return (
|
||||
<section className="welcome">
|
||||
<img className="moon" src={moon} alt="" />
|
||||
<h1 className="disp">Connect this Mac to your team</h1>
|
||||
<p>Open your invite link and choose <b>Open Lune to join</b>. Already on the team? Open the team canvas in your browser and choose <b>Connect this Mac</b>.</p>
|
||||
<button className="btn btn-ghost" onClick={() => setManual(true)}>I have a pairing code instead</button>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<form className="welcome" onSubmit={submit}>
|
||||
<span className="eyebrow">{fromLink ? (o.pending!.kind === 'join' ? 'Invite' : 'Connect') : 'Pairing code'}</span>
|
||||
<h1 className="disp">
|
||||
{fromLink ? (o.pending!.kind === 'join' ? `Join the team at ${host(o.pending!.hub)}` : `Connect to ${host(o.pending!.hub)}`) : 'Connect with a code'}
|
||||
</h1>
|
||||
{!fromLink && (
|
||||
<>
|
||||
<label htmlFor="hub">Team address</label>
|
||||
<input id="hub" className="field" value={hubUrl} onChange={(e) => setHubUrl(e.target.value)} placeholder="lune.example.com" autoFocus />
|
||||
<label htmlFor="code">Code from one of your devices</label>
|
||||
<input id="code" className="field code" value={code} onChange={(e) => setCode(e.target.value)} placeholder="K7QD-4MXA" />
|
||||
</>
|
||||
)}
|
||||
<label htmlFor="name">This Mac's name</label>
|
||||
<input id="name" className="field" value={name} onChange={(e) => setName(e.target.value)} maxLength={40} />
|
||||
<p className="muted">Your team sees it next to your changes.</p>
|
||||
<label>Shared vaults go in</label>
|
||||
<div className="folder-row">
|
||||
<span className="folder" title={folder}><bdi>{folder}</bdi></span>
|
||||
<button type="button" className="btn btn-small" onClick={pick}>Change…</button>
|
||||
</div>
|
||||
{error && <p className="error" role="alert">{error}</p>}
|
||||
<button className="btn btn-primary" type="submit" disabled={busy || !name.trim() || (!fromLink && (!hubUrl.trim() || !code.trim()))}>
|
||||
{busy ? 'Connecting…' : fromLink && o.pending!.kind === 'join' ? 'Join' : 'Connect'}
|
||||
</button>
|
||||
{fromLink ? (
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setManual(true)}>Use a pairing code instead</button>
|
||||
) : o.pending ? (
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setManual(false)}>Back to the link</button>
|
||||
) : (
|
||||
<button type="button" className="btn btn-ghost" onClick={() => (cancel ? cancel() : setManual(false))}>Back</button>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function SecretCard({ vault, s, act }: { vault: string; s: VaultStatus['secrets'][number]; act: (cmd: string, args: Record<string, unknown>, msg: string) => void }) {
|
||||
const [pointer, setPointer] = useState('');
|
||||
return (
|
||||
<div className="need need-secret">
|
||||
<b>{s.path} wasn't shared: it may contain a secret</b>
|
||||
{s.found.map((f) => <span key={f} className="muted">{f}</span>)}
|
||||
<label className="lbl" htmlFor={`p-${s.path}`}>Replace it with where to find it</label>
|
||||
<input id={`p-${s.path}`} className="field" value={pointer} onChange={(e) => setPointer(e.target.value)} placeholder='e.g. "search prod-deploy in Secrets Manager"' />
|
||||
<div className="actions">
|
||||
<button className="btn btn-small" onClick={() => act('not_a_secret', { vault, path: s.path }, `OK — ${s.path} will be shared`)}>Not a secret</button>
|
||||
<button className="btn btn-small btn-primary" disabled={!pointer.trim()} onClick={() => act('secret_pointer', { vault, path: s.path, pointer }, 'Replaced — sharing now')}>Replace</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function VaultCard({ v, several, act, compare }: { v: VaultStatus; several: boolean; act: (cmd: string, args: Record<string, unknown>, msg: string) => void; compare: (vault: string, copy: string) => void }) {
|
||||
return (
|
||||
<article className="vault" data-vault={v.name}>
|
||||
<div className="vault-head">
|
||||
<Dot level={v.level} />
|
||||
<div className="vault-name">
|
||||
<b>{v.name}{several && v.team && <span className="team-tag">{host(v.team)}</span>}</b>
|
||||
<span className="muted">{v.headline}</span>
|
||||
</div>
|
||||
<button className="btn btn-small btn-ghost" onClick={() => act('open_folder', { vault: v.name }, '')}>Open folder</button>
|
||||
</div>
|
||||
{v.held.map((h) => (
|
||||
<div key={h.message} className="need">
|
||||
<b>A big change is waiting for you</b>
|
||||
<span className="muted">"{h.message}" removes {h.removed} and rewrites {h.rewritten} of {plural(h.total, 'note')}. Nothing from this Mac is shared until you decide.</span>
|
||||
<div className="actions">
|
||||
<button className="btn btn-small" onClick={() => act('held_undo', { vault: v.name }, 'Brought everything back')}>Undo</button>
|
||||
<button className="btn btn-small btn-primary" onClick={() => act('held_share', { vault: v.name }, 'Sharing it')}>Share anyway</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{v.secrets.map((s) => <SecretCard key={s.path} vault={v.name} s={s} act={act} />)}
|
||||
{v.tidy.map((t) => (
|
||||
<div key={t.copy} className="need">
|
||||
<b>{t.note} was changed in two places</b>
|
||||
<span className="muted">Both versions are kept; pick one when you have a moment.</span>
|
||||
<div className="actions">
|
||||
<button className="btn btn-small btn-primary" onClick={() => compare(v.name, t.copy)}>Compare</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
/** Side by side (stacked in this narrow window); differing lines tinted. */
|
||||
function CompareSheet({ vault, copy, close, done }: { vault: string; copy: string; close: () => void; done: (msg: string) => void }) {
|
||||
const [c, setC] = useState<Comparison | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
useEffect(() => { invoke<Comparison>('compare', { vault, copy }).then(setC).catch((e) => setError(String(e))); }, [vault, copy]);
|
||||
const keep = async (which: 'note' | 'copy' | 'both') => {
|
||||
try {
|
||||
await invoke('tidy', { vault, copy, keep: which });
|
||||
done(which === 'both' ? 'Kept both as separate notes' : 'Tidied — every device gets it shortly');
|
||||
} catch (e) {
|
||||
setError(String(e));
|
||||
}
|
||||
};
|
||||
const column = (title: string, text: string | null, other: string | null, tint: string) => {
|
||||
const others = new Set((other ?? '').split('\n'));
|
||||
return (
|
||||
<div className="cmp-col">
|
||||
<div className="cmp-head">{title}</div>
|
||||
<div className="cmp-body">
|
||||
{text === null ? <span className="muted">Not shown (not a text note, or very large).</span>
|
||||
: text.split('\n').map((line, i) => <div key={i} style={others.has(line) ? undefined : { background: tint, margin: '0 -14px', padding: '0 14px' }}>{line || ' '}</div>)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
const mine = c?.copy_is_mine;
|
||||
return (
|
||||
<div className="scrim" onPointerDown={(e) => { if (e.target === e.currentTarget) close(); }}>
|
||||
<div className="dialog" role="dialog" aria-modal="true" aria-label="Compare two versions">
|
||||
<div><span className="eyebrow">{vault} · {c?.note ?? ''}</span><h2 className="disp">Two versions of the same lines</h2></div>
|
||||
{error && <p className="error">{error}</p>}
|
||||
{c && (
|
||||
<div className="cmp">
|
||||
{column(mine ? 'The other version (in place)' : 'In place', c.note_text, c.copy_text, '#FBEBD3')}
|
||||
{column(mine ? "This Mac's version" : `${c.label}'s version`, c.copy_text, c.note_text, '#E8E1FB')}
|
||||
</div>
|
||||
)}
|
||||
<div className="actions">
|
||||
<button className="btn" onClick={close}>Not now</button>
|
||||
{c && (
|
||||
<>
|
||||
<button className="btn" onClick={() => keep('both')}>Keep both</button>
|
||||
<button className="btn" onClick={() => keep('note')}>{mine ? 'Keep the other' : 'Keep the one in place'}</button>
|
||||
<button className="btn btn-primary" onClick={() => keep('copy')}>{mine ? "Keep this Mac's" : `Keep ${c.label}'s`}</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function App() {
|
||||
const [o, setO] = useState<Overview | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
const [toast, setToast] = useState('');
|
||||
const [comparing, setComparing] = useState<{ vault: string; copy: string } | null>(null);
|
||||
const [joining, setJoining] = useState(false);
|
||||
|
||||
const load = useCallback(() => invoke<Overview>('overview').then(setO).catch((e) => setError(String(e))), []);
|
||||
useEffect(() => {
|
||||
load();
|
||||
const t = setInterval(load, 2000);
|
||||
return () => clearInterval(t);
|
||||
}, [load]);
|
||||
useEffect(() => {
|
||||
if (!toast) return;
|
||||
const t = setTimeout(() => setToast(''), 4000);
|
||||
return () => clearTimeout(t);
|
||||
}, [toast]);
|
||||
|
||||
const act = async (cmd: string, args: Record<string, unknown>, msg: string) => {
|
||||
try {
|
||||
await invoke(cmd, args);
|
||||
if (msg) setToast(msg);
|
||||
load();
|
||||
} catch (e) {
|
||||
setToast(String(e));
|
||||
}
|
||||
};
|
||||
|
||||
if (!o) return <main className="app">{error && <p className="error">{error}</p>}</main>;
|
||||
return (
|
||||
<main className="app">
|
||||
<header className="top">
|
||||
<img className="moon-small" src={moon} alt="" />
|
||||
<div className="top-text">
|
||||
<b className="disp">Lune</b>
|
||||
<span className="muted"><Dot level={o.level} /> {o.summary}</span>
|
||||
</div>
|
||||
</header>
|
||||
{o.update && (
|
||||
<div className="banner">
|
||||
<span>Lune {o.update} is ready.</span>
|
||||
<button className="btn btn-small btn-primary" onClick={() => invoke('restart')}>Restart to update</button>
|
||||
</div>
|
||||
)}
|
||||
{!o.connected || o.pending || joining ? (
|
||||
<Connect o={o} done={(msg) => { setJoining(false); setToast(msg); load(); }} cancel={o.connected ? () => setJoining(false) : undefined} />
|
||||
) : (
|
||||
<>
|
||||
<section className="vaults">
|
||||
{o.vaults.length === 0 && <p className="muted center">Your vaults are on their way. They'll appear in {o.folder}.</p>}
|
||||
{o.vaults.map((v) => <VaultCard key={v.path} v={v} several={o.teams.length > 1} act={act} compare={(vault, copy) => setComparing({ vault, copy })} />)}
|
||||
</section>
|
||||
<footer className="foot">
|
||||
<span className="muted">{o.device} · Lune {o.version}</span>
|
||||
<ul className="teams">
|
||||
{o.teams.map((t) => (
|
||||
<li key={t}>
|
||||
<span>{host(t)}</span>
|
||||
<button className="btn btn-small btn-ghost" onClick={() => act('open_canvas', { team: t }, '')}>Open canvas</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<div className="actions">
|
||||
<button className="btn btn-small" onClick={() => act('share_now', {}, 'Sharing now')}>Share now</button>
|
||||
<button className="btn btn-small" onClick={() => setJoining(true)}>Join another team</button>
|
||||
</div>
|
||||
{o.recent.length > 0 && (
|
||||
<details className="recent">
|
||||
<summary>Recent activity</summary>
|
||||
<pre>{o.recent.join('\n')}</pre>
|
||||
</details>
|
||||
)}
|
||||
</footer>
|
||||
</>
|
||||
)}
|
||||
{comparing && <CompareSheet {...comparing} close={() => setComparing(null)} done={(msg) => { setComparing(null); setToast(msg); load(); }} />}
|
||||
{toast && <div className="toast-d" role="status">{toast}</div>}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root')!).render(<StrictMode><App /></StrictMode>);
|
||||
Reference in New Issue
Block a user