aboutsummaryrefslogtreecommitdiff
path: root/src-tauri
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
parent051748771895bb040188221c3e4136878dbedb8a (diff)
downloadFlightCore-5ffb5c1d55397162a419945eb81b942fad6603fc.tar.gz
FlightCore-5ffb5c1d55397162a419945eb81b942fad6603fc.zip
. full code
Diffstat (limited to 'src-tauri')
-rw-r--r--src-tauri/Cargo.lock56
-rw-r--r--src-tauri/Cargo.toml1
-rw-r--r--src-tauri/src/main.rs34
3 files changed, 91 insertions, 0 deletions
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 3a3fb8e8..4081fd8d 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -61,6 +61,7 @@ dependencies = [
"serde_json",
"tauri",
"tauri-build",
+ "tokio",
]
[[package]]
@@ -1460,6 +1461,18 @@ dependencies = [
]
[[package]]
+name = "mio"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "713d550d9b44d89174e066b7a6217ae06234c10cb47819a88290d2b353c31799"
+dependencies = [
+ "libc",
+ "log",
+ "wasi 0.11.0+wasi-snapshot-preview1",
+ "windows-sys",
+]
+
+[[package]]
name = "native-tls"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2487,6 +2500,15 @@ dependencies = [
]
[[package]]
+name = "signal-hook-registry"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "siphasher"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2505,6 +2527,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]]
+name = "socket2"
+version = "0.4.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
+dependencies = [
+ "libc",
+ "winapi",
+]
+
+[[package]]
name = "soup2"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2968,10 +3000,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439"
dependencies = [
"bytes",
+ "libc",
"memchr",
+ "mio",
"num_cpus",
"once_cell",
+ "parking_lot 0.12.0",
"pin-project-lite",
+ "signal-hook-registry",
+ "socket2",
+ "tokio-macros",
+ "winapi",
+]
+
+[[package]]
+name = "tokio-macros"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
]
[[package]]
@@ -3210,6 +3260,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
+name = "wasi"
+version = "0.11.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
+
+[[package]]
name = "wasm-bindgen"
version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index afafa6e4..a07e4d24 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -18,6 +18,7 @@ tauri-build = { version = "1.0.0", features = [] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0", features = ["api-all"] }
+tokio = { version = "1", features = ["full"] }
[features]
# by default Tauri runs in production mode
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}")
+}