fix normal desktop serve
This commit is contained in:
1 parent
2c1c147828
commit
98e2b4acbd
2 files changed
+34
-33
No files matched your search
+13
-20
@@ -247,46 +247,39 @@ pub fn build(config: &CrateConfig, quiet: bool) -> Result<BuildResult> {
|
|||||||
pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResult> {
|
pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResult> {
|
||||||
log::info!("🚅 Running build [Desktop] command...");
|
log::info!("🚅 Running build [Desktop] command...");
|
||||||
|
|
||||||
|
let t_start = std::time::Instant::now();
|
||||||
let ignore_files = build_assets(config)?;
|
let ignore_files = build_assets(config)?;
|
||||||
|
|
||||||
let mut cmd = Command::new("cargo");
|
let mut cmd = subprocess::Exec::cmd("cargo")
|
||||||
cmd.current_dir(&config.crate_dir)
|
.cwd(&config.crate_dir)
|
||||||
.arg("build")
|
.arg("build")
|
||||||
.stdout(std::process::Stdio::inherit())
|
.arg("--message-format=json");
|
||||||
.stderr(std::process::Stdio::inherit());
|
|
||||||
|
|
||||||
if config.release {
|
if config.release {
|
||||||
cmd.arg("--release");
|
cmd = cmd.arg("--release");
|
||||||
}
|
}
|
||||||
if config.verbose {
|
if config.verbose {
|
||||||
cmd.arg("--verbose");
|
cmd = cmd.arg("--verbose");
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.custom_profile.is_some() {
|
if config.custom_profile.is_some() {
|
||||||
let custom_profile = config.custom_profile.as_ref().unwrap();
|
let custom_profile = config.custom_profile.as_ref().unwrap();
|
||||||
cmd.arg("--profile");
|
cmd = cmd.arg("--profile").arg(custom_profile);
|
||||||
cmd.arg(custom_profile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.features.is_some() {
|
if config.features.is_some() {
|
||||||
let features_str = config.features.as_ref().unwrap().join(" ");
|
let features_str = config.features.as_ref().unwrap().join(" ");
|
||||||
cmd.arg("--features");
|
cmd = cmd.arg("--features").arg(features_str);
|
||||||
cmd.arg(features_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match &config.executable {
|
let cmd = match &config.executable {
|
||||||
crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
|
crate::ExecutableType::Binary(name) => cmd.arg("--bin").arg(name),
|
||||||
crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
|
crate::ExecutableType::Lib(name) => cmd.arg("--lib").arg(name),
|
||||||
crate::ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
crate::ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
||||||
};
|
};
|
||||||
|
|
||||||
let output = cmd.output()?;
|
let warning_messages = prettier_build(cmd)?;
|
||||||
|
|
||||||
if !output.status.success() {
|
|
||||||
return Err(Error::BuildFailed("Program build failed.".into()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if output.status.success() {
|
|
||||||
let release_type = match config.release {
|
let release_type = match config.release {
|
||||||
true => "release",
|
true => "release",
|
||||||
false => "debug",
|
false => "debug",
|
||||||
@@ -363,12 +356,12 @@ pub fn build_desktop(config: &CrateConfig, _is_serve: bool) -> Result<BuildResul
|
|||||||
.unwrap_or_else(|| PathBuf::from("dist"))
|
.unwrap_or_else(|| PathBuf::from("dist"))
|
||||||
.display()
|
.display()
|
||||||
);
|
);
|
||||||
}
|
|
||||||
println!("build desktop done");
|
println!("build desktop done");
|
||||||
|
|
||||||
Ok(BuildResult {
|
Ok(BuildResult {
|
||||||
warnings: vec![],
|
warnings: warning_messages,
|
||||||
elapsed_time: 0,
|
elapsed_time: (t_start - std::time::Instant::now()).as_millis(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ use notify::{RecommendedWatcher, Watcher};
|
|||||||
use std::{
|
use std::{
|
||||||
net::UdpSocket,
|
net::UdpSocket,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::{Command, Stdio},
|
process::{Child, Command, Stdio},
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex, RwLock},
|
||||||
};
|
};
|
||||||
use tokio::sync::broadcast::{self, Sender};
|
use tokio::sync::broadcast::{self, Sender};
|
||||||
use tower::ServiceBuilder;
|
use tower::ServiceBuilder;
|
||||||
@@ -66,7 +66,8 @@ pub async fn startup(config: CrateConfig) -> Result<()> {
|
|||||||
|
|
||||||
/// Start the server without hot reload
|
/// Start the server without hot reload
|
||||||
pub async fn serve_default(config: CrateConfig) -> Result<()> {
|
pub async fn serve_default(config: CrateConfig) -> Result<()> {
|
||||||
let first_build_result = start_desktop(&config)?;
|
let (child, first_build_result) = start_desktop(&config)?;
|
||||||
|
let currently_running_child: RwLock<Child> = RwLock::new(child);
|
||||||
|
|
||||||
log::info!("🚀 Starting development server...");
|
log::info!("🚀 Starting development server...");
|
||||||
|
|
||||||
@@ -75,7 +76,14 @@ pub async fn serve_default(config: CrateConfig) -> Result<()> {
|
|||||||
let _watcher = setup_file_watcher(
|
let _watcher = setup_file_watcher(
|
||||||
{
|
{
|
||||||
let config = config.clone();
|
let config = config.clone();
|
||||||
move || start_desktop(&config)
|
|
||||||
|
move || {
|
||||||
|
let mut current_child = currently_running_child.write().unwrap();
|
||||||
|
current_child.kill()?;
|
||||||
|
let (child, result) = start_desktop(&config)?;
|
||||||
|
*current_child = child;
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
&config,
|
&config,
|
||||||
None,
|
None,
|
||||||
@@ -93,6 +101,8 @@ pub async fn serve_default(config: CrateConfig) -> Result<()> {
|
|||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
std::future::pending::<()>().await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +110,7 @@ pub async fn serve_default(config: CrateConfig) -> Result<()> {
|
|||||||
|
|
||||||
/// Start dx serve with hot reload
|
/// Start dx serve with hot reload
|
||||||
pub async fn serve_hot_reload(config: CrateConfig) -> Result<()> {
|
pub async fn serve_hot_reload(config: CrateConfig) -> Result<()> {
|
||||||
let first_build_result = start_desktop(&config)?;
|
let (_, first_build_result) = start_desktop(&config)?;
|
||||||
|
|
||||||
println!("🚀 Starting development server...");
|
println!("🚀 Starting development server...");
|
||||||
|
|
||||||
@@ -137,7 +147,7 @@ pub async fn serve_hot_reload(config: CrateConfig) -> Result<()> {
|
|||||||
for channel in &mut *channels.lock().unwrap() {
|
for channel in &mut *channels.lock().unwrap() {
|
||||||
send_msg(HotReloadMsg::Shutdown, channel);
|
send_msg(HotReloadMsg::Shutdown, channel);
|
||||||
}
|
}
|
||||||
start_desktop(&config)
|
Ok(start_desktop(&config)?.1)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None,
|
None,
|
||||||
@@ -243,7 +253,7 @@ fn send_msg(msg: HotReloadMsg, channel: &mut impl std::io::Write) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_desktop(config: &CrateConfig) -> Result<BuildResult> {
|
pub fn start_desktop(config: &CrateConfig) -> Result<(Child, BuildResult)> {
|
||||||
// Run the desktop application
|
// Run the desktop application
|
||||||
let result = crate::builder::build_desktop(config, true)?;
|
let result = crate::builder::build_desktop(config, true)?;
|
||||||
|
|
||||||
@@ -255,11 +265,9 @@ pub fn start_desktop(config: &CrateConfig) -> Result<BuildResult> {
|
|||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
file.set_extension("exe");
|
file.set_extension("exe");
|
||||||
}
|
}
|
||||||
Command::new(file.to_str().unwrap())
|
let child = Command::new(file.to_str().unwrap()).spawn()?;
|
||||||
.stdout(Stdio::inherit())
|
|
||||||
.spawn()?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(result)
|
Ok((child, result))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user