From 90d23714da373cb824a0dd9674b4b746966b3069 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Wed, 19 Jul 2023 13:44:38 -0700 Subject: [PATCH] Fix clippy around pathbuf --- packages/cli/src/server/desktop/mod.rs | 30 ++++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/cli/src/server/desktop/mod.rs b/packages/cli/src/server/desktop/mod.rs index 93bd4e9e9..9b79bdea9 100644 --- a/packages/cli/src/server/desktop/mod.rs +++ b/packages/cli/src/server/desktop/mod.rs @@ -11,7 +11,6 @@ use dioxus_html::HtmlCtx; use dioxus_rsx::hot_reload::*; use interprocess_docfix::local_socket::LocalSocketListener; use std::{ - path::PathBuf, process::{Child, Command}, sync::{Arc, Mutex, RwLock}, }; @@ -138,19 +137,7 @@ pub async fn serve_hot_reload(config: CrateConfig) -> Result<()> { None, ); - #[cfg(target_os = "macos")] - { - // On unix, if you force quit the application, it can leave the file socket open - // This will cause the local socket listener to fail to open - // We check if the file socket is already open from an old session and then delete it - let paths = ["./dioxusin", "./@dioxusin"]; - for path in paths { - let path = PathBuf::from(path); - if path.exists() { - let _ = std::fs::remove_file(path); - } - } - } + clear_paths(); match LocalSocketListener::bind("@dioxusin") { Ok(local_socket_stream) => { @@ -212,6 +199,21 @@ pub async fn serve_hot_reload(config: CrateConfig) -> Result<()> { Ok(()) } +fn clear_paths() { + if cfg!(target_os = "macos") { + // On unix, if you force quit the application, it can leave the file socket open + // This will cause the local socket listener to fail to open + // We check if the file socket is already open from an old session and then delete it + let paths = ["./dioxusin", "./@dioxusin"]; + for path in paths { + let path = std::path::PathBuf::from(path); + if path.exists() { + let _ = std::fs::remove_file(path); + } + } + } +} + fn send_msg(msg: HotReloadMsg, channel: &mut impl std::io::Write) -> bool { if let Ok(msg) = serde_json::to_string(&msg) { if channel.write_all(msg.as_bytes()).is_err() {