chore: senior-review cleanup pass
- Remove Gemini's committed update_*.py regex-surgery scripts - Drop unused iroh-tickets dependency (hand-rolled ticket is used instead) - Replace ToString antipattern with Display impl on PeerSpeakTicket - Route debug log to XDG state/cache dir instead of hardcoded /home path - Clear all compiler + clippy warnings (unused imports, collapsible ifs, redundant pattern matching, missing Default) Builds clean with zero warnings. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+2
-2
@@ -4,7 +4,7 @@ use crate::audio::pw_cli::{AudioDevice, enumerate_audio_devices};
|
||||
use crate::config::AppConfig;
|
||||
|
||||
use iced::widget::{
|
||||
container, column, row, text, button, text_input, scrollable, slider, checkbox, pick_list, Column, Space,
|
||||
container, column, row, text, button, text_input, scrollable, slider, checkbox, pick_list, Column,
|
||||
};
|
||||
use iced::{
|
||||
Color, Background, Border, Element, Subscription, Task, Theme, Event, keyboard,
|
||||
@@ -143,7 +143,7 @@ pub fn run_gui() -> iced::Result {
|
||||
.run()
|
||||
}
|
||||
|
||||
fn subscription(state: &AppState) -> Subscription<AppMessage> {
|
||||
fn subscription(_state: &AppState) -> Subscription<AppMessage> {
|
||||
let core_sub = Subscription::run(core_subscription).map(AppMessage::UiEventReceived);
|
||||
let event_sub = iced::event::listen().map(AppMessage::EventOccurred);
|
||||
Subscription::batch(vec![core_sub, event_sub])
|
||||
|
||||
@@ -24,6 +24,12 @@ struct PlaybackState {
|
||||
thread: JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl Default for PipeWireBackend {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl PipeWireBackend {
|
||||
pub fn new() -> Self {
|
||||
pw::init();
|
||||
|
||||
+1
-2
@@ -1,10 +1,9 @@
|
||||
use peerspeak::network::{
|
||||
gossip::IrohGossipState,
|
||||
RoomState, PeerState, RoomEvent,
|
||||
RoomState, PeerState,
|
||||
};
|
||||
use iroh::{Endpoint, endpoint::presets};
|
||||
use iroh_gossip::net::Gossip;
|
||||
use std::sync::Arc;
|
||||
use tokio::time::{self, Duration};
|
||||
|
||||
#[tokio::main]
|
||||
|
||||
+3
-5
@@ -29,13 +29,11 @@ impl AppConfig {
|
||||
}
|
||||
|
||||
pub fn load() -> Self {
|
||||
if let Some(path) = Self::config_path() {
|
||||
if let Ok(contents) = fs::read_to_string(&path) {
|
||||
if let Ok(config) = serde_json::from_str(&contents) {
|
||||
if let Some(path) = Self::config_path()
|
||||
&& let Ok(contents) = fs::read_to_string(&path)
|
||||
&& let Ok(config) = serde_json::from_str(&contents) {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
Self::default()
|
||||
}
|
||||
|
||||
|
||||
+20
-1
@@ -5,11 +5,30 @@ pub mod core;
|
||||
pub mod app;
|
||||
pub mod config;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
/// Resolves the log file path once: `$XDG_STATE_HOME/peerspeak/peerspeak.log`
|
||||
/// (via `dirs::state_dir`), falling back to the system temp dir. Computed lazily
|
||||
/// so we never hardcode a per-user path.
|
||||
fn log_path() -> &'static PathBuf {
|
||||
static LOG_PATH: OnceLock<PathBuf> = OnceLock::new();
|
||||
LOG_PATH.get_or_init(|| {
|
||||
let mut dir = dirs::state_dir()
|
||||
.or_else(dirs::cache_dir)
|
||||
.unwrap_or_else(std::env::temp_dir);
|
||||
dir.push("peerspeak");
|
||||
let _ = std::fs::create_dir_all(&dir);
|
||||
dir.push("peerspeak.log");
|
||||
dir
|
||||
})
|
||||
}
|
||||
|
||||
pub fn log_msg(msg: &str) {
|
||||
if let Ok(mut file) = std::fs::OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open("/home/mollusk/peerspeak.log")
|
||||
.open(log_path())
|
||||
{
|
||||
use std::io::Write;
|
||||
if let Ok(time) = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) {
|
||||
|
||||
@@ -114,12 +114,11 @@ impl RoomState for IrohGossipState {
|
||||
})
|
||||
};
|
||||
|
||||
if let Some(payload) = initial_payload {
|
||||
if let Ok(bytes) = serde_json::to_vec(&payload) {
|
||||
if let Some(payload) = initial_payload
|
||||
&& let Ok(bytes) = serde_json::to_vec(&payload) {
|
||||
crate::log_msg(&format!("Broadcasting initial state from self_id={:?}", self_id));
|
||||
let _ = gossip_sender_clone.broadcast(bytes.into()).await;
|
||||
}
|
||||
}
|
||||
|
||||
// Stream topic messages
|
||||
while let Some(res) = gossip_receiver.next().await {
|
||||
@@ -186,12 +185,11 @@ impl RoomState for IrohGossipState {
|
||||
msg: GossipMessage::Announce(state.clone()),
|
||||
})
|
||||
};
|
||||
if let Some(payload) = payload_opt {
|
||||
if let Ok(bytes) = serde_json::to_vec(&payload) {
|
||||
if let Some(payload) = payload_opt
|
||||
&& let Ok(bytes) = serde_json::to_vec(&payload) {
|
||||
crate::log_msg(&format!("Broadcasting state to new neighbor={:?}", peer_id));
|
||||
let _ = gossip_sender_clone.broadcast(bytes.into()).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(iroh_gossip::api::Event::NeighborDown(peer_id)) => {
|
||||
crate::log_msg(&format!("Gossip event: NeighborDown={:?}", peer_id));
|
||||
|
||||
@@ -94,7 +94,7 @@ impl NetworkTransport for IrohTransport {
|
||||
loop {
|
||||
match conn_clone.read_datagram().await {
|
||||
Ok(bytes) => {
|
||||
if let Err(_) = incoming_tx_inner.send((peer_id, bytes)).await {
|
||||
if incoming_tx_inner.send((peer_id, bytes)).await.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-5
@@ -42,11 +42,16 @@ pub struct PeerSpeakTicket {
|
||||
pub topic_id: [u8; 32],
|
||||
}
|
||||
|
||||
impl ToString for PeerSpeakTicket {
|
||||
fn to_string(&self) -> String {
|
||||
let serialized = serde_json::to_vec(self).unwrap();
|
||||
// Convert to base64 URL-safe string
|
||||
base64::Engine::encode(&base64::engine::general_purpose::URL_SAFE_NO_PAD, &serialized)
|
||||
impl std::fmt::Display for PeerSpeakTicket {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// serde_json on a struct of String/[u8;32] fields is infallible in practice,
|
||||
// but Display can't surface an error, so fall back to an empty ticket body.
|
||||
let serialized = serde_json::to_vec(self).unwrap_or_default();
|
||||
let encoded = base64::Engine::encode(
|
||||
&base64::engine::general_purpose::URL_SAFE_NO_PAD,
|
||||
&serialized,
|
||||
);
|
||||
f.write_str(&encoded)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user