Simplify cli-config, hotreload -> devtools (drop to 0 deps, fast compile times) (#2975)
* simplify cli-config crate * clean up configs * add devtools crate, update cargo imports * fix serve addr, fix websocket proxy issue * add comment about opt profiles * rename hot-reload to devtools
This commit is contained in:
1 parent
8203ee571f
commit
3fb1f739d1
58 files changed
+1131
-1654
No files matched your search
+11
-32
@@ -86,12 +86,7 @@ impl App {
|
||||
app.set_menubar_receiver();
|
||||
|
||||
// Allow hotreloading to work - but only in debug mode
|
||||
#[cfg(all(
|
||||
feature = "hot-reload",
|
||||
debug_assertions,
|
||||
not(target_os = "android"),
|
||||
not(target_os = "ios")
|
||||
))]
|
||||
#[cfg(all(feature = "devtools", debug_assertions))]
|
||||
app.connect_hotreload();
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
@@ -140,25 +135,14 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
feature = "hot-reload",
|
||||
debug_assertions,
|
||||
not(target_os = "android"),
|
||||
not(target_os = "ios")
|
||||
))]
|
||||
#[cfg(all(feature = "devtools", debug_assertions))]
|
||||
pub fn connect_hotreload(&self) {
|
||||
let proxy = self.shared.proxy.clone();
|
||||
|
||||
tokio::task::spawn(async move {
|
||||
let Some(Ok(mut receiver)) = dioxus_hot_reload::NativeReceiver::create_from_cli().await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
while let Some(Ok(msg)) = receiver.next().await {
|
||||
if let Some(endpoint) = dioxus_cli_config::devserver_ws_endpoint() {
|
||||
let proxy = self.shared.proxy.clone();
|
||||
dioxus_devtools::connect(endpoint, move |msg| {
|
||||
_ = proxy.send_event(UserWindowEvent::HotReloadEvent(msg));
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_new_window(&mut self) {
|
||||
@@ -276,19 +260,14 @@ impl App {
|
||||
view.desktop_context.query.send(result);
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
feature = "hot-reload",
|
||||
debug_assertions,
|
||||
not(target_os = "android"),
|
||||
not(target_os = "ios")
|
||||
))]
|
||||
pub fn handle_hot_reload_msg(&mut self, msg: dioxus_hot_reload::DevserverMsg) {
|
||||
use dioxus_hot_reload::DevserverMsg;
|
||||
#[cfg(all(feature = "devtools", debug_assertions))]
|
||||
pub fn handle_hot_reload_msg(&mut self, msg: dioxus_devtools::DevserverMsg) {
|
||||
use dioxus_devtools::DevserverMsg;
|
||||
|
||||
match msg {
|
||||
DevserverMsg::HotReload(hr_msg) => {
|
||||
for webview in self.webviews.values_mut() {
|
||||
dioxus_hot_reload::apply_changes(&mut webview.dom, &hr_msg);
|
||||
dioxus_devtools::apply_changes(&webview.dom, &hr_msg);
|
||||
webview.poll_vdom();
|
||||
}
|
||||
|
||||
|
||||
@@ -65,18 +65,12 @@ impl Config {
|
||||
/// Initializes a new `WindowBuilder` with default values.
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
let dioxus_config = dioxus_cli_config::CURRENT_CONFIG.as_ref();
|
||||
|
||||
let mut window: WindowBuilder = WindowBuilder::new().with_title(
|
||||
dioxus_config
|
||||
.map(|c| c.application.name.clone())
|
||||
.unwrap_or("Dioxus App".to_string()),
|
||||
);
|
||||
let mut window: WindowBuilder = WindowBuilder::new()
|
||||
.with_title(dioxus_cli_config::app_title().unwrap_or_else(|| "Dioxus App".to_string()));
|
||||
|
||||
// During development we want the window to be on top so we can see it while we work
|
||||
let always_on_top = dioxus_config
|
||||
.map(|c| c.desktop.always_on_top)
|
||||
.unwrap_or(true);
|
||||
let always_on_top = dioxus_cli_config::always_on_top().unwrap_or(true);
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
window = window.with_always_on_top(always_on_top);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ pub enum UserWindowEvent {
|
||||
|
||||
/// Handle a hotreload event, basically telling us to update our templates
|
||||
#[cfg(all(
|
||||
feature = "hot-reload",
|
||||
feature = "devtools",
|
||||
debug_assertions,
|
||||
not(target_os = "android"),
|
||||
not(target_os = "ios")
|
||||
))]
|
||||
HotReloadEvent(dioxus_hot_reload::DevserverMsg),
|
||||
HotReloadEvent(dioxus_devtools::DevserverMsg),
|
||||
|
||||
/// Create a new window
|
||||
NewWindow,
|
||||
|
||||
@@ -41,12 +41,7 @@ pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, desktop_config: Conf
|
||||
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
|
||||
UserWindowEvent::MudaMenuEvent(evnt) => app.handle_menu_event(evnt),
|
||||
|
||||
#[cfg(all(
|
||||
feature = "hot-reload",
|
||||
debug_assertions,
|
||||
not(target_os = "android"),
|
||||
not(target_os = "ios")
|
||||
))]
|
||||
#[cfg(all(feature = "devtools", debug_assertions))]
|
||||
UserWindowEvent::HotReloadEvent(msg) => app.handle_hot_reload_msg(msg),
|
||||
|
||||
UserWindowEvent::Ipc { id, msg } => match msg.method() {
|
||||
|
||||
@@ -280,10 +280,10 @@ fn running_in_dev_mode() -> bool {
|
||||
#[allow(unreachable_code)]
|
||||
fn get_asset_root() -> Option<PathBuf> {
|
||||
if running_in_dev_mode() {
|
||||
return dioxus_cli_config::CURRENT_CONFIG
|
||||
.as_ref()
|
||||
.map(|c| c.application.out_dir.clone())
|
||||
.ok();
|
||||
// todo: we don't want to canonicalize assets like this, but it will take longer to migrate, so we'll do it later
|
||||
// we should just be parsing paths the way they are instead of relative to the "asset" dir
|
||||
// manganis will eventually just dump the raw path to us, but until then, we need to canonicalize here
|
||||
return dioxus_cli_config::base_path();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
|
||||
@@ -381,7 +381,7 @@ impl WebviewInstance {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "hot-reload", debug_assertions))]
|
||||
#[cfg(all(feature = "devtools", debug_assertions))]
|
||||
pub fn kick_stylsheets(&self) {
|
||||
// run eval in the webview to kick the stylesheets by appending a query string
|
||||
// we should do something less clunky than this
|
||||
|
||||
Reference in new issue
Block a user