Skip to content

Commit f1002c7

Browse files
committed
docs(rust): add example where stdout/err get processed
1 parent 9425a12 commit f1002c7

File tree

1 file changed

+19
-13
lines changed
  • examples/01_tauri_ws/src-tauri/src

1 file changed

+19
-13
lines changed

examples/01_tauri_ws/src-tauri/src/main.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,25 @@ fn main() {
2222

2323
tauri::async_runtime::spawn(async move {
2424
while let Some(event) = rx.recv().await {
25-
if let CommandEvent::Stdout(line) = event {
26-
if line.contains("tauri-server-port=") {
27-
let tokens: Vec<&str> = line.split("=").collect();
28-
let port_token = tokens[1].to_string();
29-
let port = port_token.trim();
30-
// println!("window.location.replace(window.location.href + '?sessionURL=ws://localhost:{}/ws')", port);
31-
let _ = main_window.eval(&format!("window.location.replace(window.location.href + '?sessionURL=ws://localhost:{}/ws')", port));
32-
}
33-
if line.contains("tauri-client-ready") {
34-
task::sleep(Duration::from_secs(2)).await;
35-
splashscreen_window.close().unwrap();
36-
main_window.show().unwrap();
37-
}
25+
match event {
26+
CommandEvent::Stdout(line) => {
27+
if line.contains("tauri-server-port=") {
28+
let tokens: Vec<&str> = line.split("=").collect();
29+
let port_token = tokens[1].to_string();
30+
let port = port_token.trim();
31+
// println!("window.location.replace(window.location.href + '?sessionURL=ws://localhost:{}/ws')", port);
32+
let _ = main_window.eval(&format!("window.location.replace(window.location.href + '?sessionURL=ws://localhost:{}/ws')", port));
33+
}
34+
if line.contains("tauri-client-ready") {
35+
task::sleep(Duration::from_secs(2)).await;
36+
splashscreen_window.close().unwrap();
37+
}
38+
},
39+
CommandEvent::Stderr(line) => {
40+
// Handle stderr output
41+
println!("Stderr: {}", line);
42+
},
43+
_ => {},
3844
}
3945
}
4046
});

0 commit comments

Comments
 (0)