feat: add optional Windows virtual USB ADB device
This commit is contained in:
1 parent
2abfb63da9
commit
08d60de364
23 files changed
+802
-26
No files matched your search
@@ -42,6 +42,9 @@ struct Args {
|
||||
/// Machine-readable active transport state for desktop clients
|
||||
#[arg(long)]
|
||||
status_file: Option<PathBuf>,
|
||||
/// Optional lease readiness file for virtual USB consumers (no secret tickets)
|
||||
#[arg(long)]
|
||||
lease_status_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -50,6 +53,15 @@ struct LeaseState {
|
||||
protocol: u8,
|
||||
}
|
||||
|
||||
fn publish_lease(args: &Args, ready: bool) {
|
||||
if let Some(file) = &args.lease_status_file {
|
||||
let temp = file.with_extension("tmp");
|
||||
if std::fs::write(&temp, if ready { "true" } else { "false" }).is_ok() {
|
||||
let _ = std::fs::rename(temp, file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn lease_once(args: &Args, state: &watch::Sender<Option<LeaseState>>) -> Result<()> {
|
||||
let mut ws = dial(
|
||||
args.network
|
||||
@@ -63,6 +75,7 @@ async fn lease_once(args: &Args, state: &watch::Sender<Option<LeaseState>>) -> R
|
||||
bail!("expected leased response");
|
||||
}
|
||||
let id = response.lease.context("missing lease ticket")?;
|
||||
publish_lease(args, true);
|
||||
state.send_replace(Some(LeaseState {
|
||||
id,
|
||||
protocol: response.protocol,
|
||||
@@ -80,6 +93,7 @@ async fn maintain_lease(args: Arc<Args>, state: watch::Sender<Option<LeaseState>
|
||||
if let Err(error) = lease_once(&args, &state).await {
|
||||
warn!(%error, "lease unavailable; reconnecting");
|
||||
}
|
||||
publish_lease(&args, false);
|
||||
state.send_replace(None);
|
||||
if started.elapsed() > Duration::from_secs(30) {
|
||||
delay = 1;
|
||||
@@ -164,6 +178,7 @@ async fn accept_connections(
|
||||
async fn main() -> Result<()> {
|
||||
init_logging();
|
||||
let args = Arc::new(Args::parse());
|
||||
publish_lease(&args, false);
|
||||
validate_token(&args.token)?;
|
||||
if !valid_device_id(&args.device) {
|
||||
bail!("invalid device ID");
|
||||
|
||||
Reference in new issue
Block a user