fix hotreloading issues in the CLI

This commit is contained in:
Jonathan Kelley committed 2024-03-12 13:39:42 -07:00
1 parent d180f569cf
commit ad7a350d2e
37 files changed
+818 -805

No files matched your search

+18 -15
View File
@@ -1,20 +1,18 @@
use crate::server::Platform;
use crate::{
cfg::ConfigOptsServe,
server::{
output::{print_console_info, PrettierOptions},
setup_file_watcher,
setup_file_watcher, Platform,
},
BuildResult, Result,
};
use dioxus_cli_config::CrateConfig;
use dioxus_cli_config::{CrateConfig, ExecutableType};
use dioxus_hot_reload::HotReloadMsg;
use dioxus_html::HtmlCtx;
use dioxus_rsx::hot_reload::*;
use interprocess_docfix::local_socket::LocalSocketListener;
use std::fs::create_dir_all;
use interprocess::local_socket::LocalSocketListener;
use std::{
fs::create_dir_all,
process::{Child, Command},
sync::{Arc, Mutex, RwLock},
};
@@ -33,13 +31,7 @@ pub(crate) async fn startup_with_platform<P: Platform + Send + 'static>(
config: CrateConfig,
serve_cfg: &ConfigOptsServe,
) -> Result<()> {
// ctrl-c shutdown checker
let _crate_config = config.clone();
let _ = ctrlc::set_handler(move || {
#[cfg(feature = "plugin")]
let _ = PluginManager::on_serve_shutdown(&_crate_config);
std::process::exit(0);
});
set_ctrl_c(&config);
let hot_reload_state = match config.hot_reload {
true => {
@@ -67,6 +59,16 @@ pub(crate) async fn startup_with_platform<P: Platform + Send + 'static>(
Ok(())
}
fn set_ctrl_c(config: &CrateConfig) {
// ctrl-c shutdown checker
let _crate_config = config.clone();
let _ = ctrlc::set_handler(move || {
#[cfg(feature = "plugin")]
let _ = PluginManager::on_serve_shutdown(&_crate_config);
std::process::exit(0);
});
}
/// Start the server without hot reload
async fn serve<P: Platform + Send + 'static>(
config: CrateConfig,
@@ -169,12 +171,13 @@ async fn start_desktop_hot_reload(hot_reload_state: HotReloadState) -> Result<()
let mut hot_reload_rx = hot_reload_state.messages.subscribe();
while let Ok(template) = hot_reload_rx.recv().await {
while let Ok(msg) = hot_reload_rx.recv().await {
let channels = &mut *channels.lock().unwrap();
let mut i = 0;
while i < channels.len() {
let channel = &mut channels[i];
if send_msg(HotReloadMsg::UpdateTemplate(template), channel) {
if send_msg(msg.clone(), channel) {
i += 1;
} else {
channels.remove(i);