@ -77,6 +77,13 @@ fn socket_cleanup(socket: &PathBuf) {
fn notify_singleton ( socket : & PathBuf ) -> Result < ( ) , Error > {
fn notify_singleton ( socket : & PathBuf ) -> Result < ( ) , Error > {
let stream = UnixStream ::connect ( socket ) ? ;
let stream = UnixStream ::connect ( socket ) ? ;
let mut bf = BufWriter ::new ( & stream ) ;
let mut bf = BufWriter ::new ( & stream ) ;
let cwd = std ::env ::current_dir ( )
. unwrap_or_default ( )
. to_str ( )
. unwrap_or_default ( )
. to_string ( ) ;
bf . write_all ( cwd . as_bytes ( ) ) ? ;
bf . write_all ( b" \0 \0 " ) ? ;
let args_joined = std ::env ::args ( ) . collect ::< Vec < String > > ( ) . join ( "\0" ) ;
let args_joined = std ::env ::args ( ) . collect ::< Vec < String > > ( ) . join ( "\0" ) ;
bf . write_all ( args_joined . as_bytes ( ) ) ? ;
bf . write_all ( args_joined . as_bytes ( ) ) ? ;
bf . flush ( ) ? ;
bf . flush ( ) ? ;
@ -91,12 +98,6 @@ fn listen_for_other_instances<A: Runtime>(
) {
) {
match UnixListener ::bind ( socket ) {
match UnixListener ::bind ( socket ) {
Ok ( listener ) = > {
Ok ( listener ) = > {
let cwd = std ::env ::current_dir ( )
. unwrap_or_default ( )
. to_str ( )
. unwrap_or_default ( )
. to_string ( ) ;
tauri ::async_runtime ::spawn ( async move {
tauri ::async_runtime ::spawn ( async move {
for stream in listener . incoming ( ) {
for stream in listener . incoming ( ) {
match stream {
match stream {
@ -104,9 +105,16 @@ fn listen_for_other_instances<A: Runtime>(
let mut s = String ::new ( ) ;
let mut s = String ::new ( ) ;
match stream . read_to_string ( & mut s ) {
match stream . read_to_string ( & mut s ) {
Ok ( _ ) = > {
Ok ( _ ) = > {
let ( cwd , args ) = {
let mut split = s . split ( "\0\0" ) ;
(
split . next ( ) . unwrap_or_default ( ) ,
split . next ( ) . unwrap_or_default ( ) ,
)
} ;
let args : Vec < String > =
let args : Vec < String > =
s . split ( '\0' ) . map ( String ::from ) . collect ( ) ;
arg s. split ( '\0' ) . map ( String ::from ) . collect ( ) ;
cb ( app . app_handle ( ) , args , cwd . clone ( ) ) ;
cb ( app . app_handle ( ) , args , cwd . to_string ( ) ) ;
}
}
Err ( e ) = > {
Err ( e ) = > {
tracing ::debug ! ( "single_instance failed to be notified: {e}" )
tracing ::debug ! ( "single_instance failed to be notified: {e}" )