Skip to content

Commit

Permalink
feat: sort resolved addresses in backend (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
hrzlgnm committed Mar 6, 2024
1 parent a185e77 commit 5e38ab9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use log::LevelFilter;
use mdns_sd::{ServiceDaemon, ServiceEvent};
use serde::{Deserialize, Serialize};
use std::{
collections::HashSet,
net::IpAddr,
sync::{Arc, Mutex},
};
Expand All @@ -28,7 +27,7 @@ struct ResolvedService {
instance_name: String,
hostname: String,
port: u16,
addresses: HashSet<IpAddr>,
addresses: Vec<IpAddr>,
}

#[tauri::command]
Expand All @@ -43,11 +42,14 @@ fn resolve_service(service_type: String, state: State<Daemon>) -> Vec<ResolvedSe
while let Ok(event) = receiver.recv() {
match event {
ServiceEvent::ServiceResolved(info) => {
let mut sorted_addresses: Vec<IpAddr> =
info.get_addresses().clone().drain().collect();
sorted_addresses.sort();
result.push(ResolvedService {
instance_name: info.get_fullname().into(),
hostname: info.get_hostname().into(),
port: info.get_port(),
addresses: info.get_addresses().clone(),
addresses: sorted_addresses,
});
}
ServiceEvent::SearchStarted(_) => {
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashSet, net::IpAddr};
use std::net::IpAddr;

use leptos::{html::Input, *};
use serde::{Deserialize, Serialize};
Expand All @@ -24,7 +24,7 @@ struct ResolvedService {
instance_name: String,
hostname: String,
port: u16,
addresses: HashSet<IpAddr>,
addresses: Vec<IpAddr>,
}
type ResolvedServices = Vec<ResolvedService>;

Expand Down

0 comments on commit 5e38ab9

Please sign in to comment.