Expand description
§tauri-plugin-widgets
A Tauri v2 plugin for building native widgets on Android, iOS, macOS, Windows, and Linux from a single JSON UI configuration.
Empty placeholders for Adaptive Cards are avoided when the rasterize
feature is enabled (chart/canvas/gauge/shape/zstack/gradients → PNG).
§Overview
-
Widget Config API — send a declarative
WidgetConfigdescribing layouts and elements. The native widget renders it using SwiftUI (Apple), RemoteViews (Android), or HTML/CSS (desktop). -
Data API — key-value storage shared with native widget extensions via the App Group shared container (Apple), SharedPreferences (Android), or JSON files (desktop).
-
Desktop widget windows — frameless, transparent Tauri webview windows that render the same JSON config as HTML/CSS.
§Architecture
The plugin acts as a library, not a builder. It does NOT compile or inject widget extensions at runtime. Instead, it provides:
- Rust side — commands for data storage and WidgetKit reload
- Swift Package (
swift/TauriWidgets) — public SwiftUI views and models that developers import into their own Widget Extension target - Templates (
templates/) — ready-to-use scripts and Swift files
This follows Apple’s guidelines: the extension is built by Xcode, signed with the developer’s certificate, and included in the app bundle at compile time.
§Quick Start (Rust)
tauri::Builder::default()
.plugin(tauri_plugin_widgets::init());§iOS Setup
- Open
gen/apple/*.xcodeprojin Xcode - File → New → Target → Widget Extension
- Add
swift/as a Local Swift Package dependency - Add
TauriWidgetslibrary to the Widget Extension target - Enable App Groups in both targets (App + Widget Extension)
- Use the template from
templates/ios-widget/MyWidget.swift
§macOS Setup (“Satellite Project”)
Tauri for macOS does not generate an .xcodeproj, so the widget
extension must be built as a separate Xcode project:
- Create
src-tauri/widget-extension/with an Xcode project containing a Widget Extension target - Add
swift/as a Local Swift Package dependency - Enable App Groups in both the main app entitlements and the widget extension entitlements
build-widget.shruns viabeforeBundleCommand(builds + signs.appex)bundle.macOS.filescopies the.appexintoContents/PlugIns/during a normaltauri build(Tauri nested-codesigns PlugIns)- Set
plugins.widgets.transport(appGroupwith Team ID, orwidgetContainerfor ad-hoc) andplugins.widgets.appGroup
§Rust API
Build a config with typed helpers (compile-checked, not executed here):
use tauri_plugin_widgets::models::{text, vstack, WidgetConfig};
let _cfg = WidgetConfig::small(vstack(vec![
text("72°").font_size(36.0).into(),
]));Then call WidgetExt::widget on an AppHandle to set_widget_config /
reload_all_timelines (requires a running Tauri app).
Re-exports§
pub use adaptive_card::to_adaptive_card;pub use adaptive_card::to_adaptive_card_for_size;pub use adaptive_card::TranspileResult;pub use apply::ApplyOutcome;pub use apply::ReloadOutcome;pub use apply::SkipReason;pub use config::TransportKind;pub use config::WidgetsPluginConfig;pub use error::Error;pub use error::Result;pub use receipt::SkippedElement;pub use receipt::WidgetRenderReceipt;pub use store::WidgetActionEnvelope;pub use trace::TraceEntry;pub use trace::TraceEvent;pub use trace::WidgetTrace;pub use transport::Receipt;pub use transport::Transport;pub use desktop::Widget;desktop
Modules§
- adaptive_
card - Adaptive Cards transpiler (Windows Widgets Board). IR → Adaptive Card 1.5 transpiler for Windows Widgets Board.
- apply
- Outcomes for
set_widget_config(written / reload / skip). Outcomes forset_widget_config— no silentOk(true). - capabilities
- Element × platform capability matrix. Platform capability matrix for widget IR elements.
- codegen
- TypeScript IR emitter (
gen-ts). Emit TypeScript IR types from an explicit RustIR_ELEMENTSspec (SoT with models). - config
- Plugin configuration (
plugins.widgetsintauri.conf.json). Plugin config fromtauri.conf.json→plugins.widgets. - desktop
desktop - error
- Plugin error type. Error types for the widget plugin.
- icons
- SF Symbol → Material / emoji resolve for non-Apple hosts. SF Symbol → cross-platform icon resolve (Material ligature + emoji fallback).
- image_
prefetch - Host-side remote image prefetch for WidgetKit / desktop store writes.
Prefetch remote
image.urlintodata:URIs for hosts that cannot fetch (WidgetKit). Android keeps its ownlocalPathpipeline — Rust prefetch is a no-op there so we do not inflate SharedPreferences / Binder with base64. - linux
Linux and linux - Linux desktop-widget pinning: X11
_NET_WM_*hints and optional gtk-layer-shell. - models
- Widget IR models (
WidgetConfig,WidgetElement, …). - normalize
- Host-side IR normalization (
textStyle→ points, semantic colors → adaptive hex). Host-side IR normalization before store write. - rasterize
- SVG / PNG helpers for Adaptive Cards fallbacks. SVG builders + optional PNG rasterize for Adaptive Cards Image data URIs.
- receipt
- Render receipts written by native / desktop surfaces. Cross-platform render receipts (diagnostics, not a critical path).
- snapshot
- Canonical layout dumps for snapshot tests. Canonical layout dump for core WidgetConfig snapshot tests.
- store
- Shared key-value store helpers and action envelopes. Shared storage contract for widget data across platforms.
- trace
- Host black-box journal (
WIDGET_DEBUG/ debug builds). Host-side black-box journal for widget delivery diagnostics. - transport
- macOS / desktop config transport selection. Apple host→widget transport: one driver, chosen by config (not runtime fan-out).
Traits§
- Widget
Ext - Extension trait for convenient access from any Tauri manager.
Functions§
- init
- Initialize the widgets plugin. Register it with
tauri::Builder::plugin().