Merge pull request #1060 from Demonthos/fix-macos-hot-reloading
Fix restarting MacOs hot reloading after a forced exit
This commit is contained in:
1 file changed
+20
-2
@@ -159,7 +159,22 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
|
||||
}
|
||||
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));
|
||||
|
||||
// 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 mut watcher = RecommendedWatcher::new(tx, notify::Config::default()).unwrap();
|
||||
let mut watcher =
|
||||
RecommendedWatcher::new(tx, notify::Config::default()).unwrap();
|
||||
|
||||
for path in listening_paths {
|
||||
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}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user