Hi, I wanted to build an app that requires me to spawn a window every x amount of time. The flow looks like:
- Window opens
- When event from the frontend (solid.js in my case, but id doesn't matter i guess) is send to the current window it closes
- After 10 seconds (doesn't matter, could be 2 hours) the window appears again
I have very little experience with Rust (though learning about it as much as I can). This is what I came up with but it doesn't work. Tauri terminates when I call .close() on the created window.
In addition I don't know how to handle waiting for an event before calling sleep. I am doing appWindow.emit("break-end") on the frontend.
Any suggestions / docs I could look at?
fn main() {
tauri::Builder::default()
.setup(|app| {
let handle = app.handle();
tauri::async_runtime::spawn(async move {
loop {
// Spawn window
let window = tauri::WindowBuilder::new(
&handle,
"app",
tauri::WindowUrl::App("index.html".into()),
)
.build()
.unwrap();
// I really would like to make this happen on an event from the solid app.
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
window.close().unwrap(); // This closes the whole app.
// Wait for 10 seconds before spawning another window.
tokio::time::sleep(tokio::time::Duration::from_secs(10)).await;
}
});
Ok(())
})
.run(tauri::generate_context!())
.unwrap();
}