@@ -4,32 +4,26 @@ use tauri::AppHandle;
44use tauri_plugin_os:: arch;
55use tauri_plugin_shell:: ShellExt ;
66
7- pub fn check_docker_status ( app : & AppHandle ) -> bool {
7+ pub fn check_docker_status ( app : & AppHandle ) -> Result < bool , String > {
88 let shell = app. shell ( ) ;
99 match tauri:: async_runtime:: block_on ( async move {
1010 shell. command ( "docker" ) . args ( [ "ps" ] ) . output ( ) . await
1111 } ) {
1212 Ok ( output) => {
1313 if output. status . success ( ) {
14- println ! ( "Result: {:?}" , String :: from_utf8( output. stdout) ) ;
15- return true ;
14+ return Ok ( true ) ;
1615 } else {
17- println ! ( "Exit with code: {}" , output. status. code( ) . unwrap( ) ) ;
18- return false ;
16+ return Err ( String :: from_utf8 ( output. stderr ) . unwrap ( ) ) ;
1917 }
2018 }
2119 Err ( e) => {
2220 println ! ( "Error: {}" , e) ;
23- return false ;
21+ return Err ( e . to_string ( ) ) ;
2422 }
2523 }
2624}
2725
28- pub fn start_cloudflare_resolver ( app : & AppHandle , port : usize ) -> bool {
29- if !check_docker_status ( app) {
30- return false ;
31- }
32-
26+ pub fn start_cloudflare_resolver ( app : & AppHandle , port : usize ) -> Result < bool , String > {
3327 let shell = app. shell ( ) ;
3428 let start_cmd = [ "start" , "novelscraper-cloudflare-resolver" ] ;
3529
@@ -38,16 +32,12 @@ pub fn start_cloudflare_resolver(app: &AppHandle, port: usize) -> bool {
3832 } ) {
3933 Ok ( start_output) => {
4034 if start_output. status . success ( ) {
41- println ! ( "Result: {:?}" , String :: from_utf8( start_output. stdout) ) ;
42- return true ;
43- } else {
44- println ! ( "Exit with code: {}" , start_output. status. code( ) . unwrap( ) ) ;
45- println ! ( "Error: {:?}" , String :: from_utf8( start_output. stderr) ) ;
35+ return Ok ( true ) ;
4636 }
4737 }
4838 Err ( e) => {
4939 println ! ( "Error: {}" , e) ;
50- return false ;
40+ return Err ( e . to_string ( ) ) ;
5141 }
5242 }
5343
@@ -77,22 +67,19 @@ pub fn start_cloudflare_resolver(app: &AppHandle, port: usize) -> bool {
7767 } ) {
7868 Ok ( run_output) => {
7969 if run_output. status . success ( ) {
80- println ! ( "Result: {:?}" , String :: from_utf8( run_output. stdout) ) ;
81- return true ;
70+ return Ok ( true ) ;
8271 } else {
83- println ! ( "Exit with code: {}" , run_output. status. code( ) . unwrap( ) ) ;
84- println ! ( "Error: {:?}" , String :: from_utf8( run_output. stderr) ) ;
85- return false ;
72+ return Err ( String :: from_utf8 ( run_output. stderr ) . unwrap ( ) ) ;
8673 }
8774 }
8875 Err ( e) => {
8976 println ! ( "Error: {}" , e) ;
90- return false ;
77+ return Err ( e . to_string ( ) ) ;
9178 }
9279 }
9380}
9481
95- pub fn stop_cloudflare_resolver ( app : & AppHandle ) -> bool {
82+ pub fn stop_cloudflare_resolver ( app : & AppHandle ) -> Result < bool , String > {
9683 let shell = app. shell ( ) ;
9784 match tauri:: async_runtime:: block_on ( async move {
9885 shell
@@ -103,16 +90,14 @@ pub fn stop_cloudflare_resolver(app: &AppHandle) -> bool {
10390 } ) {
10491 Ok ( output) => {
10592 if output. status . success ( ) {
106- println ! ( "Result: {:?}" , String :: from_utf8( output. stdout) ) ;
107- return true ;
93+ return Ok ( true ) ;
10894 } else {
109- println ! ( "Exit with code: {}" , output. status. code( ) . unwrap( ) ) ;
110- return false ;
95+ return Err ( String :: from_utf8 ( output. stderr ) . unwrap ( ) ) ;
11196 }
11297 }
11398 Err ( e) => {
11499 println ! ( "Error: {}" , e) ;
115- return false ;
100+ return Err ( e . to_string ( ) ) ;
116101 }
117102 }
118103}
0 commit comments