use a temp directory for the hot reloading pipe on desktop, fullstack and liveview

This commit is contained in:
Evan Almloff committed 2023-12-06 17:01:51 -06:00
1 parent 8530f53692
commit b965fc23e9
3 files changed
+9 -6

No files matched your search

+3 -2
View File
@@ -109,7 +109,8 @@ pub async fn serve(config: CrateConfig, hot_reload_state: Option<HotReloadState>
} }
async fn start_desktop_hot_reload(hot_reload_state: HotReloadState) -> Result<()> { async fn start_desktop_hot_reload(hot_reload_state: HotReloadState) -> Result<()> {
match LocalSocketListener::bind("@dioxusin") { let path = std::env::temp_dir().join("dioxusin");
match LocalSocketListener::bind(path) {
Ok(local_socket_stream) => { Ok(local_socket_stream) => {
let aborted = Arc::new(Mutex::new(false)); let aborted = Arc::new(Mutex::new(false));
// States // States
@@ -188,7 +189,7 @@ fn clear_paths() {
// We check if the file socket is already open from an old session and then delete it // We check if the file socket is already open from an old session and then delete it
let paths = ["./dioxusin", "./@dioxusin"]; let paths = ["./dioxusin", "./@dioxusin"];
for path in paths { for path in paths {
let path = std::path::PathBuf::from(path); let path = std::env::temp_dir().join(path);
if path.exists() { if path.exists() {
let _ = std::fs::remove_file(path); let _ = std::fs::remove_file(path);
} }
+4 -3
View File
@@ -157,16 +157,17 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
// On unix, if you force quit the application, it can leave the file socket open // 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 // 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 // We check if the file socket is already open from an old session and then delete it
let paths = ["./dioxusin", "./@dioxusin"]; let paths = ["./dioxusin"];
for path in paths { for path in paths {
let path = PathBuf::from(path); let path = std::env::temp_dir().join(path);
if path.exists() { if path.exists() {
let _ = std::fs::remove_file(path); let _ = std::fs::remove_file(path);
} }
} }
} }
match LocalSocketListener::bind("@dioxusin") { let path = std::env::temp_dir().join("dioxusin");
match LocalSocketListener::bind(path) {
Ok(local_socket_stream) => { Ok(local_socket_stream) => {
let aborted = Arc::new(Mutex::new(false)); let aborted = Arc::new(Mutex::new(false));
+2 -1
View File
@@ -24,7 +24,8 @@ pub enum HotReloadMsg {
/// Connect to the hot reloading listener. The callback provided will be called every time a template change is detected /// Connect to the hot reloading listener. The callback provided will be called every time a template change is detected
pub fn connect(mut f: impl FnMut(HotReloadMsg) + Send + 'static) { pub fn connect(mut f: impl FnMut(HotReloadMsg) + Send + 'static) {
std::thread::spawn(move || { std::thread::spawn(move || {
if let Ok(socket) = LocalSocketStream::connect("@dioxusin") { let path = std::env::temp_dir().join("dioxusin");
if let Ok(socket) = LocalSocketStream::connect(path) {
let mut buf_reader = BufReader::new(socket); let mut buf_reader = BufReader::new(socket);
loop { loop {
let mut buf = String::new(); let mut buf = String::new();