1
0
Fork 0
esix-client/src-tauri/src/main.rs

43 lines
1.3 KiB
Rust
Raw Normal View History

2024-02-17 01:29:25 +00:00
#![feature(lazy_cell)]
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use r621::client::{Authentication, Client};
use tauri::State;
use tokio::sync::Mutex;
use std::sync::Arc;
use r621::prelude::Post;
#[tauri::command]
async fn get_posts(query: Option<String>, arcmut_esix_client: State<'_, Arc<Mutex<Client>>>) -> anyhow::Result<Vec<Post>, String> {
let mut esix_client = arcmut_esix_client.lock().await;
match esix_client.list_posts(None, query, None).await {
Ok(res) => {
return Ok(res);
}
Err(err) => {
eprintln!("{err}");
return Err(format!("{err}"));
}
}
}
#[tokio::main]
async fn main() {
let user_agent = "eSixClient/1.0 (by pixelhunter on e621)";
let auth = Authentication::Authorized {
username: "pixelhunter",
apikey: "P4pzvnfLSjhQdgCmMfZ8HwUy"
};
let esix_client = Client::new(auth, user_agent).expect("Could not create esix client");
let arcmut_esix_client = Arc::new(Mutex::new(esix_client));
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![get_posts])
.manage(arcmut_esix_client.clone())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}