@@ -23,7 +23,7 @@ use shared_child::SharedChild;
2323use tauri_utils:: platform;
2424
2525/// Payload for the `Terminated` command event.
26- #[ derive( Serialize ) ]
26+ #[ derive( Debug , Clone , Serialize ) ]
2727pub 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" ) ]
3737pub 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+
91115impl 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.
0 commit comments