This commit is contained in:
Bianca Fürstenau 2025-02-09 18:57:46 +01:00
parent 9609a80f7f
commit 7c4ca73f68
7 changed files with 151 additions and 12 deletions

94
src-tauri/Cargo.lock generated
View file

@ -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"

View file

@ -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"}

View file

@ -1,3 +1,3 @@
fn main() {
tauri_build::build()
tauri_build::build()
}

3
src-tauri/rustfmt.toml Normal file
View file

@ -0,0 +1,3 @@
max_width = 80
hard_tabs = true
tab_spaces = 8

View file

@ -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<u8>);
impl easy::Handler for Collector {
fn write(&mut self, data: &[u8]) -> Result<usize, easy::WriteError> {
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<String, ()> {
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<AppState>>) -> Result<(), ()> {
async fn swap(
store: &str,
state: State<'_, Mutex<AppState>>,
) -> 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<AppState>>) -> 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");
}

View file

@ -2,5 +2,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
bkbh_lib::run()
bkbh_lib::run()
}

View file

@ -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", () => {