echoed/src-tauri/src/lib.rs
2024-11-27 00:22:53 +00:00

39 lines
1.2 KiB
Rust

use commands::auth::*;
use data::AppState;
use reqwest_cookie_store::CookieStoreMutex;
use std::sync::Arc;
use tauri::{async_runtime::Mutex, Manager};
mod commands;
mod data;
mod error;
mod prelude;
#[macro_use]
extern crate tauri;
#[cfg_attr(mobile, mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![authenticate, is_authenticated])
.setup(|app| {
// todo: load profile file, or create if it does not exist
// create reqwest client with cookie jar
// todo: load cookies into cookie jar
//? https://docs.rs/tauri/1.8.1/tauri/api/path/fn.app_config_dir.html
let jar = Arc::new(CookieStoreMutex::default());
let client = tauri_plugin_http::reqwest::Client::builder()
.cookie_provider(jar.clone())
.build()?;
// store app state
app.manage(Mutex::new(AppState { client, jar }));
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}