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

This commit is contained in:
Evan Almloff 2023-12-06 17:01:51 -06:00
parent 8530f53692
commit b965fc23e9
3 changed files with 9 additions and 6 deletions

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<()> {
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);
}

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
// 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));

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
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();