Skip to main content

Widget

Struct Widget 

Source
pub struct Widget<R: Runtime> { /* private fields */ }
Available on desktop only.

Implementations§

Source§

impl<R: Runtime> Widget<R>

Source

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.

Source

pub fn register_poll_source<F>( &self, widget_id: &str, interval: Duration, poll: F, )
where F: FnMut() -> Value + Send + 'static,

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 })
});
Source

pub fn register_listen_source<I>(&self, widget_id: &str, values: I)
where I: IntoIterator<Item = Value>, I::IntoIter: Send + 'static,

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.

Source

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>

Source

pub fn set_items(&self, key: &str, value: &str, group: &str) -> Result<bool>

Source

pub fn get_items(&self, key: &str, group: &str) -> Result<Option<String>>

Source

pub fn create_widget_window(&self, config: WidgetWindowConfig) -> Result<bool>

Source

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.

Source

pub fn close_widget_window(&self, label: &str) -> Result<bool>

Source

pub fn set_register_widget(&self, _widgets: Vec<String>) -> Result<bool>

Register native widget provider ids.

PlatformBehaviour
Androidstores fully-qualified provider class names
iOS / macOSstores WidgetKit kind strings (advisory)
Desktopno-op, accepted for API symmetry
Source

pub fn reload_all_timelines(&self) -> Result<bool>

Source

pub fn reload_timelines(&self, of_kind: &str) -> Result<bool>

Source

pub fn request_widget(&self) -> Result<bool>

Request that the OS show the “add widget” / pin UI.

PlatformBehaviour
Androidopens the pin-widget flow
iOS / macOSno native pin API — returns Ok from the mobile bridge
Desktoperror — use Self::create_widget_window instead
Source

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.

Source

pub fn set_widget_config( &self, config: &WidgetConfig, group: &str, widget_id: &str, skip_reload: bool, ) -> Result<ApplyOutcome>

Source

pub fn data_changed(&self, group: &str, widget_id: &str, instance: Option<&str>)

setWidgetData changed {{data.…}}: rebuild what the host renders itself.

Source

pub fn get_widget_config( &self, group: &str, widget_id: &str, ) -> Result<Option<WidgetConfig>>

Source

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.

Source

pub fn report_receipt(&self, receipt: WidgetRenderReceipt) -> Result<bool>

Source

pub fn get_widget_diagnostics( &self, group: &str, ) -> Result<Vec<WidgetRenderReceipt>>

Source

pub fn mark_listener_ready(&self)

JavaScript drains the queue itself: queued taps may be emitted from now on.

Source

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.

Source

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" (feature notify, Linux / Windows): a system notification.

When no window can open, a system notification instead (feature notify).

Source

pub fn update_activity( &self, content: ActivityContent, group: &str, ) -> Result<bool>

Source

pub fn end_activity( &self, id: &str, dismiss_after_ms: Option<u64>, ) -> Result<bool>

Source

pub fn can_promote_activities(&self) -> Result<bool>

Live Updates promotion is an Android gate; desktop activities need no permission.

Source

pub fn open_activity_promotion_settings(&self) -> Result<bool>

Source

pub fn activity_push_to_start_token(&self) -> Result<Option<String>>

Push-to-start is an ActivityKit (iOS) feature.

Source

pub fn list_activities(&self) -> Result<Vec<String>>

Source

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).

Source

pub fn get_widget_trace( &self, group: &str, since_ms: Option<u64>, ) -> Result<WidgetTrace>

Source

pub fn flush_widget_trace(&self) -> Result<bool>

Auto Trait Implementations§

§

impl<R> !Freeze for Widget<R>

§

impl<R> !RefUnwindSafe for Widget<R>

§

impl<R> !UnwindSafe for Widget<R>

§

impl<R> Forget for Widget<R>

§

impl<R> Move for Widget<R>

§

impl<R> Send for Widget<R>
where AppHandle<R>: Send,

§

impl<R> Sync for Widget<R>
where AppHandle<R>: Sync,

§

impl<R> Unpin for Widget<R>
where AppHandle<R>: Unpin,

§

impl<R> UnsafeUnpin for Widget<R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.