* feat: web bookmarks for arbitrary URLs (NIP-B0) Adds a Web Bookmarks app backed by NIP-B0 (kind 39701): one addressable event per saved URL, distinct from the NIP-51 bookmark list (#21) since it carries its own title/description/tags per page rather than being an entry in a list. - src/hooks/useWebBookmarks.ts: create/list/delete, plus bookmarkDTag/bookmarkUrl implementing the spec's "strip https://" d-tag rule (round-tripped by a unit test). - Delete publishes a NIP-09 kind 5 request and also drops the item from the local query cache directly, since relays aren't obligated to honor the deletion. - New src/apps/web-bookmarks/index.tsx: inline add form, list with title/description/tags, opens the saved URL in a new tab. Closes #25 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BYiUtZMQeA5RHggQw73wto * fix: address review feedback on web bookmarks Per review: - bookmarkDTag() now matches the https scheme case-insensitively, so "HTTPS://…" and "https://…" collapse to the same d tag instead of creating duplicate bookmarks. - The form now accepts every scheme sanitizeUrl() allows (https, http, mailto, nostr) via a dedicated isBookmarkableUrl() check — not sanitizeUrl() itself, which resolves relative URLs against this app's own origin and would have "validated" a bare hostname like "example.com" as a link back into the app. - WebBookmarkRow no longer falls back to the raw unsanitized URL when sanitizeUrl() rejects it (e.g. a malicious "d" tag) — it renders plain text with no link instead of defeating the sanitization. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BYiUtZMQeA5RHggQw73wto * fix: round-trip mailto:/nostr: bookmarks and preserve published_at Per review: - bookmarkUrl() required "scheme://" to recognize an already-schemed d tag, so opaque URIs with no "//" — mailto: and nostr: — were incorrectly prefixed with "https://". Fixed by also checking a closed list of the opaque schemes this app supports, alongside the existing "://" check (kept as-is so a hierarchical scheme like gemini:// still round-trips, and so a stripped https URL containing a port, e.g. alice.blog:8080/post, still isn't misread as scheme "alice.blog"). Added regression tests for all three cases. - useCreateWebBookmark now looks up the existing bookmark for the same d tag before publishing and carries its published_at forward, instead of resetting it to now on every edit — per NIP-B0, published_at is "the first time the bookmark was published." Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BYiUtZMQeA5RHggQw73wto * fix: dedupe multiple revisions of the same web bookmark Per an earlier "previously missed" finding: useMyWebBookmarks() returned every kind-39701 event a relay handed back, but for an addressable event the pool can return more than one revision of the same d tag (an edit history, or relays disagreeing on what's current), which showed up as duplicate rows for the same URL. Extracted dedupeLatestByDTag() (keeps the newest per d, newest-first) and covered it with regression tests. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BYiUtZMQeA5RHggQw73wto --------- Co-authored-by: highperfocused <highperfocused@pm.me> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
6.1 KiB
Apps
An app is a component that renders inside a window. It receives its window's parameters, can rename its window and can rewrite its own parameters — and knows nothing else about the OS.
The registry
src/os/registry.ts is the single source of truth. Adding an entry there is all it takes
for an app to appear on the desktop, in the Go menu, in the command palette and in the
About app. There is no router change, no menu update, no icon grid to edit.
interface AppDefinition {
id: string; // 'feed' — also the ?app= value and the window id prefix
title: string; // default window title
description: string; // one line, shown in the palette and About
icon: LucideIcon;
category: 'social' | 'tools' | 'system';
component: LazyExoticComponent<ComponentType<AppProps>>;
defaultSize: Size; // capped to the viewport by fitSize()
minSize: Size; // enforced while resizing
resizable?: boolean; // default true
singleton?: boolean; // default true — a second open focuses the existing window
showOnDesktop?: boolean; // default true
requiresAuth?: boolean;
}
Every component is a React.lazy(() => import('@/apps/<id>')), so each app is its own
code-split chunk and the initial bundle contains only the shell. WindowFrame supplies
the <Suspense> skeleton and an ErrorBoundary around it — a crashing app takes down its
own window, not the desktop.
The contract
interface AppProps {
windowId: string;
params: AppParams; // Record<string, string>
setTitle: (title: string) => void; // truncated to 48 chars by the reducer
setParams: (params: AppParams) => void;
}
params is the app's navigation state, not local state. Putting the current
selection in params rather than useState buys three things at once: the URL describes
what is on screen, a reload restores it, and the state survives the remount when the
window switches between the desktop and mobile shells. The Reader does this with the
selected article; the Feed keeps its scope in local state because a tab choice is not
worth a URL.
setTitle is normally called from an effect once the content is known:
useEffect(() => {
setTitle(name ? `Profile — ${name}` : 'Profile');
}, [name, setTitle]);
Adding an app
- Create
src/apps/<id>/index.tsxwith a default export takingAppProps. - Build the UI from the
AppChromeprimitives (seestyleguide.md) so it fills its window instead of centring a column like a web page. - Add an entry to
APPSinsrc/os/registry.ts. - If the app should be reachable by a NIP-19 identifier, map that identifier to it in
src/pages/NIP19Page.tsx. - Run
npm run test.
A minimal app:
import { useEffect } from 'react';
import { AppBody, AppLayout, AppToolbar } from '@/components/os/AppChrome';
import type { AppProps } from '@/os/types';
export default function ExampleApp({ setTitle }: AppProps) {
useEffect(() => setTitle('Example'), [setTitle]);
return (
<AppLayout>
<AppToolbar>
<span className="text-[13px] font-medium">Example</span>
</AppToolbar>
<AppBody className="p-4">…</AppBody>
</AppLayout>
);
}
The nine apps
| App | id |
Params | Notes |
|---|---|---|---|
| Feed | feed |
— | kind 1 timeline, Following/Global, composer (⌘↵ publishes) |
| Profile | profile |
pubkey, relays? |
kind 0 metadata, the author's notes, follow/unfollow |
| Note | notes |
id?, relays? |
One note and its replies, or a blank local draft when id is absent. Not a singleton |
| Reader | articles |
pubkey?, identifier?, kind?, relays? |
NIP-23 long-form, react-markdown, NIP-84 highlights |
| Bookmarks | bookmarks |
— | NIP-51 kind 10003 list — bookmarked notes and articles |
| Web Bookmarks | web-bookmarks |
— | NIP-B0 kind 39701 — one addressable event per saved URL |
| Relays | relays |
— | Connection state, subscription count, measured latency |
| Settings | settings |
— | Theme, relay list, Blossom servers, account, session |
| About | about |
— | What this is, the app list, the shortcuts |
Web bookmarks are one event per URL, not a list
Unlike a NIP-51 list, each NIP-B0 web bookmark (kind 39701) is its own addressable event —
the d tag is the URL itself (scheme stripped for https, see bookmarkDTag in
src/hooks/useWebBookmarks.ts). Removing one publishes a NIP-09 kind 5 deletion request,
which relays are free to ignore, so the client also drops it from its own query cache
rather than trusting a refetch to reflect it.
Highlighting selects against the DOM, not the markdown source
HighlightLayer (src/apps/articles/HighlightLayer.tsx) tracks window.getSelection()
against the rendered article, not the raw markdown — the highlighted text saved to a kind
9802 event is whatever that Selection's .toString() returns, i.e. the plain-text content
the reader actually saw, not markdown syntax.
Bookmarks are one whole-list replacement, like follow lists
kind 10003 is a replaceable event: publishing it replaces the entire list. useToggleBookmark
(src/hooks/useBookmarks.ts) therefore reads the current list back before publishing an
update, the same trap follow lists have.
Follow lists are a whole-list replacement
kind 3 replaces the entire contact list. The follow button therefore reads the current list back before writing, or the edit would silently drop everyone else.
Relay latency is a real round trip
A WebSocket gives the browser no ping, so the Relays app times an actual REQ/EOSE
cycle ({ kinds: [1], limit: 1 }, 5s timeout). It is the only honest number available.
useRelayStatus samples socket state once a second — sockets have no change event to
subscribe to — and feeds both the Relays app and the menu bar indicator, so the two can
never disagree.
A closed socket is the resting state, not a fault: relays are opened on demand and dropped after idling. That is why nothing turns red at "0 connected"; only a connection that keeps trying to establish itself gets an amber dot.