Instances
A user can place the same widget twice — weather for London and for New York. Each placement has an instance id, and can have its own config, data and fetch.
| Platform | Instance id |
|---|---|
| Android | appWidgetId |
| iOS / macOS | The item the user picks in Edit Widget (TauriInstanceIntent) |
| Desktop window | instance of createWidgetWindow (default: window label) |
| Windows Widgets Board | Board widget id |
List placements
import { getActiveWidgets } from "tauri-plugin-widgets-api";
for (const w of await getActiveWidgets()) {
console.log(w.widgetId, w.instance, w.size);
}
Exact on Android (AppWidgetManager) and iOS (WidgetCenter; the Edit Widget choice comes
from the extension's last render). iOS maps WidgetKit kinds to widget ids only for providers
created with kind: (TauriWidgetProvider(…, kind: kind); the init-ios template does it). On desktop: open windows plus placements that rendered
in the last 48 h (macOS WidgetKit, Widgets Board).
Give a placement its own config or data
await setWidgetConfig(nycLayout, undefined, "weather", false, "nyc");
await setWidgetData("weather", { temp: 4 }, { instance: "nyc" });
A placement reads its own config:weather#nyc / data:weather#nyc first, then the
widget-wide ones. {{instance}} in text and in source.url gives every placement its own
request without per-placement configs:
{
"source": { "url": "https://api.example.com/weather?city={{instance}}" },
"small": { "type": "text", "content": "{{instance}}: {{data.temp}}°" }
}
Apple: the Edit Widget choice
Publish the choices, then use the instance provider in the extension (the init-ios /
init-macos template has MyInstanceWidget ready to uncomment):
await setWidgetInstances("weather", [
{ id: "ldn", title: "London" },
{ id: "nyc", title: "New York" },
]);
AppIntentConfiguration(
kind: "weather.instance",
intent: TauriInstanceIntent.self,
provider: TauriInstanceProvider(appGroup: appGroup, widgetId: "weather", kind: "weather.instance")
) { entry in TauriWidgetView(entry: entry) }
The picker lists the choices of every widget in the App Group; give different widgets distinct ids if they must not mix.