echoed/src-tauri/src/lib.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

2024-11-27 00:22:53 +00:00
use commands::auth::*;
use data::AppState;
2024-11-23 21:07:46 +00:00
use reqwest_cookie_store::CookieStoreMutex;
use std::sync::Arc;
use tauri::{async_runtime::Mutex, Manager};
2024-11-27 00:22:53 +00:00
mod commands;
2024-11-23 21:07:46 +00:00
mod data;
mod error;
2024-11-27 00:22:53 +00:00
mod prelude;
2024-11-23 21:07:46 +00:00
#[macro_use]
extern crate tauri;
#[cfg_attr(mobile, mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
2024-11-27 00:22:53 +00:00
.plugin(tauri_plugin_http::init())
2024-11-23 21:07:46 +00:00
.plugin(tauri_plugin_shell::init())
2024-11-27 00:22:53 +00:00
.invoke_handler(tauri::generate_handler![authenticate, is_authenticated])
2024-11-23 21:07:46 +00:00
.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());
2024-11-27 00:22:53 +00:00
let client = tauri_plugin_http::reqwest::Client::builder()
2024-11-23 21:07:46 +00:00
.cookie_provider(jar.clone())
.build()?;
// store app state
2024-11-27 00:22:53 +00:00
app.manage(Mutex::new(AppState { client, jar }));
2024-11-23 21:07:46 +00:00
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}