pub struct Widget<R: Runtime> { /* private fields */ }desktop only.Implementations§
Source§impl<R: Runtime> Widget<R>
impl<R: Runtime> Widget<R>
Sourcepub fn set_widget_data(
&self,
widget_id: &str,
data: &Value,
instance: Option<&str>,
group: Option<&str>,
) -> Result<bool>
pub fn set_widget_data( &self, widget_id: &str, data: &Value, instance: Option<&str>, group: Option<&str>, ) -> Result<bool>
setWidgetData from Rust: store data for {{data.…}}, push it to open widget
windows and reload native widgets. Unchanged data is a no-op (Ok(false)).
group: None uses the configured default group.
Sourcepub fn register_poll_source<F>(
&self,
widget_id: &str,
interval: Duration,
poll: F,
)
pub fn register_poll_source<F>( &self, widget_id: &str, interval: Duration, poll: F, )
Call poll every interval (first call right away) and store the result as the
widget’s data (default group). Registering a widget id again replaces its source.
use tauri_plugin_widgets::WidgetExt;
app.widget().register_poll_source("cpu", std::time::Duration::from_secs(2), || {
serde_json::json!({ "load": 0.42 })
});Sourcepub fn register_listen_source<I>(&self, widget_id: &str, values: I)
pub fn register_listen_source<I>(&self, widget_id: &str, values: I)
Store every value values yields (a std::sync::mpsc::Receiver, any blocking
iterator) as the widget’s data until it ends or the source is replaced.
Sourcepub fn unregister_source(&self, widget_id: &str) -> bool
pub fn unregister_source(&self, widget_id: &str) -> bool
Stop a poll / listen source. A listen source stops at its next value.
Source§impl<R: Runtime> Widget<R>
impl<R: Runtime> Widget<R>
pub fn set_items(&self, key: &str, value: &str, group: &str) -> Result<bool>
pub fn get_items(&self, key: &str, group: &str) -> Result<Option<String>>
pub fn create_widget_window(&self, config: WidgetWindowConfig) -> Result<bool>
Sourcepub fn restore_windows(&self) -> usize
pub fn restore_windows(&self) -> usize
Reopen the widget windows that were open when the app last ran (closed with
close_widget_window = removed from the set; quitting the app keeps them).
plugins.widgets.restoreWindowsOnStart: true calls this at startup. Returns how
many windows were requested.
pub fn close_widget_window(&self, label: &str) -> Result<bool>
Sourcepub fn set_register_widget(&self, _widgets: Vec<String>) -> Result<bool>
pub fn set_register_widget(&self, _widgets: Vec<String>) -> Result<bool>
Register native widget provider ids.
| Platform | Behaviour |
|---|---|
| Android | stores fully-qualified provider class names |
| iOS / macOS | stores WidgetKit kind strings (advisory) |
| Desktop | no-op, accepted for API symmetry |
pub fn reload_all_timelines(&self) -> Result<bool>
pub fn reload_timelines(&self, of_kind: &str) -> Result<bool>
Sourcepub fn request_widget(&self) -> Result<bool>
pub fn request_widget(&self) -> Result<bool>
Request that the OS show the “add widget” / pin UI.
| Platform | Behaviour |
|---|---|
| Android | opens the pin-widget flow |
| iOS / macOS | no native pin API — returns Ok from the mobile bridge |
| Desktop | error — use Self::create_widget_window instead |
Sourcepub fn set_widget_config_from_path(
&self,
path: impl AsRef<Path>,
group: &str,
widget_id: &str,
skip_reload: bool,
) -> Result<ApplyOutcome>
pub fn set_widget_config_from_path( &self, path: impl AsRef<Path>, group: &str, widget_id: &str, skip_reload: bool, ) -> Result<ApplyOutcome>
Load a WidgetConfig JSON file from disk, then apply it like Self::set_widget_config.
pub fn set_widget_config( &self, config: &WidgetConfig, group: &str, widget_id: &str, skip_reload: bool, ) -> Result<ApplyOutcome>
Sourcepub fn data_changed(&self, group: &str, widget_id: &str, instance: Option<&str>)
pub fn data_changed(&self, group: &str, widget_id: &str, instance: Option<&str>)
setWidgetData changed {{data.…}}: rebuild what the host renders itself.
pub fn get_widget_config( &self, group: &str, widget_id: &str, ) -> Result<Option<WidgetConfig>>
Sourcepub fn poll_pending_actions(
&self,
group: &str,
) -> Result<Vec<WidgetActionEnvelope>>
pub fn poll_pending_actions( &self, group: &str, ) -> Result<Vec<WidgetActionEnvelope>>
Drain pending actions for a group. On macOS the whole read-drain-write runs under the App Group file lock the widget extension appends under.
pub fn report_receipt(&self, receipt: WidgetRenderReceipt) -> Result<bool>
pub fn get_widget_diagnostics( &self, group: &str, ) -> Result<Vec<WidgetRenderReceipt>>
Sourcepub fn mark_listener_ready(&self)
pub fn mark_listener_ready(&self)
JavaScript drains the queue itself: queued taps may be emitted from now on.
Sourcepub fn get_active_widgets(&self, group: &str) -> Result<Vec<ActiveWidget>>
pub fn get_active_widgets(&self, group: &str) -> Result<Vec<ActiveWidget>>
Open widget windows, plus placements that rendered recently (macOS WidgetKit extension, Windows Widgets Board) according to their receipts.
Sourcepub fn start_activity(
&self,
content: ActivityContent,
group: &str,
) -> Result<ActivityHandle>
pub fn start_activity( &self, content: ActivityContent, group: &str, ) -> Result<ActivityHandle>
Desktop surface, by plugins.widgets.activitySurface:
"island"(default): a black pill at the top centre of the primary display that wraps the notch on notched Macs and expands on hover ([island]);"window": a small always-on-top window in the top-right corner drawing the activity layout;"notification"(featurenotify, Linux / Windows): a system notification.
When no window can open, a system notification instead (feature notify).
pub fn update_activity( &self, content: ActivityContent, group: &str, ) -> Result<bool>
pub fn end_activity( &self, id: &str, dismiss_after_ms: Option<u64>, ) -> Result<bool>
Sourcepub fn can_promote_activities(&self) -> Result<bool>
pub fn can_promote_activities(&self) -> Result<bool>
Live Updates promotion is an Android gate; desktop activities need no permission.
pub fn open_activity_promotion_settings(&self) -> Result<bool>
Sourcepub fn activity_push_to_start_token(&self) -> Result<Option<String>>
pub fn activity_push_to_start_token(&self) -> Result<Option<String>>
Push-to-start is an ActivityKit (iOS) feature.
pub fn list_activities(&self) -> Result<Vec<String>>
Sourcepub fn activity_island(
&self,
expanded: Option<bool>,
focus: Option<&str>,
) -> Result<Option<Value>>
pub fn activity_island( &self, expanded: Option<bool>, focus: Option<&str>, ) -> Result<Option<Value>>
Island page → host: expand / collapse (hover, click) or bring a minimal activity to
the pill. Returns what the island shows (None without an island).