React Widget SDK Quick Start
Build true native macOS SwiftUI desktop widgets using familiar TypeScript and React TSX. Deskset transpiles and executes your .tsx source directly — no Webpack, Vite, or esbuild step required.
1. How It Works: Direct TSX Execution#
Unlike WebView-based desktop widgets, Deskset never embeds a browser engine. Your TSX component executes inside a sandboxed JavaScriptCore VM and emits a lightweight element tree that the host maps straight to native macOS SwiftUI views:
- Readable index.tsx + deskpack.json
- Built-in Sucrase TSX Transpiler
- Sandboxed JavaScriptCore Runtime
- Native macOS SwiftUI Views & Animations
Key takeaways:
- No DOM or CSS: Do not use
<div>,<span>,document, orwindow. Import all UI components and hooks from"deskset-react". - No build black box: Every
.deskpackships readableindex.tsxsource so anyone can tweak and hot-reload widgets just like Rainmeter skins. - Zero-config networking & telemetry: Call useFetch for public HTTP(S) APIs or useHostData for live clock, calendar, system, and battery metrics with zero manifest allowlists or permissions.
2. Your First Widget in 5 Minutes#
Create a new draft in Widget Studio, or create deskpack.json, locales/ JSON files, and index.tsx in a local folder:
Step 1: Create deskpack.json#
{
"id": "com.you.water-counter",
"name": "Water Counter",
"nameZh": "喝水打卡",
"version": "1.0.0",
"description": "Track daily hydration on your desktop",
"descriptionZh": "在桌面记录每日喝水杯数",
"defaultLocale": "en",
"author": "@you",
"category": "productivity",
"icon": "drop.fill",
"sizes": ["small", "medium"],
"accentColor": "#0EA5E9",
"options": {
"goal": {
"type": "number",
"label": "每日目标(杯)",
"labelEn": "Daily Goal",
"default": 8,
"min": 1,
"max": 20,
"order": 1
}
}
}
Step 2: Add locales/ Translations#
Place BCP-47 JSON dictionaries inside locales/ (or click + → New Locale File in Widget Studio's File Explorer ⌘B) to keep your TSX clean and easily add more languages anytime:
locales/en.json:
{
"tapToAdd": "Tap +1",
"title": "Hydration",
"goalMet": "Goal met",
"remaining": "{n} to go"
}
locales/zh-Hans.json:
{
"tapToAdd": "点按 +1 杯",
"title": "今日喝水",
"goalMet": "目标达成",
"remaining": "还差 {n} 杯"
}
Step 3: Write index.tsx#
import React, {
Button, HStack, RingGauge, Spacer, Text, VStack,
useStorage, useWidget,
} from "deskset-react";
function todayKey(): string {
const d = new Date();
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
}
export default function WaterCounter() {
const { settings, theme, t, isPreview, match } = useWidget();
const goal = Math.max(1, Number(settings.goal) || 8);
const [record, setRecord] = useStorage("today", { day: todayKey(), count: 0 });
const count = isPreview ? 5 : (record.day === todayKey() ? record.count : 0);
const add = (delta: number) => {
setRecord({ day: todayKey(), count: Math.max(0, count + delta) });
};
const ringSize = match({ small: 96, medium: 112, default: 112 });
const ring = (
<RingGauge
value={count}
total={goal}
size={ringSize}
lineWidth={ringSize > 100 ? 11 : 10}
color="theme.accent"
centerText={`${count}`}
subText={`/ ${goal}`}
/>
);
return (
<VStack
maxWidth={true}
maxHeight={true}
background={theme.isPure ? "clear" : "theme.card"}
cornerRadius={theme.isPure ? 0 : theme.corner}
clip={!theme.isPure}
>
{match({
small: () => (
<VStack maxWidth={true} maxHeight={true} padding={14} alignment="center" spacing={8} onClick={() => add(1)}>
{ring}
<Text fontSize={12} color="theme.secondary">{t("tapToAdd")}</Text>
</VStack>
),
medium: () => (
<HStack maxWidth={true} maxHeight={true} padding={16} spacing={16} alignment="center">
{ring}
<VStack alignment="leading" spacing={6} maxWidth={true}>
<Text fontSize={13} color="theme.secondary">{t("title")}</Text>
<Text fontSize={22} fontWeight="bold" monospacedDigits>
{count >= goal ? t("goalMet") : t("remaining", { n: goal - count })}
</Text>
<Spacer />
<HStack spacing={8}>
<Button title="+1" icon="plus" variant="filled" color="theme.accent" onClick={() => add(1)} />
<Button icon="minus" variant="tinted" onClick={() => add(-1)} />
</HStack>
</VStack>
</HStack>
),
})}
</VStack>
);
}
3. Working in External IDEs with deskpack CLI#
Prefer VS Code, Cursor, or Zed? Use the zero-dependency deskpack CLI alongside deskset-react.d.ts for full TypeScript autocomplete:
# 1. Scaffold a new widget project (creates deskpack.json, index.tsx, and locales/)
npx deskpack init my-widget
# 2. Validate deskpack.json, index.tsx, locales/, and asset limits
npx deskpack validate ./my-widget
# 3. Package into a shareable .deskpack archive (keeps readable TSX & locales/)
npx deskpack build ./my-widget --out my-widget.deskpack
# 4. Unpack any community .deskpack into an editable source folder
npx deskpack unpack community-widget.deskpack ./editable-widget
4. Next Steps#
- Learn every manifest field and auto-generated settings control in deskpack.json.
- Master Light/Dark semantic tokens and Glass vs Minimal finishes in Styling & Theme.
- Explore
locales/_metametadata localization, bundledassets/, and sandbox limits in Assets, i18n & Debugging. - Jump directly to any Hook or Component from the left sidebar (
useWidget,useFetch,useStorage,RingGauge,Chart,Canvas, and more). - Working with Claude, ChatGPT, or Cursor? Copy the compact spec from AI Reference (llms.txt).