-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.rs
38 lines (29 loc) · 1.26 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod database;
mod state;
use state::{AppState, ServiceAccess};
use tauri::{State, Manager, AppHandle};
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn greet(app_handle: AppHandle, name: &str) -> String {
// Should handle errors instead of unwrapping here
app_handle.db(|db| database::add_item(name, db)).unwrap();
let items = app_handle.db(|db| database::get_all(db)).unwrap();
let items_string = items.join(" | ");
format!("Your name log: {}", items_string)
}
fn main() {
tauri::Builder::default()
.manage(AppState { db: Default::default() })
.invoke_handler(tauri::generate_handler![greet])
.setup(|app| {
let handle = app.handle();
let app_state: State<AppState> = handle.state();
let db = database::initialize_database(&handle).expect("Database initialize should succeed");
*app_state.db.lock().unwrap() = Some(db);
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}