Skip to content

Commit

Permalink
feat(cli): add log plugin to the app template (#11004)
Browse files Browse the repository at this point in the history
* feat(cli): add log plugin to the app template

The log plugin is really important for mobile development - without it you don't have a clue about logs and stdout for iOS apps

* patch tauri dep for local testing

* clippy
  • Loading branch information
lucasfernog authored Sep 15, 2024
1 parent 35bd9dd commit 6c5340f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-template-log-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tauri-apps/cli": patch:enhance
"tauri-cli": patch:enhance
---

Added the `log` plugin to the app template, which is required to visualize logs on Android and iOS.
9 changes: 6 additions & 3 deletions crates/tauri-cli/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ pub fn command(mut options: Options) -> Result<()> {
template_target_path
);
} else {
let (tauri_dep, tauri_build_dep) = if let Some(tauri_path) = options.tauri_path {
let (tauri_dep, tauri_build_dep) = if let Some(tauri_path) = &options.tauri_path {
(
format!(
r#"{{ path = {:?} }}"#,
resolve_tauri_path(&tauri_path, "crates/tauri")
resolve_tauri_path(tauri_path, "crates/tauri")
),
format!(
"{{ path = {:?} }}",
resolve_tauri_path(&tauri_path, "crates/tauri-build")
resolve_tauri_path(tauri_path, "crates/tauri-build")
),
)
} else {
Expand All @@ -220,6 +220,9 @@ pub fn command(mut options: Options) -> Result<()> {

let mut data = BTreeMap::new();
data.insert("tauri_dep", to_json(tauri_dep));
if options.tauri_path.is_some() {
data.insert("patch_tauri_dep", to_json(true));
}
data.insert("tauri_build_dep", to_json(tauri_build_dep));
data.insert(
"frontend_dist",
Expand Down
6 changes: 6 additions & 0 deletions crates/tauri-cli/templates/app/src-tauri/Cargo.crate-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ tauri-build = {{ tauri_build_dep }}
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
log = "0.4"
tauri = {{ tauri_dep }}
tauri-plugin-log = "2.0.0-rc"
{{#if patch_tauri_dep}}
[patch.crates-io]
tauri = {{ tauri_dep }}
{{/if}}
10 changes: 10 additions & 0 deletions crates/tauri-cli/templates/app/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
tauri_plugin_log::Builder::default()
.level(log::LevelFilter::Info)
.build(),
)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
2 changes: 1 addition & 1 deletion crates/tauri/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn restart(env: &Env) -> ! {
}

#[cfg(target_os = "macos")]
fn restart_macos_app(current_binary: &PathBuf, env: &Env) {
fn restart_macos_app(current_binary: &std::path::Path, env: &Env) {
use std::process::{exit, Command};

if let Some(macos_directory) = current_binary.parent() {
Expand Down

0 comments on commit 6c5340f

Please sign in to comment.