From 7c4ca73f686f9d76bac1dc8eafe661a343b443a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bianca=20F=C3=BCrstenau?= Date: Sun, 9 Feb 2025 18:57:46 +0100 Subject: [PATCH] Foo --- src-tauri/Cargo.lock | 94 ++++++++++++++++++++++++++++++++++++++++++ src-tauri/Cargo.toml | 2 + src-tauri/build.rs | 2 +- src-tauri/rustfmt.toml | 3 ++ src-tauri/src/lib.rs | 58 ++++++++++++++++++++++---- src-tauri/src/main.rs | 2 +- src/main.js | 2 +- 7 files changed, 151 insertions(+), 12 deletions(-) create mode 100644 src-tauri/rustfmt.toml diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index b9e3592..c0726da 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -287,12 +287,14 @@ name = "bkbh" version = "0.1.0" dependencies = [ "chrono", + "curl", "rand 0.9.0", "rusqlite", "serde", "serde_json", "tauri", "tauri-build", + "tauri-plugin-fs", "tauri-plugin-opener", "tokio", ] @@ -697,6 +699,36 @@ dependencies = [ "syn 2.0.98", ] +[[package]] +name = "curl" +version = "0.4.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9fb4d13a1be2b58f14d60adba57c9834b78c62fd86c3e76a148f732686e9265" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "curl-sys" +version = "0.4.78+curl-8.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eec768341c5c7789611ae51cf6c459099f22e64a5d5d0ce4892434e33821eaf" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "windows-sys 0.52.0", +] + [[package]] name = "darling" version = "0.20.10" @@ -2047,6 +2079,18 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libz-sys" +version = "1.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9b68e50e6e0b26f672573834882eb57759f6db9b3be2ea3c35c91188bb4eaa" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linux-raw-sys" version = "0.4.15" @@ -2517,6 +2561,24 @@ dependencies = [ "pathdiff", ] +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "openssl-sys" +version = "0.9.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b22d5b84be05a8d6947c7cb71f7c849aa0f112acd4bf51c2a7c1c988ac0a9dc" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "option-ext" version = "0.2.0" @@ -3311,6 +3373,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "schemars" version = "0.8.21" @@ -3944,6 +4015,29 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-fs" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a1edf18000f02903a7c2e5997fb89aca455ecbc0acc15c6535afbb883be223" +dependencies = [ + "anyhow", + "dunce", + "glob", + "percent-encoding", + "schemars", + "serde", + "serde_json", + "serde_repr", + "tauri", + "tauri-plugin", + "tauri-utils", + "thiserror 2.0.11", + "toml 0.8.20", + "url", + "uuid", +] + [[package]] name = "tauri-plugin-opener" version = "2.2.5" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b1f2ac9..5c22be1 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -26,3 +26,5 @@ rusqlite = {version = "^0.33", features = ["backup", "bundled"] } rand = {version = "^0.9"} chrono = {version = "^0.4"} tokio = {version = "^1.43"} +tauri-plugin-fs = "2" +curl = {version = "^0.4"} diff --git a/src-tauri/build.rs b/src-tauri/build.rs index d860e1e..c1ea373 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -1,3 +1,3 @@ fn main() { - tauri_build::build() + tauri_build::build() } diff --git a/src-tauri/rustfmt.toml b/src-tauri/rustfmt.toml new file mode 100644 index 0000000..f4b1b83 --- /dev/null +++ b/src-tauri/rustfmt.toml @@ -0,0 +1,3 @@ +max_width = 80 +hard_tabs = true +tab_spaces = 8 diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index dd34520..b44ac29 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,8 +1,18 @@ -use rusqlite::{Connection, ToSql, types::ToSqlOutput}; -use rand::prelude::*; -use tokio::sync::Mutex; -use tauri::{Manager, State}; use chrono::offset::Utc; +use curl::{easy, easy::Easy2}; +use rand::prelude::*; +use rusqlite::{types::ToSqlOutput, Connection, ToSql}; +use tauri::{Manager, State}; +use tokio::sync::Mutex; + +struct Collector(Vec); + +impl easy::Handler for Collector { + fn write(&mut self, data: &[u8]) -> Result { + self.0.extend_from_slice(data); + Ok(data.len()) + } +} struct AppState { db: Connection, @@ -48,9 +58,31 @@ impl ToSql for Store { } } +#[tauri::command] +async fn pull_data() -> Result { + let mut client = Easy2::new(Collector(Vec::new())); + client.custom_request("PROPFIND").map_err(|_| ())?; + client.url("https://cloud.seebruecke.org/public.php/webdav/data/") + .map_err(|_| ())?; + client.username(include_str!("cloud_user.txt")); + client.http_auth(easy::Auth::new().auto(true)); + client.perform().map_err(|_| ())?; + let content = client.get_ref(); + Ok(String::from_utf8_lossy(&content.0).to_string()) +} + +#[tauri::command] +async fn push_data() -> Result<(), ()> { + let mut client = Easy2::new(Collector(Vec::new())); + Ok(()) +} + // Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ #[tauri::command] -async fn swap(store: &str, state: State<'_, Mutex>) -> Result<(), ()> { +async fn swap( + store: &str, + state: State<'_, Mutex>, +) -> Result<(), ()> { let state = state.lock().await; let mut rng = rand::rng(); let store: Store = store.try_into()?; @@ -63,7 +95,8 @@ async fn swap(store: &str, state: State<'_, Mutex>) -> Result<(), ()> Utc::now().timestamp(), false, ), - ).map_err(|_| ())?; + ) + .map_err(|_| ())?; Ok(()) } @@ -91,12 +124,19 @@ pub fn run() { cancellation BOOL )", (), - ).unwrap(); + ) + .unwrap(); let state = AppState { db, acc }; tauri::Builder::default() - .setup(|app| {app.manage(Mutex::new(state)); Ok(())}) + .plugin(tauri_plugin_fs::init()) + .setup(|app| { + app.manage(Mutex::new(state)); + Ok(()) + }) .plugin(tauri_plugin_opener::init()) - .invoke_handler(tauri::generate_handler![swap, count]) + .invoke_handler(tauri::generate_handler![ + swap, count, pull_data + ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 1ef1b2d..4d73f4d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,5 +2,5 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { - bkbh_lib::run() + bkbh_lib::run() } diff --git a/src/main.js b/src/main.js index d24ec47..85db6a0 100644 --- a/src/main.js +++ b/src/main.js @@ -9,7 +9,7 @@ let cntMsgEl; async function swap(s) { invoke("swap", { store: s }); - cntMsgEl.textContent = await invoke("count", {}); + cntMsgEl.textContent = await invoke("pull_data", {}); } window.addEventListener("DOMContentLoaded", () => {