Skip to main content

on_theme_change

Function on_theme_change 

Source
pub fn on_theme_change(
    callback: impl Fn(ThemeChangeEvent) + Send + 'static,
) -> Result<ThemeSubscription>
Expand description

Start watching for OS theme changes.

The callback is invoked on a background thread whenever the OS theme changes. To marshal events to your UI thread, send them through a channel:

use std::sync::mpsc;
use native_theme::watch::ThemeChangeEvent;

let (tx, rx) = mpsc::channel();
let _watcher = native_theme::watch::on_theme_change(move |event| {
    let _ = tx.send(event);
})?;

// On UI thread:
// match rx.try_recv() {
//     Ok(ThemeChangeEvent::Changed) => { /* re-read theme */ }
//     _ => {}
// }

ยงErrors

Returns Error::WatchUnavailable if no platform-specific backend is available for the current desktop environment or platform.