diff --git a/src-tauri/src/fns.rs b/src-tauri/src/fns.rs index 13ecf547..3f901d18 100644 --- a/src-tauri/src/fns.rs +++ b/src-tauri/src/fns.rs @@ -9,8 +9,8 @@ use tauri_nspanel::{ base::{id, nil}, foundation::{NSPoint, NSRect}, }, - ManagerExt, - objc::{class, msg_send, runtime::NO, sel, sel_impl}, panel_delegate, WebviewWindowExt, + objc::{class, msg_send, runtime::NO, sel, sel_impl}, + panel_delegate, ManagerExt, WebviewWindowExt, }; #[allow(non_upper_case_globals)] @@ -28,11 +28,8 @@ pub fn swizzle_to_menubar_panel(app_handle: &tauri::AppHandle) { let handle = app_handle.clone(); panel_delegate.set_listener(Box::new(move |delegate_name: String| { - match delegate_name.as_str() { - "window_did_resign_key" => { - let _ = handle.emit("menubar_panel_did_resign_key", ()); - } - _ => (), + if delegate_name.as_str() == "window_did_resign_key" { + let _ = handle.emit("menubar_panel_did_resign_key", ()); } })); diff --git a/src-tauri/src/nostr/relay.rs b/src-tauri/src/nostr/relay.rs index 401e39af..91843f14 100644 --- a/src-tauri/src/nostr/relay.rs +++ b/src-tauri/src/nostr/relay.rs @@ -19,7 +19,7 @@ pub struct Relays { #[tauri::command] #[specta::specta] -pub async fn get_relays(state: State<'_, Nostr>) -> Result { +pub async fn get_relays(state: State<'_, Nostr>) -> Result { let client = &state.client; // Get connected relays @@ -27,8 +27,8 @@ pub async fn get_relays(state: State<'_, Nostr>) -> Result { let connected_relays: Vec = list.into_keys().map(|url| url.to_string()).collect(); // Get NIP-65 relay list - let signer = client.signer().await.unwrap(); - let public_key = signer.public_key().await.unwrap(); + let signer = client.signer().await.map_err(|e| e.to_string())?; + let public_key = signer.public_key().await.map_err(|e| e.to_string())?; let filter = Filter::new() .author(public_key) .kind(Kind::RelayList) @@ -71,53 +71,50 @@ pub async fn get_relays(state: State<'_, Nostr>) -> Result { }) } } - Err(_) => Ok(Relays { - connected: connected_relays, - read: None, - write: None, - both: None, - }), + Err(e) => Err(e.to_string()), } } #[tauri::command] #[specta::specta] -pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result { +pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result { let client = &state.client; - if let Ok(status) = client.add_relay(relay).await { - if status { - println!("connecting to relay: {}", relay); - let _ = client.connect_relay(relay).await; - Ok(true) - } else { - Ok(false) + match client.add_relay(relay).await { + Ok(status) => { + if status { + println!("connecting to relay: {}", relay); + let _ = client.connect_relay(relay).await; + Ok(true) + } else { + Ok(false) + } } - } else { - Ok(false) + Err(e) => Err(e.to_string()), } } #[tauri::command] #[specta::specta] -pub async fn remove_relay(relay: &str, state: State<'_, Nostr>) -> Result { +pub async fn remove_relay(relay: &str, state: State<'_, Nostr>) -> Result { let client = &state.client; - if (client.remove_relay(relay).await).is_ok() { - let _ = client.disconnect_relay(relay).await; - Ok(true) - } else { - Ok(false) + match client.remove_relay(relay).await { + Ok(_) => { + let _ = client.disconnect_relay(relay).await; + Ok(true) + } + Err(e) => Err(e.to_string()), } } #[tauri::command] #[specta::specta] -pub fn get_bootstrap_relays(app: tauri::AppHandle) -> Result, ()> { +pub fn get_bootstrap_relays(app: tauri::AppHandle) -> Result, String> { let relays_path = app .path() .resolve("resources/relays.txt", BaseDirectory::Resource) - .expect("Bootstrap relays not found."); + .map_err(|e| e.to_string())?; - let file = std::fs::File::open(relays_path).unwrap(); + let file = std::fs::File::open(relays_path).map_err(|e| e.to_string())?; let lines = io::BufReader::new(file).lines(); let mut relays = Vec::new(); @@ -135,15 +132,15 @@ pub fn save_bootstrap_relays(relays: &str, app: tauri::AppHandle) -> Result<(), let relays_path = app .path() .resolve("resources/relays.txt", BaseDirectory::Resource) - .expect("Bootstrap relays not found."); + .map_err(|e| e.to_string())?; let mut file = fs::OpenOptions::new() .write(true) .open(relays_path) - .unwrap(); + .map_err(|e| e.to_string())?; match file.write_all(relays.as_bytes()) { Ok(_) => Ok(()), - Err(_) => Err("Cannot save bootstrap relays, please try again later.".into()), + Err(e) => Err(e.to_string()), } }