INNER CODE UNIT · Rust

spawn_wsl_monitor

owu/wsl-dashboard · src/app/tasks/mod.rs:25

pub fn spawn_wsl_monitor(app_handle: slint::Weak<AppWindow>, app_state: Arc<Mutex<AppState>>) {
    tokio::spawn(async move {
        let mut interval = tokio::time::interval(std::time::Duration::from_secs(5));
        interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
        loop {
            interval.tick().await;
            let ah = app_handle.clone();
            let as_ptr = app_state.clone();
            let _ = slint::invoke_from_event_loop(move || {
                if let Some(app) = ah.upgrade() {
                    let is_visible = app.get_is_window_visible();
                    // Only refresh if the Home tab (index 0) is selected to save resources
                    if app.get_selected_tab() == 0 {
                        let as_ptr_res = as_ptr.clone();
                        tokio::spawn(async move {
                            if crate::ui::data::should_refresh_wsl("periodic trigger", is_visible) {
                                let dashboard = {
                                    let state = as_ptr_res.lock().await;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…