mirror of
https://github.com/lumehq/lume.git
synced 2025-03-29 11:11:43 +01:00
chore: Refactor code to use HashSet for account search results (#222)
This commit is contained in:
parent
72da83d648
commit
4c323b9daa
@ -27,11 +27,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", ());
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -3,6 +3,7 @@ use keyring_search::{Limit, List, Search};
|
||||
use nostr_sdk::prelude::*;
|
||||
use serde::Serialize;
|
||||
use specta::Type;
|
||||
use std::collections::HashSet;
|
||||
use std::time::Duration;
|
||||
use tauri::{EventTarget, Manager, State};
|
||||
use tauri_plugin_notification::NotificationExt;
|
||||
@ -22,24 +23,18 @@ pub struct Account {
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub fn get_accounts() -> Result<Vec<String>, String> {
|
||||
let search = Search::new().unwrap();
|
||||
let search = Search::new().map_err(|e| e.to_string())?;
|
||||
let results = search.by("Account", "nostr_secret");
|
||||
|
||||
match List::list_credentials(results, Limit::All) {
|
||||
Ok(list) => {
|
||||
let search: Vec<String> = list
|
||||
let accounts: HashSet<String> = list
|
||||
.split_whitespace()
|
||||
.map(|v| v.to_string())
|
||||
.filter(|v| v.starts_with("npub1"))
|
||||
.map(String::from)
|
||||
.collect();
|
||||
|
||||
let accounts: Vec<String> = search
|
||||
.into_iter()
|
||||
.collect::<std::collections::HashSet<_>>()
|
||||
.into_iter()
|
||||
.collect();
|
||||
|
||||
Ok(accounts)
|
||||
Ok(accounts.into_iter().collect())
|
||||
}
|
||||
Err(_) => Err("Empty.".into()),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user