fix macos hot reloading on forced exit

This commit is contained in:
Evan Almloff committed 2023-06-02 10:30:40 -05:00
1 parent 563a2b0953
commit 60abafb381
1 file changed
+20 -2
+20 -2
View File
@@ -159,7 +159,22 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
} }
let file_map = Arc::new(Mutex::new(file_map)); let file_map = Arc::new(Mutex::new(file_map));
if let Ok(local_socket_stream) = LocalSocketListener::bind("@dioxusin") { #[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);
}
}
}
match LocalSocketListener::bind("@dioxusin") {
Ok(local_socket_stream) => {
let aborted = Arc::new(Mutex::new(false)); let aborted = Arc::new(Mutex::new(false));
// listen for connections // listen for connections
@@ -207,7 +222,8 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
let (tx, rx) = std::sync::mpsc::channel(); let (tx, rx) = std::sync::mpsc::channel();
let mut watcher = RecommendedWatcher::new(tx, notify::Config::default()).unwrap(); let mut watcher =
RecommendedWatcher::new(tx, notify::Config::default()).unwrap();
for path in listening_paths { for path in listening_paths {
let full_path = crate_dir.join(path); let full_path = crate_dir.join(path);
@@ -326,6 +342,8 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
} }
}); });
} }
Err(error) => println!("failed to connect to hot reloading\n{error}"),
}
} }
} }