API

JavaScript API

Package: tauri-plugin-widgets-api. Types for the widget IR are generated from Rust (guest-js/generated/widget-types.ts) — do not hand-edit them.

import {
  setWidgetConfig,
  setWidgetConfigFromPath,
  createWidgetWindow,
  onWidgetAction,
  startWidgetUpdater,
} from "tauri-plugin-widgets-api";

Config and storage

FunctionPurpose
setWidgetConfig(config, group, widgetId, skipReload?, instance?)Push a full WidgetConfig. Returns ApplyOutcome (written, reload, transports, optional skip) — not a bare boolean. With instance, only that placement gets it (Instances)
setWidgetData(widgetId, data, { instance?, group?, skipReload? })Values for {{data.path}} without resending the layout (Remote data)
setWidgetState(widgetId, patch, { instance?, group?, skipReload? })Change local state ({{state.path}}) like a set tap: "$toggle", "$inc", "$dec", null removes a key, patch: null clears. Resolves with the merged state; emits widget-state-changed (Local state)
getWidgetState(widgetId, { instance?, group? })Merged local state: config state defaults, then the stored state
setWidgetConfigFromPath(path, group, widgetId, skipReload?, instance?)Read a WidgetConfig JSON file from disk, then push it like setWidgetConfig. Path must be readable by the app process (absolute or resolved resourceDir() / app-data). No network URLs. Needs widgets:allow-set-widget-config-from-path (included in widgets:default)
getWidgetTrace(group, { since? })Host delivery journal + receipt history (debug / WIDGET_DEBUG=1)
flushWidgetTrace()Flush journal to disk (desktop)
getWidgetConfig(group, widgetId, instance?)Read the stored config (a placement's own when instance is set)
setItems(key, value, group)Low-level key/value write shared with native widgets
getItems(key, group)Low-level key/value read
import { resourceDir, join } from "@tauri-apps/api/path";
import { setWidgetConfigFromPath } from "tauri-plugin-widgets-api";

const path = await join(await resourceDir(), "widgets", "weather.json");
await setWidgetConfigFromPath(path, "group.com.example.myapp", "weather");

Placements

FunctionPurpose
getActiveWidgets(group?)Widgets placed right now: { widgetId, instance?, size?, lastSeenMs? }
setWidgetInstances(widgetId, [{ id, title }], group?)Choices of the Apple Edit Widget sheet

Live activities

FunctionPurpose
startActivity(content, group?)iOS Live Activity / Android ongoing notification / desktop window. Returns { id, surface, pushToken? }
updateActivity(content, group?)Replace the content of a running activity
endActivity(id, dismissAfterMs?, { content?, dismissalPolicy?, group? })End it; content is the final state, dismissalPolicy "default" / "immediate" (dismissAfterMs wins)
listActivities()Ids still running
onActivityState(cb) / onActivityContent(cb)Native activity-state { id, state } and activity-content { id, content } events (no-op where the OS sends none)
getWidgetPushToken(group?)WidgetKit push token (hex) for server-driven widget reloads; null elsewhere
registerActivityTemplate(name, layout, group?)Store a layout on the device; requests with template: name send only data (null removes it)

Details: Live activities.

Timelines and Android pin

FunctionPurpose
reloadAllTimelines()Ask the host to reload widget timelines
reloadTimelines(ofKind)Reload a specific widget kind
setRegisterWidget(widgets)Register provider class names (Android)
requestWidget()Prompt the user to pin a widget (Android)

Desktop windows

Omit url to use the embedded renderer (widget.html inside the crate, served over widgetview). You do not copy that file into the app. Optional custom url and declarative-config caveats: Desktop webview.

FunctionPurpose
createWidgetWindow(config)Frameless transparent window; pass group, widgetId, size for the built-in renderer
closeWidgetWindow(label)Close a window created earlier
await createWidgetWindow({
  label: "weather",
  width: 280,
  height: 160,
  group: "group.com.example.myapp",
  widgetId: "weather",
  size: "small",
});

Actions

FunctionPurpose
widgetAction(action, payload?, opts?)Emit a widget-action from the host
onWidgetAction(callback)Subscribe to taps from button / link / list rows
pollPendingWidgetActions(group)Drain native-queued actions (Android fallback). The first call also tells the host JavaScript listens, so a tap that launched the app is kept until then and delivered once

Action payload: { action, payload?, ts, widgetId, group }.

Diagnostics

FunctionPurpose
reportReceipt(receipt)Native renderers report what they drew / skipped
getWidgetDiagnostics(group)Inspect latest receipts for a group

Updater

FunctionPurpose
startWidgetUpdater(builder, group, widgetId, options?)Periodically rebuild and push config; returns a stop function

See Updating data for WidgetKit reload budget notes.

Rust

Host-side API: Rust API · docs.rs.