Sfoglia il codice sorgente

feat: use start detached for emulators (#6465)

Amr Bashir 2 anni fa
parent
commit
1798c5901d
4 ha cambiato i file con 182 aggiunte e 215 eliminazioni
  1. 167 189
      tooling/cli/Cargo.lock
  2. 1 1
      tooling/cli/Cargo.toml
  3. 11 12
      tooling/cli/src/mobile/android.rs
  4. 3 13
      tooling/cli/src/mobile/ios.rs

File diff suppressed because it is too large
+ 167 - 189
tooling/cli/Cargo.lock


+ 1 - 1
tooling/cli/Cargo.toml

@@ -39,7 +39,7 @@ name = "cargo-tauri"
 path = "src/main.rs"
 
 [dependencies]
-tauri-mobile = { version = "0.2.3", default-features = false, features = ["openssl-vendored"] }
+tauri-mobile = { git ="https://github.com/tauri-apps/tauri-mobile", version = "0.2.3", default-features = false, features = ["openssl-vendored"] }
 textwrap = { version = "0.11.0", features = [ "term_size" ] }
 jsonrpsee = { version = "0.16", features = [ "client", "server" ] }
 thiserror = "1"

+ 11 - 12
tooling/cli/src/mobile/android.rs

@@ -3,13 +3,7 @@
 // SPDX-License-Identifier: MIT
 
 use clap::{Parser, Subcommand};
-use std::{
-  env::set_var,
-  fs::create_dir,
-  process::exit,
-  thread::{sleep, spawn},
-  time::Duration,
-};
+use std::{env::set_var, fs::create_dir, process::exit, thread::sleep, time::Duration};
 use sublime_fuzzy::best_match;
 use tauri_mobile::{
   android::{
@@ -214,6 +208,7 @@ fn adb_device_prompt<'a>(env: &'_ Env, target: Option<&str>) -> Result<Device<'a
     } else {
       device_list.into_iter().next().unwrap()
     };
+
     log::info!(
       "Detected connected device: {} with target {:?}",
       device,
@@ -269,16 +264,20 @@ fn device_prompt<'a>(env: &'_ Env, target: Option<&str>) -> Result<Device<'a>> {
     Ok(device)
   } else {
     let emulator = emulator_prompt(env, target)?;
-    let handle = emulator.start(env)?;
-    spawn(move || {
-      let _ = handle.wait();
-    });
+    log::info!("Starting emulator {}", emulator.name());
+    emulator.start_detached(env)?;
+    let mut tries = 0;
     loop {
       sleep(Duration::from_secs(2));
       if let Ok(device) = adb_device_prompt(env, Some(emulator.name())) {
         return Ok(device);
       }
-      log::info!("Waiting for emulator to start...");
+      if tries >= 3 {
+        log::info!("Waiting for emulator to start... (maybe the emulator is unathorized or offline, run `adb devices` to check)");
+      } else {
+        log::info!("Waiting for emulator to start...");
+      }
+      tries += 1;
     }
   }
 }

+ 3 - 13
tooling/cli/src/mobile/ios.rs

@@ -33,11 +33,7 @@ use crate::{
   Result,
 };
 
-use std::{
-  process::exit,
-  thread::{sleep, spawn},
-  time::Duration,
-};
+use std::{process::exit, thread::sleep, time::Duration};
 
 mod build;
 mod dev;
@@ -241,10 +237,7 @@ fn simulator_prompt(env: &'_ Env, target: Option<&str>) -> Result<simctl::Device
     };
 
     log::info!("Starting simulator {}", device.name());
-    let handle = device.start(env)?;
-    spawn(move || {
-      let _ = handle.wait();
-    });
+    device.start_detached(env)?;
 
     Ok(device)
   } else {
@@ -257,10 +250,7 @@ fn device_prompt<'a>(env: &'_ Env, target: Option<&str>) -> Result<Device<'a>> {
     Ok(device)
   } else {
     let simulator = simulator_prompt(env, target)?;
-    let handle = simulator.start(env)?;
-    spawn(move || {
-      let _ = handle.wait();
-    });
+    simulator.start_detached(env)?;
     Ok(simulator.into())
   }
 }

Some files were not shown because too many files changed in this diff