Home Tab + Tauri backend

This commit is contained in:
2025-12-28 09:01:26 +01:00
commit 896841e1c0
85 changed files with 1533 additions and 0 deletions

42
src-tauri/src/home.rs Normal file
View File

@@ -0,0 +1,42 @@
use easy_nostr::EasyNostr;
use serde::Serialize;
// Diese Struktur ist für den Transport zum Frontend (JSON)
#[derive(Serialize)]
pub struct LocalPost {
pub content: String,
pub author: String,
pub created_at: u64,
}
#[tauri::command]
pub async fn fetch_nostr_posts() -> Result<Vec<LocalPost>, String> {
// 1. Verbindung aufbauen
let easy = EasyNostr::new("nsec1...")
.await
.map_err(|e| e.to_string())?;
// 2. Relays hinzufügen
easy.add_relays(vec![
"wss://relay.damus.io",
"wss://nos.lol",
"wss://relay.snort.social",
])
.await
.map_err(|e| e.to_string())?;
// 3. Posts von der Library holen
let raw_posts = easy.get_random_posts().await.map_err(|e| e.to_string())?;
// 4. Mappen: Library-Typ -> Unser serialisierbarer Typ
let mapped_posts = raw_posts
.into_iter()
.map(|p| LocalPost {
content: p.content,
author: p.author.to_string(),
created_at: p.created_at.as_secs(), // Hier geändert von as_u64()
})
.collect();
Ok(mapped_posts)
}

10
src-tauri/src/lib.rs Normal file
View File

@@ -0,0 +1,10 @@
mod home;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![home::fetch_nostr_posts])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View File

@@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
marstemedia_lib::run()
}