Refactor
This commit is contained in:
parent
934c704cbf
commit
bd40e5c8d8
4 changed files with 47 additions and 48 deletions
|
@ -5,13 +5,9 @@ use tauri::{Manager, State};
|
|||
use tokio::sync::Mutex;
|
||||
|
||||
mod data_door;
|
||||
mod app_state;
|
||||
|
||||
use data_door::DoorState;
|
||||
|
||||
struct AppState {
|
||||
db: Connection,
|
||||
acc: i64,
|
||||
}
|
||||
use app_state::AppState;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Store {
|
||||
|
@ -55,17 +51,19 @@ impl ToSql for Store {
|
|||
#[tauri::command]
|
||||
async fn swap(
|
||||
store: &str,
|
||||
acc: i64,
|
||||
state: State<'_, Mutex<AppState>>,
|
||||
) -> Result<(), ()> {
|
||||
let state = state.lock().await;
|
||||
let mut rng = rand::thread_rng();
|
||||
let store: Store = store.try_into()?;
|
||||
state.db.execute(
|
||||
"INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5)",
|
||||
"INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
|
||||
(
|
||||
rng.gen::<i64>(),
|
||||
store,
|
||||
state.acc,
|
||||
acc,
|
||||
state.id,
|
||||
Utc::now().timestamp(),
|
||||
false,
|
||||
),
|
||||
|
@ -86,26 +84,10 @@ async fn count(state: State<'_, Mutex<AppState>>) -> Result<String, ()> {
|
|||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let mut rng = rand::thread_rng();
|
||||
let db = Connection::open_in_memory().expect("Failed to create DB.");
|
||||
let acc = rng.gen::<i64>();
|
||||
db.execute(
|
||||
"CREATE TABLE swap (
|
||||
rand INTEGER,
|
||||
store INTEGER,
|
||||
account INTEGER,
|
||||
time INTEGER,
|
||||
cancellation BOOL
|
||||
)",
|
||||
(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AppState { db, acc };
|
||||
let door = DoorState::new();
|
||||
let state = AppState::new();
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.setup(|app| {
|
||||
app.manage(Mutex::new(door));
|
||||
app.manage(Mutex::new(state));
|
||||
Ok(())
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue