fix hot reload on windows (#2142)
This commit is contained in:
1 parent
9942c8bfd1
commit
e464294c66
5 files changed
+84
-51
No files matched your search
@@ -173,7 +173,13 @@ pub fn init<Ctx: HotReloadingContext + Send + 'static>(cfg: Config<Ctx>) {
|
||||
}
|
||||
}
|
||||
|
||||
let local_socket_stream = match LocalSocketListener::bind(hot_reload_socket_path) {
|
||||
let listener = if cfg!(windows) {
|
||||
LocalSocketListener::bind("@dioxusin")
|
||||
} else {
|
||||
LocalSocketListener::bind(hot_reload_socket_path)
|
||||
};
|
||||
|
||||
let local_socket_stream = match listener {
|
||||
Ok(local_socket_stream) => local_socket_stream,
|
||||
Err(err) => {
|
||||
println!("failed to connect to hot reloading\n{err}");
|
||||
|
||||
@@ -30,41 +30,49 @@ 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(callback: impl FnMut(HotReloadMsg) + Send + 'static) {
|
||||
// FIXME: this is falling back onto the current directory when not running under cargo, which is how the CLI runs this.
|
||||
// This needs to be fixed.
|
||||
let _manifest_dir = std::env::var("CARGO_MANIFEST_DIR");
|
||||
if cfg!(windows) {
|
||||
connect_at(PathBuf::from("@dioxusin"), callback);
|
||||
} else {
|
||||
// FIXME: this is falling back onto the current directory when not running under cargo, which is how the CLI runs this.
|
||||
// This needs to be fixed.
|
||||
let _manifest_dir = std::env::var("CARGO_MANIFEST_DIR");
|
||||
|
||||
// get the cargo manifest directory, where the target dir lives
|
||||
let mut path = match _manifest_dir {
|
||||
Ok(manifest_dir) => PathBuf::from(manifest_dir),
|
||||
Err(_) => std::env::current_dir().unwrap(),
|
||||
};
|
||||
// get the cargo manifest directory, where the target dir lives
|
||||
let mut path = match _manifest_dir {
|
||||
Ok(manifest_dir) => PathBuf::from(manifest_dir),
|
||||
Err(_) => std::env::current_dir().unwrap(),
|
||||
};
|
||||
|
||||
// walk the path until we a find a socket named `dioxusin` inside that folder's target directory
|
||||
loop {
|
||||
let maybe = path.join("target").join("dioxusin");
|
||||
// walk the path until we a find a socket named `dioxusin` inside that folder's target directory
|
||||
loop {
|
||||
let maybe = path.join("target").join("dioxusin");
|
||||
|
||||
if maybe.exists() {
|
||||
path = maybe;
|
||||
break;
|
||||
if maybe.exists() {
|
||||
path = maybe;
|
||||
break;
|
||||
}
|
||||
|
||||
// It's likely we're running under just cargo and not dx
|
||||
path = match path.parent() {
|
||||
Some(parent) => parent.to_path_buf(),
|
||||
None => return,
|
||||
};
|
||||
}
|
||||
|
||||
// It's likely we're running under just cargo and not dx
|
||||
path = match path.parent() {
|
||||
Some(parent) => parent.to_path_buf(),
|
||||
None => return,
|
||||
};
|
||||
println!("connecting to {:?}", path);
|
||||
connect_at(path, callback);
|
||||
}
|
||||
|
||||
println!("connecting to {:?}", path);
|
||||
|
||||
connect_at(path, callback);
|
||||
}
|
||||
|
||||
pub fn connect_at(socket: PathBuf, mut callback: impl FnMut(HotReloadMsg) + Send + 'static) {
|
||||
std::thread::spawn(move || {
|
||||
// There might be a socket since the we're not running under the hot reloading server
|
||||
let Ok(socket) = LocalSocketStream::connect(socket.clone()) else {
|
||||
let stream = if cfg!(windows) {
|
||||
LocalSocketStream::connect("@dioxusin")
|
||||
} else {
|
||||
LocalSocketStream::connect(socket.clone())
|
||||
};
|
||||
let Ok(socket) = stream else {
|
||||
println!(
|
||||
"could not find hot reloading server at {:?}, make sure it's running",
|
||||
socket
|
||||
|
||||
Reference in new issue
Block a user