Resume window position/size, watch cargo/dioxus tomls, fix css reverting during hotreloading, allow menubar events to be captured from within dioxus (#2116)

* Fix: css hotreloading being invalidated, watcher not watching cargo/dioxus tomls, add feature to restore window state

* Make clappy hippier

* remove console log

* use simpler css invalidator

* Less flash, remove log on web hotreload

* Fix floating window managed behavior on mac

* clippy...
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-03-20 09:16:18 -07:00
1 parent 44e997f7df
commit e923c6462c
17 files changed
+303 -40

No files matched your search

+25 -1
View File
@@ -111,6 +111,7 @@ async fn start_desktop_hot_reload(hot_reload_state: HotReloadState) -> Result<()
.exec()
.unwrap();
let target_dir = metadata.target_directory.as_std_path();
let _ = create_dir_all(target_dir); // `_all` is for good measure and future-proofness.
let path = target_dir.join("dioxusin");
clear_paths(&path);
@@ -141,6 +142,7 @@ async fn start_desktop_hot_reload(hot_reload_state: HotReloadState) -> Result<()
.flat_map(|v| v.templates.values().copied())
.collect()
};
for template in templates {
if !send_msg(
HotReloadMsg::UpdateTemplate(template),
@@ -282,7 +284,29 @@ impl DesktopPlatform {
config: &CrateConfig,
rust_flags: Option<String>,
) -> Result<BuildResult> {
self.currently_running_child.0.kill()?;
// Gracefully shtudown the desktop app
// It might have a receiver to do some cleanup stuff
let pid = self.currently_running_child.0.id();
// on unix, we can send a signal to the process to shut down
#[cfg(unix)]
{
_ = Command::new("kill")
.args(["-s", "TERM", &pid.to_string()])
.spawn();
}
// on windows, use the `taskkill` command
#[cfg(windows)]
{
_ = Command::new("taskkill")
.args(["/F", "/PID", &pid.to_string()])
.spawn();
}
// Todo: add a timeout here to kill the process if it doesn't shut down within a reasonable time
self.currently_running_child.0.wait()?;
let (child, result) = start_desktop(config, self.skip_assets, rust_flags)?;
self.currently_running_child = child;
Ok(result)
+6 -2
View File
@@ -56,9 +56,14 @@ async fn setup_file_watcher<F: Fn() -> Result<BuildResult> + Send + 'static>(
// file watcher: check file change
let mut allow_watch_path = config.dioxus_config.web.watcher.watch_path.clone();
// Extend the watch path to include the assets directory - this is so we can hotreload CSS and other assets
// Extend the watch path to include the assets directory - this is so we can hotreload CSS and other assets by default
allow_watch_path.push(config.dioxus_config.application.asset_dir.clone());
// Extend the watch path to include Cargo.toml and Dioxus.toml
allow_watch_path.push("Cargo.toml".to_string().into());
allow_watch_path.push("Dioxus.toml".to_string().into());
allow_watch_path.dedup();
// Create the file watcher
let mut watcher = notify::recommended_watcher({
let watcher_config = config.clone();
@@ -66,7 +71,6 @@ async fn setup_file_watcher<F: Fn() -> Result<BuildResult> + Send + 'static>(
let Ok(e) = info else {
return;
};
watch_event(
e,
&mut last_update_time,
+1 -1
View File
@@ -112,7 +112,7 @@ pub fn print_console_info(
.watch_path
.iter()
.cloned()
.chain(Some(config.dioxus_config.application.asset_dir.clone()))
.chain(["Cargo.toml", "Dioxus.toml"].iter().map(PathBuf::from))
.map(|f| f.display().to_string())
.collect::<Vec<String>>()
.join(", ")