useHostData
HOOK

HOOKS & API / TELEMETRY

useHostData

Subscribe directly to live read-only macOS telemetry: wall clock, calendar, CPU/memory/network performance, and battery state. Synchronous on the first frame, reactive on updates, and requires zero manifest permissions.

Signature#

SIGNATURE
const data = useHostData<SnapshotType>(service, fallback, params?);

Parameters#

servicestringRequired
Read-only service name: "clock", "calendar", "system", or "battery".
fallbackTRequired
Initial fallback object returned before a snapshot arrives (also infers the return type T).
paramsobjectOptional
Optional service parameters (usually omitted).

Available Read-Only Services#

"clock" — Live Wall Clock (every second)#

hournumber0–23
Current hour (24-hour clock).
minutenumber0–59
Current minute.
secondnumber0–59
Current second.
monthnumber1–12
Current month.
daynumber1–31
Day of month.
weekdaynumber1–7
Weekday (1 = Sunday through 7 = Saturday).
weekOfYearnumberLive
Week number of the current year.
timeZonestringLive
Active IANA time zone (e.g. "America/Los_Angeles").
citiesobject[]Optional
Configured world clock city entries.

"calendar" — Calendar Info (every 30s / midnight)#

yearnumberLive
Current Gregorian year (e.g. 2026).
monthnumber1–12
Current month.
todaynumber1–31
Today's day number.
weekdaynumber1–7
Today's weekday (1 = Sunday ... 7 = Saturday).
daysInMonthnumber28–31
Total days in the current month.
firstWeekdaynumber1–7
Weekday of the 1st of the month (useful for 7-column calendar grids).
systemFirstWeekdaynumber1–7
macOS user preference for the first day of the week.

"system" — Mac Performance Telemetry (~every 3s)#

cpunumber0–100
CPU utilization percentage.
cpuHistorynumber[]Array
Recent CPU samples ready to feed into Chart.
gpunumber0–100
GPU utilization percentage.
memorynumber0–100
Memory utilization percentage.
memoryUsedstringString
Formatted memory used (e.g. "19.5 GB").
memoryTotalstringString
Formatted total installed memory (e.g. "32 GB").
memoryHistorynumber[]Array
Recent memory utilization history samples.
disknumber0–100
Main volume disk usage percentage.
diskAvailablestringString
Formatted available disk space.
diskTotalstringString
Formatted total disk capacity.
netDownstringString
Live download throughput (e.g. "4.8 MB/s").
netUpstringString
Live upload throughput (e.g. "320 KB/s").
tempnumberOptional
Thermal sensor reading when available.
tempLabelstringOptional
Formatted temperature label.
batterynumber0–100
Quick battery charge percentage.
batteryChargingbooleanLive
true while charging.

"battery" — Battery & Bluetooth Accessories (on change)#

percentnumber0–100
Mac battery charge percentage.
chargingbooleanFlag
true while actively charging.
externalPowerbooleanFlag
true when connected to a power adapter.
lowPowerbooleanFlag
true when macOS Low Power Mode is on.
statusstringString
Human-readable power status.
estimatestringString
Estimated time remaining or time until full.
healthPercentnumberOptional
Maximum battery capacity percentage.
cyclesnumberOptional
Total battery cycle count.
historynumber[]Array
Recent battery charge history samples.
accessoriesobject[]Array
Connected Bluetooth peripherals (AirPods, mouse, keyboard) with battery levels.

Example: Live System Monitor (CPU + Memory + Network)#

TSX
import React, { Chart, HStack, ProgressBar, Spacer, Text, VStack, useHostData, useWidget } from "deskset-react";

interface SysSnapshot {
  cpu: number;
  cpuHistory: number[];
  memory: number;
  memoryUsed: string;
  netDown: string;
  netUp: string;
}

const FALLBACK: SysSnapshot = {
  cpu: 24,
  cpuHistory: [18, 22, 20, 29, 25, 24, 21, 26],
  memory: 61,
  memoryUsed: "19.5 GB",
  netDown: "2.4 MB/s",
  netUp: "320 KB/s",
};

export default function SystemCard() {
  const { theme, t } = useWidget();
  const sys = useHostData<SysSnapshot>("system", FALLBACK);

  return (
    <VStack
      maxWidth={true}
      maxHeight={true}
      padding={16}
      spacing={10}
      background={theme.isPure ? "clear" : "theme.card"}
      cornerRadius={theme.isPure ? 0 : theme.corner}
      clip={!theme.isPure}
    >
      <HStack alignment="center">
        <Text fontSize={13} fontWeight="semibold" color="theme.secondary">
          {t("系统状态", "System")}
        </Text>
        <Spacer />
        <Text fontSize={12} color="theme.secondary" monospacedDigits>
          {`↓ ${sys.netDown}  ↑ ${sys.netUp}`}
        </Text>
      </HStack>

      <HStack spacing={12} alignment="center">
        <Text fontSize={26} fontWeight="bold" monospacedDigits>{`${Math.round(sys.cpu)}%`}</Text>
        <Chart kind="area" values={sys.cpuHistory} color="theme.accent" height={34} maxWidth={true} />
      </HStack>

      <VStack spacing={4} maxWidth={true}>
        <HStack>
          <Text fontSize={12} color="theme.secondary">{t("内存", "Memory")}</Text>
          <Spacer />
          <Text fontSize={12} color="theme.ink" monospacedDigits>{`${sys.memoryUsed} (${Math.round(sys.memory)}%)`}</Text>
        </HStack>
        <ProgressBar value={sys.memory} total={100} color="theme.blue" height={6} />
      </VStack>
    </VStack>
  );
}