Skip to content

Commit

Permalink
refactor(cli): use cargo run for tauri dev (tauri-apps#11694)
Browse files Browse the repository at this point in the history
* x

* todo

* lint

* lint

* rename fn

* lint

* lint

---------

Co-authored-by: Lucas Nogueira <[email protected]>
  • Loading branch information
FabianLars and lucasfernog authored Dec 5, 2024
1 parent 1f65fd2 commit 2b8a981
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 199 deletions.
1 change: 0 additions & 1 deletion crates/tauri-bundler/src/bundle/linux/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
use anyhow::Context;
use std::{
fs,
io::Write,
path::{Path, PathBuf},
process::Command,
};
Expand Down
1 change: 0 additions & 1 deletion crates/tauri-bundler/src/bundle/macos/dmg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
if let Some(value) = env::var_os("CI") {
if value == "true" {
bundle_dmg_cmd.arg("--skip-jenkins");
} else {
}
}
}
Expand Down
31 changes: 2 additions & 29 deletions crates/tauri-cli/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
get as get_config, reload as reload_config, BeforeDevCommand, ConfigHandle, FrontendDist,
},
},
interface::{AppInterface, DevProcess, ExitReason, Interface},
interface::{AppInterface, ExitReason, Interface},
CommandExt, ConfigValue, Result,
};

Expand Down Expand Up @@ -338,35 +338,8 @@ pub fn setup(interface: &AppInterface, options: &mut Options, config: ConfigHand
Ok(())
}

pub fn wait_dev_process<
C: DevProcess + Send + 'static,
F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static,
>(
child: C,
on_exit: F,
) {
std::thread::spawn(move || {
let code = child
.wait()
.ok()
.and_then(|status| status.code())
.or(Some(1));
on_exit(
code,
if child.manually_killed_process() {
ExitReason::TriggeredKill
} else {
ExitReason::NormalExit
},
);
});
}

pub fn on_app_exit(code: Option<i32>, reason: ExitReason, exit_on_panic: bool, no_watch: bool) {
if no_watch
|| (!matches!(reason, ExitReason::TriggeredKill)
&& (exit_on_panic || matches!(reason, ExitReason::NormalExit)))
{
if no_watch || exit_on_panic || matches!(reason, ExitReason::NormalExit) {
kill_before_dev_process();
exit(code.unwrap_or(0));
}
Expand Down
5 changes: 4 additions & 1 deletion crates/tauri-cli/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ pub use rust::{MobileOptions, Options, Rust as AppInterface};
pub trait DevProcess {
fn kill(&self) -> std::io::Result<()>;
fn try_wait(&self) -> std::io::Result<Option<ExitStatus>>;
// TODO:
#[allow(unused)]
fn wait(&self) -> std::io::Result<ExitStatus>;
#[allow(unused)]
fn manually_killed_process(&self) -> bool;
}

Expand Down Expand Up @@ -84,7 +87,7 @@ pub trait AppSettings {
#[derive(Debug)]
pub enum ExitReason {
/// Killed manually.
TriggeredKill,
// TriggeredKill,
/// App compilation failed.
CompilationFailed,
/// Regular exit.
Expand Down
11 changes: 6 additions & 5 deletions crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ fn lookup<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {
}

fn shared_options(
desktop_dev: bool,
mobile: bool,
args: &mut Vec<String>,
features: &mut Option<Vec<String>>,
Expand All @@ -374,7 +375,9 @@ fn shared_options(
.get_or_insert(Vec::new())
.push("tauri/rustls-tls".into());
} else {
args.push("--bins".into());
if !desktop_dev {
args.push("--bins".into());
}
let all_features = app_settings
.manifest
.lock()
Expand Down Expand Up @@ -408,7 +411,7 @@ fn dev_options(
}
*args = dev_args;

shared_options(mobile, args, features, app_settings);
shared_options(true, mobile, args, features, app_settings);

if !args.contains(&"--no-default-features".into()) {
let manifest_features = app_settings.manifest.lock().unwrap().features();
Expand Down Expand Up @@ -488,7 +491,7 @@ impl Rust {
features
.get_or_insert(Vec::new())
.push("tauri/custom-protocol".into());
shared_options(mobile, args, features, &self.app_settings);
shared_options(false, mobile, args, features, &self.app_settings);
}

fn run_dev<F: Fn(Option<i32>, ExitReason) + Send + Sync + 'static>(
Expand All @@ -502,8 +505,6 @@ impl Rust {
run_args,
&mut self.available_targets,
self.config_features.clone(),
&self.app_settings,
self.main_binary_name.clone(),
on_exit,
)
.map(|c| Box::new(c) as Box<dyn DevProcess + Send>)
Expand Down
Loading

0 comments on commit 2b8a981

Please sign in to comment.