mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-04 17:18:56 +03:00
fix(core): sidecar command path (#1584)
This commit is contained in:
parent
7f998d08e3
commit
99307d02c3
5
.changes/sidecar-fix.md
Normal file
5
.changes/sidecar-fix.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"tauri": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes `sidecar` Command API.
|
@ -23,7 +23,7 @@ use shared_child::SharedChild;
|
|||||||
use tauri_utils::platform;
|
use tauri_utils::platform;
|
||||||
|
|
||||||
/// Payload for the `Terminated` command event.
|
/// Payload for the `Terminated` command event.
|
||||||
#[derive(Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct TerminatedPayload {
|
pub struct TerminatedPayload {
|
||||||
/// Exit code of the process.
|
/// Exit code of the process.
|
||||||
pub code: Option<i32>,
|
pub code: Option<i32>,
|
||||||
@ -32,7 +32,7 @@ pub struct TerminatedPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A event sent to the command callback.
|
/// A event sent to the command callback.
|
||||||
#[derive(Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
#[serde(tag = "event", content = "payload")]
|
#[serde(tag = "event", content = "payload")]
|
||||||
pub enum CommandEvent {
|
pub enum CommandEvent {
|
||||||
/// Stderr line.
|
/// Stderr line.
|
||||||
@ -88,6 +88,30 @@ impl CommandChild {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn relative_command_path(command: String) -> crate::Result<String> {
|
||||||
|
match std::env::current_exe()?.parent() {
|
||||||
|
Some(exe_dir) => Ok(format!(
|
||||||
|
"{}/{}",
|
||||||
|
exe_dir.to_string_lossy().to_string(),
|
||||||
|
command
|
||||||
|
)),
|
||||||
|
None => Err(super::Error::Command("Could not evaluate executable dir".to_string()).into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn relative_command_path(command: String) -> crate::Result<String> {
|
||||||
|
match std::env::current_exe()?.parent() {
|
||||||
|
Some(exe_dir) => Ok(format!(
|
||||||
|
"{}/{}.exe",
|
||||||
|
exe_dir.to_string_lossy().to_string(),
|
||||||
|
command
|
||||||
|
)),
|
||||||
|
None => Err(super::Error::Command("Could not evaluate executable dir".to_string()).into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
/// Creates a new Command for launching the given program.
|
/// Creates a new Command for launching the given program.
|
||||||
pub fn new<S: Into<String>>(program: S) -> Self {
|
pub fn new<S: Into<String>>(program: S) -> Self {
|
||||||
@ -98,12 +122,13 @@ impl Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new Command for launching the given sidecar program.
|
/// Creates a new Command for launching the given sidecar program.
|
||||||
pub fn new_sidecar<S: Into<String>>(program: S) -> Self {
|
pub fn new_sidecar<S: Into<String>>(program: S) -> crate::Result<Self> {
|
||||||
Self::new(format!(
|
let program = format!(
|
||||||
"{}-{}",
|
"{}-{}",
|
||||||
program.into(),
|
program.into(),
|
||||||
platform::target_triple().expect("unsupported platform")
|
platform::target_triple().expect("unsupported platform")
|
||||||
))
|
);
|
||||||
|
Ok(Self::new(relative_command_path(program)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append args to the command.
|
/// Append args to the command.
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
/// The error types.
|
/// The error types.
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
/// Command error.
|
||||||
|
#[error("Command Error: {0}")]
|
||||||
|
Command(String),
|
||||||
/// The extract archive error.
|
/// The extract archive error.
|
||||||
#[error("Extract Error: {0}")]
|
#[error("Extract Error: {0}")]
|
||||||
Extract(String),
|
Extract(String),
|
||||||
|
@ -70,7 +70,7 @@ impl Cmd {
|
|||||||
#[cfg(shell_execute)]
|
#[cfg(shell_execute)]
|
||||||
{
|
{
|
||||||
let mut command = if sidecar {
|
let mut command = if sidecar {
|
||||||
Command::new_sidecar(program)
|
Command::new_sidecar(program)?
|
||||||
} else {
|
} else {
|
||||||
Command::new(program)
|
Command::new(program)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user