Initial commit

This commit is contained in:
Bianca Fürstenau 2025-02-09 08:22:57 +01:00
commit 96033b4b9f
15 changed files with 6300 additions and 0 deletions

5542
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

28
src-tauri/Cargo.toml Normal file
View file

@ -0,0 +1,28 @@
[package]
name = "bkbh"
version = "0.1.0"
description = "A Tauri App"
authors = ["Bianca Fürstenau"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "bkbh_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
rusqlite = {version = "^0.33", features = ["backup", "bundled"] }
rand = {version = "^0.9"}
chrono = {version = "^0.4"}
tokio = {version = "^1.43"}

3
src-tauri/build.rs Normal file
View file

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

90
src-tauri/src/lib.rs Normal file
View file

@ -0,0 +1,90 @@
use rusqlite::{Connection, ToSql, types::ToSqlOutput};
use rand::prelude::*;
use tokio::sync::Mutex;
use tauri::{Manager, State};
use chrono::offset::Utc;
struct AppState {
db: Connection,
acc: i64,
}
#[derive(Clone, Copy)]
enum Store {
Aldi,
Rewe,
}
impl TryFrom<&str> for Store {
type Error = ();
fn try_from(s: &str) -> Result<Self, Self::Error> {
match s {
"aldi" => Ok(Store::Aldi),
"rewe" => Ok(Store::Rewe),
_ => Err(()),
}
}
}
impl ToSql for Store {
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
match self {
Store::Aldi => 0.to_sql(),
Store::Rewe => 1.to_sql(),
}
}
}
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
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()?;
state.db.execute(
"INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5)",
(
rng.random::<i64>(),
store,
state.acc,
Utc::now().timestamp(),
false,
),
).map_err(|_| ())?;
Ok(())
}
#[tauri::command]
async fn count(state: State<'_, Mutex<AppState>>) -> Result<String, ()> {
let state = state.lock().await;
let mut stmt = state.db.prepare("SELECT COUNT(*) FROM swap").unwrap();
let mut rows = stmt.query([]).unwrap();
let row = rows.next().unwrap().unwrap();
let cnt: u64 = row.get_unwrap(0);
Ok(cnt.to_string())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let mut rng = rand::rng();
let db = Connection::open_in_memory().expect("Failed to create DB.");
let acc = rng.random::<i64>();
db.execute(
"CREATE TABLE swap (
rand INTEGER,
store INTEGER,
account INTEGER,
time INTEGER,
cancellation BOOL
)",
(),
).unwrap();
let state = AppState { db, acc };
tauri::Builder::default()
.setup(|app| {app.manage(Mutex::new(state)); Ok(())})
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![swap, count])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View file

@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
bkbh_lib::run()
}

33
src-tauri/tauri.conf.json Normal file
View file

@ -0,0 +1,33 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "bkbh",
"version": "0.1.0",
"identifier": "de.mathebau.bkbh",
"build": {
"frontendDist": "../src"
},
"app": {
"withGlobalTauri": true,
"windows": [
{
"title": "bkbh",
"width": 800,
"height": 600
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}