docs(shell): update example to include Encoding usage in Command::spawn (#3183)

* docs(shell): update example to include Encoding usage in `Command::spawn`

* docs(shell): update patch level to minor for Encoding usage in `Command::spawn` documentation

* Update .changes/doc-to-Encoding-usage-in-shell.md

Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com>

* docs(shell): update examples to demonstrate manual Encoding usage in command output

* Update plugins/shell/src/process/mod.rs

Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com>

* docs(shell): update example to use 'windows-1252' encoding in command output

* Update plugins/shell/src/process/mod.rs

Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com>

* docs(shell): update example command in documentation to use 'some-program' with 'some-arg'

* Bump shell-js in change file

* Fix indent
This commit is contained in:
Tunglies
2025-12-29 10:58:55 +08:00
committed by GitHub
parent 04b33ea0b0
commit 31415effdf
2 changed files with 37 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
shell: patch
shell-js: patch
---
Docs on example to Encoding usage in `Command::spawn`. No user facing changes.

View File

@@ -242,7 +242,9 @@ impl Command {
/// .setup(|app| {
/// let handle = app.handle().clone();
/// tauri::async_runtime::spawn(async move {
/// let (mut rx, mut child) = handle.shell().command("cargo")
/// let (mut rx, mut child) = handle
/// .shell()
/// .command("cargo")
/// .args(["tauri", "dev"])
/// .spawn()
/// .expect("Failed to spawn cargo");
@@ -260,7 +262,34 @@ impl Command {
/// }
/// });
/// Ok(())
/// });
/// });
/// ```
///
/// Depending on the command you spawn, it might output in a specific encoding, to parse the output lines in this case:
///
/// ```rust,no_run
/// use tauri_plugin_shell::{process::{CommandEvent, Encoding}, ShellExt};
/// tauri::Builder::default()
/// .setup(|app| {
/// let handle = app.handle().clone();
/// tauri::async_runtime::spawn(async move {
/// let (mut rx, mut child) = handle
/// .shell()
/// .command("some-program")
/// .arg("some-arg")
/// .spawn()
/// .expect("Failed to spawn some-program");
///
/// let encoding = Encoding::for_label(b"windows-1252").unwrap();
/// while let Some(event) = rx.recv().await {
/// if let CommandEvent::Stdout(line) = event {
/// let (decoded, _, _) = encoding.decode(&line);
/// println!("got: {decoded}");
/// }
/// }
/// });
/// Ok(())
/// });
/// ```
pub fn spawn(self) -> crate::Result<(Receiver<CommandEvent>, CommandChild)> {
let raw = self.raw_out;