main.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Prevents additional console window on Windows in release, DO NOT REMOVE!!
  2. #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
  3. // fn main() {
  4. // app_lib::run();
  5. // }
  6. fn main() {
  7. tauri::Builder::default()
  8. .invoke_handler(tauri::generate_handler![
  9. greet,
  10. receive_messages,
  11. send_message
  12. ])
  13. .run(tauri::generate_context!())
  14. .expect("error while running tauri application");
  15. }
  16. #[tauri::command]
  17. fn greet(name: &str) -> String {
  18. format!("Hello, {}!", name)
  19. }
  20. #[tauri::command]
  21. fn receive_messages(hostname: &str, password: &str) -> Vec<(u128, String, String, String)> {
  22. let msges = client_shared::utils::rx_messages(hostname, password, 2);
  23. let Ok(msges) = msges else {
  24. return vec![];
  25. };
  26. let mut out = vec![];
  27. for msg in msges {
  28. out.push((msg.time, msg.channel, msg.sender, msg.content));
  29. }
  30. out
  31. }
  32. // TODO: Handle errors
  33. #[tauri::command]
  34. fn send_message(channel: &str, sender: &str, content: &str, hostname: &str, password: &str) {
  35. let message = client_shared::message::Message::new(sender, content, channel);
  36. let _ = client_shared::utils::tx_message(hostname, password, 2, message);
  37. }