chore: Refactor code to use HashSet for account search results (#222)

This commit is contained in:
XIAO YU 2024-07-03 09:33:16 +09:00 committed by GitHub
parent 72da83d648
commit 4c323b9daa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 15 deletions

View File

@ -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", ());
}
}));

View File

@ -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()),
}