aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/main.rs
diff options
context:
space:
mode:
authorJeremy Chone <jeremy.chone@gmail.com>2022-06-20 12:43:09 -0700
committerJeremy Chone <jeremy.chone@gmail.com>2022-06-20 12:43:09 -0700
commit5ffb5c1d55397162a419945eb81b942fad6603fc (patch)
treee3ec46506ff1a94d939ef53ce018e10b29213df2 /src-tauri/src/main.rs
parent051748771895bb040188221c3e4136878dbedb8a (diff)
downloadFlightCore-5ffb5c1d55397162a419945eb81b942fad6603fc.tar.gz
FlightCore-5ffb5c1d55397162a419945eb81b942fad6603fc.zip
. full code
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r--src-tauri/src/main.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 65bb630c..464a5430 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -2,9 +2,43 @@
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
+use std::sync::{Arc, Mutex};
+use std::time::Duration;
+use tauri::{Manager, State};
+use tokio::time::sleep;
+
+#[derive(Default)]
+struct Counter(Arc<Mutex<i32>>);
fn main() {
tauri::Builder::default()
+ .setup(|app| {
+ let app_handle = app.app_handle();
+ tauri::async_runtime::spawn(async move {
+ loop {
+ sleep(Duration::from_millis(2000)).await;
+ println!("sending backend-ping");
+ app_handle.emit_all("backend-ping", "ping").unwrap();
+ }
+ });
+
+ Ok(())
+ })
+ .manage(Counter::default())
+ .invoke_handler(tauri::generate_handler![hello_world, add_count])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
+
+#[tauri::command]
+fn hello_world() -> String {
+ "Hello World!!!!".to_string()
+}
+
+#[tauri::command]
+fn add_count(num: i32, counter: State<'_, Counter>) -> String {
+ let mut val = counter.0.lock().unwrap();
+ *val += num;
+
+ format!("{val}")
+}