@@ -97,48 +97,66 @@ fn run_wsl(args: &[&str]) -> Result<String, String> {
9797 Ok ( decode_command_output ( & out. stdout ) )
9898}
9999
100+ #[ cfg( windows) ]
101+ fn list_distros_blocking ( ) -> Result < Vec < WslDistro > , String > {
102+ let out = run_wsl ( & [ "--list" , "--verbose" ] ) ?;
103+ let mut distros = Vec :: new ( ) ;
104+ for raw in out. lines ( ) . skip ( 1 ) {
105+ let line = raw. trim ( ) ;
106+ if line. is_empty ( ) {
107+ continue ;
108+ }
109+ let default = line. starts_with ( '*' ) ;
110+ let line = line. trim_start_matches ( '*' ) . trim ( ) ;
111+ let parts: Vec < & str > = line. split_whitespace ( ) . collect ( ) ;
112+ if parts. len ( ) < 3 {
113+ continue ;
114+ }
115+ let state_idx = parts. len ( ) - 2 ;
116+ let name = parts[ ..state_idx] . join ( " " ) ;
117+ let state = parts[ state_idx] ;
118+ distros. push ( WslDistro {
119+ name,
120+ default,
121+ running : state. eq_ignore_ascii_case ( "Running" ) ,
122+ } ) ;
123+ }
124+ Ok ( distros)
125+ }
126+
100127#[ tauri:: command]
101- pub fn wsl_list_distros ( ) -> Result < Vec < WslDistro > , String > {
128+ pub async fn wsl_list_distros ( ) -> Result < Vec < WslDistro > , String > {
102129 #[ cfg( not( windows) ) ]
103130 {
104131 Ok ( Vec :: new ( ) )
105132 }
106133 #[ cfg( windows) ]
107134 {
108- let out = run_wsl ( & [ "--list" , "--verbose" ] ) ?;
109- let mut distros = Vec :: new ( ) ;
110- for raw in out. lines ( ) . skip ( 1 ) {
111- let line = raw. trim ( ) ;
112- if line. is_empty ( ) {
113- continue ;
114- }
115- let default = line. starts_with ( '*' ) ;
116- let line = line. trim_start_matches ( '*' ) . trim ( ) ;
117- let parts: Vec < & str > = line. split_whitespace ( ) . collect ( ) ;
118- if parts. len ( ) < 3 {
119- continue ;
120- }
121- let state_idx = parts. len ( ) - 2 ;
122- let name = parts[ ..state_idx] . join ( " " ) ;
123- let state = parts[ state_idx] ;
124- distros. push ( WslDistro {
125- name,
126- default,
127- running : state. eq_ignore_ascii_case ( "Running" ) ,
128- } ) ;
129- }
130- Ok ( distros)
135+ tauri:: async_runtime:: spawn_blocking ( list_distros_blocking)
136+ . await
137+ . map_err ( |e| e. to_string ( ) ) ?
131138 }
132139}
133140
134141#[ tauri:: command]
135- pub fn wsl_default_distro ( ) -> Result < Option < String > , String > {
136- let distros = wsl_list_distros ( ) ?;
137- Ok ( distros
138- . iter ( )
139- . find ( |d| d. default )
140- . map ( |d| d. name . clone ( ) )
141- . or_else ( || distros. first ( ) . map ( |d| d. name . clone ( ) ) ) )
142+ pub async fn wsl_default_distro ( ) -> Result < Option < String > , String > {
143+ #[ cfg( not( windows) ) ]
144+ {
145+ Ok ( None )
146+ }
147+ #[ cfg( windows) ]
148+ {
149+ tauri:: async_runtime:: spawn_blocking ( || {
150+ let distros = list_distros_blocking ( ) ?;
151+ Ok ( distros
152+ . iter ( )
153+ . find ( |d| d. default )
154+ . map ( |d| d. name . clone ( ) )
155+ . or_else ( || distros. first ( ) . map ( |d| d. name . clone ( ) ) ) )
156+ } )
157+ . await
158+ . map_err ( |e| e. to_string ( ) ) ?
159+ }
142160}
143161
144162#[ tauri:: command]
0 commit comments