Skip to content

Commit 99307d0

Browse files
authored
fix(core): sidecar command path (#1584)
1 parent 7f998d0 commit 99307d0

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

.changes/sidecar-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Fixes `sidecar` Command API.

core/tauri/src/api/command.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use shared_child::SharedChild;
2323
use tauri_utils::platform;
2424

2525
/// Payload for the `Terminated` command event.
26-
#[derive(Serialize)]
26+
#[derive(Debug, Clone, Serialize)]
2727
pub struct TerminatedPayload {
2828
/// Exit code of the process.
2929
pub code: Option<i32>,
@@ -32,7 +32,7 @@ pub struct TerminatedPayload {
3232
}
3333

3434
/// A event sent to the command callback.
35-
#[derive(Serialize)]
35+
#[derive(Debug, Clone, Serialize)]
3636
#[serde(tag = "event", content = "payload")]
3737
pub enum CommandEvent {
3838
/// Stderr line.
@@ -88,6 +88,30 @@ impl CommandChild {
8888
}
8989
}
9090

91+
#[cfg(not(windows))]
92+
fn relative_command_path(command: String) -> crate::Result<String> {
93+
match std::env::current_exe()?.parent() {
94+
Some(exe_dir) => Ok(format!(
95+
"{}/{}",
96+
exe_dir.to_string_lossy().to_string(),
97+
command
98+
)),
99+
None => Err(super::Error::Command("Could not evaluate executable dir".to_string()).into()),
100+
}
101+
}
102+
103+
#[cfg(windows)]
104+
fn relative_command_path(command: String) -> crate::Result<String> {
105+
match std::env::current_exe()?.parent() {
106+
Some(exe_dir) => Ok(format!(
107+
"{}/{}.exe",
108+
exe_dir.to_string_lossy().to_string(),
109+
command
110+
)),
111+
None => Err(super::Error::Command("Could not evaluate executable dir".to_string()).into()),
112+
}
113+
}
114+
91115
impl Command {
92116
/// Creates a new Command for launching the given program.
93117
pub fn new<S: Into<String>>(program: S) -> Self {
@@ -98,12 +122,13 @@ impl Command {
98122
}
99123

100124
/// Creates a new Command for launching the given sidecar program.
101-
pub fn new_sidecar<S: Into<String>>(program: S) -> Self {
102-
Self::new(format!(
125+
pub fn new_sidecar<S: Into<String>>(program: S) -> crate::Result<Self> {
126+
let program = format!(
103127
"{}-{}",
104128
program.into(),
105129
platform::target_triple().expect("unsupported platform")
106-
))
130+
);
131+
Ok(Self::new(relative_command_path(program)?))
107132
}
108133

109134
/// Append args to the command.

core/tauri/src/api/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
/// The error types.
66
#[derive(thiserror::Error, Debug)]
77
pub enum Error {
8+
/// Command error.
9+
#[error("Command Error: {0}")]
10+
Command(String),
811
/// The extract archive error.
912
#[error("Extract Error: {0}")]
1013
Extract(String),

core/tauri/src/endpoints/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Cmd {
7070
#[cfg(shell_execute)]
7171
{
7272
let mut command = if sidecar {
73-
Command::new_sidecar(program)
73+
Command::new_sidecar(program)?
7474
} else {
7575
Command::new(program)
7676
};

0 commit comments

Comments
 (0)