Argh
This commit is contained in:
parent
51c76921a0
commit
bb7d09d1ef
6 changed files with 297 additions and 98 deletions
|
@ -1,18 +1,12 @@
|
|||
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>);
|
||||
mod data_door;
|
||||
|
||||
impl easy::Handler for Collector {
|
||||
fn write(&mut self, data: &[u8]) -> Result<usize, easy::WriteError> {
|
||||
self.0.extend_from_slice(data);
|
||||
Ok(data.len())
|
||||
}
|
||||
}
|
||||
use data_door::DoorState;
|
||||
|
||||
struct AppState {
|
||||
db: Connection,
|
||||
|
@ -58,40 +52,19 @@ 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.ssl_cainfo_blob(include_bytes!("isrg-root-x1.pem"))
|
||||
.map_err(|_| ())?;
|
||||
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<(), ()> {
|
||||
println!("Hi");
|
||||
let state = state.lock().await;
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = rand::thread_rng();
|
||||
let store: Store = store.try_into()?;
|
||||
state.db.execute(
|
||||
"INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||
(
|
||||
rng.random::<i64>(),
|
||||
rng.gen::<i64>(),
|
||||
store,
|
||||
state.acc,
|
||||
Utc::now().timestamp(),
|
||||
|
@ -114,9 +87,9 @@ async fn count(state: State<'_, Mutex<AppState>>) -> Result<String, ()> {
|
|||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let mut rng = rand::rng();
|
||||
let mut rng = rand::thread_rng();
|
||||
let db = Connection::open_in_memory().expect("Failed to create DB.");
|
||||
let acc = rng.random::<i64>();
|
||||
let acc = rng.gen::<i64>();
|
||||
db.execute(
|
||||
"CREATE TABLE swap (
|
||||
rand INTEGER,
|
||||
|
@ -129,15 +102,20 @@ pub fn run() {
|
|||
)
|
||||
.unwrap();
|
||||
let state = AppState { db, acc };
|
||||
let door = DoorState::new();
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.setup(|app| {
|
||||
// app.manage(Mutex::new(door));
|
||||
app.manage(Mutex::new(state));
|
||||
Ok(())
|
||||
})
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
swap, count, pull_data
|
||||
swap,
|
||||
count,
|
||||
data_door::pull_data,
|
||||
data_door::push_data,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue