Browse Source

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

Evan Almloff 1 year ago
parent
commit
b965fc23e9

+ 3 - 2
packages/cli/src/server/desktop/mod.rs

@@ -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<()> {
-    match LocalSocketListener::bind("@dioxusin") {
+    let path = std::env::temp_dir().join("dioxusin");
+    match LocalSocketListener::bind(path) {
         Ok(local_socket_stream) => {
             let aborted = Arc::new(Mutex::new(false));
             // 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
         let paths = ["./dioxusin", "./@dioxusin"];
         for path in paths {
-            let path = std::path::PathBuf::from(path);
+            let path = std::env::temp_dir().join(path);
             if path.exists() {
                 let _ = std::fs::remove_file(path);
             }

+ 4 - 3
packages/hot-reload/src/file_watcher.rs

@@ -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
             // 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"];
+            let paths = ["./dioxusin"];
             for path in paths {
-                let path = PathBuf::from(path);
+                let path = std::env::temp_dir().join(path);
                 if path.exists() {
                     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) => {
                 let aborted = Arc::new(Mutex::new(false));
 

+ 2 - 1
packages/hot-reload/src/lib.rs

@@ -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
 pub fn connect(mut f: impl FnMut(HotReloadMsg) + Send + 'static) {
     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);
             loop {
                 let mut buf = String::new();