webui icon indicating copy to clipboard operation
webui copied to clipboard

webui_wait() returns when device goes to sleep.

Open thrombe opened this issue 1 year ago • 0 comments

Description

works as expected when running normally, but disconnects when device goes to sleep.

Expected behavior

webui should not disconnect when device goes to sleep.

Relevant Snippets

use std::{ffi::CStr, sync::Arc};
use webui_rs::webui;

#[derive(Clone)]
pub struct App {
    pub win: Arc<webui::Window>,
}
impl App {
    pub fn new() -> Self {
        Self {
            win: Arc::new(webui::Window::new()),
        }
    }

    pub async fn open_window(&self, url: String) -> anyhow::Result<()> {
        unsafe {
            let _ = webui::bindgen::webui_set_port(
                self.win.id,
                core::env!("WEBUI_PORT").parse().unwrap(),
            );
        }
        webui::set_timeout(3);
        self.win.bind("", |e| {
            dbg!(e.event_type as u32);
        });

        let s = self.clone();
        tokio::task::spawn_blocking(move || {
            s.win.show(url);
            webui::wait();
        })
        .await?;

        Ok(())
    }

    pub fn close(&self) {
        self.win.close();
    }
}

#[tokio::main]
async fn main() -> Result<()> {
    let port: u16 = core::env!("SERVER_PORT").parse().unwrap();
    let mut url = format!("http://localhost:{}/", port);

    let app = webui::App::new();

    tokio::select! {
        window = app.open_window(url) => {
            app.close();
            window?;
        }
    }

    Ok(())
}

Logs

[src/webui.rs:48:13] e.event_type as u32 = 2
[src/webui.rs:48:13] e.event_type as u32 = 2
[src/webui.rs:48:13] e.event_type as u32 = 0

Environment info

OS Version: Linux NixOS 24.05

Compiler Version: Rust 1.77.1

WebUI Version: 2.5.0-beta.1

thrombe avatar Jul 06 '24 10:07 thrombe