diff --git a/Cargo.lock b/Cargo.lock index 8025d2f..5ec875b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1831,7 +1831,7 @@ checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "isideload" -version = "0.2.0" +version = "0.2.1" dependencies = [ "aes 0.9.0-rc.4", "aes-gcm", diff --git a/examples/minimal/src/main.rs b/examples/minimal/src/main.rs index b6138b2..6c5f11d 100644 --- a/examples/minimal/src/main.rs +++ b/examples/minimal/src/main.rs @@ -117,7 +117,7 @@ async fn main() { }; let mut sideloader = SideloaderBuilder::new(dev_session, apple_id.to_string()) - .team_selection(TeamSelection::Prompt(team_selection_prompt)) + .team_selection(TeamSelection::PromptOnce(team_selection_prompt)) .max_certs_behavior(MaxCertsBehavior::Prompt(cert_selection_prompt)) .machine_name("isideload-minimal".to_string()) .build(); diff --git a/isideload/Cargo.toml b/isideload/Cargo.toml index 4f3c5ce..adf2c31 100644 --- a/isideload/Cargo.toml +++ b/isideload/Cargo.toml @@ -3,7 +3,7 @@ name = "isideload" description = "Sideload iOS/iPadOS applications" license = "MIT" authors = ["Nicholas Sharp "] -version = "0.2.0" +version = "0.2.1" edition = "2024" repository = "https://github.com/nab138/isideload" documentation = "https://docs.rs/isideload" diff --git a/isideload/src/sideload/builder.rs b/isideload/src/sideload/builder.rs index ba17b87..285455e 100644 --- a/isideload/src/sideload/builder.rs +++ b/isideload/src/sideload/builder.rs @@ -13,18 +13,22 @@ use crate::{ /// /// If there is only one team, it will be selected automatically regardless of this setting. /// If there are multiple teams, the behavior will depend on this setting. +#[derive(Clone)] pub enum TeamSelection { /// Select the first team automatically First, - /// Prompt the user to select a team - Prompt(fn(&Vec) -> Option), + /// Prompt the user to select a team the first time this sideloader is used, and remember the selection for future runs + PromptOnce(fn(&Vec) -> Option), + /// Prompt the user to select a team every time this sideloader is used + PromptAlways(fn(&Vec) -> Option), } impl Display for TeamSelection { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { TeamSelection::First => write!(f, "first team"), - TeamSelection::Prompt(_) => write!(f, "prompting for team"), + TeamSelection::PromptOnce(_) => write!(f, "prompting for team (once)"), + TeamSelection::PromptAlways(_) => write!(f, "prompting for team (always)"), } } } diff --git a/isideload/src/sideload/sideloader.rs b/isideload/src/sideload/sideloader.rs index 9e4f918..3cfd67a 100644 --- a/isideload/src/sideload/sideloader.rs +++ b/isideload/src/sideload/sideloader.rs @@ -31,6 +31,7 @@ pub struct Sideloader { max_certs_behavior: MaxCertsBehavior, //extensions_behavior: ExtensionsBehavior, delete_app_after_install: bool, + team: Option, } impl Sideloader { @@ -56,6 +57,7 @@ impl Sideloader { max_certs_behavior, //extensions_behavior, delete_app_after_install, + team: None, } } @@ -219,8 +221,11 @@ impl Sideloader { /// Get the developer team according to the configured team selection behavior pub async fn get_team(&mut self) -> Result { + if let Some(team) = &self.team { + return Ok(team.clone()); + } let teams = self.dev_session.list_teams().await?; - Ok(match teams.len() { + let team = match teams.len() { 0 => { bail!("No developer teams available") } @@ -232,7 +237,8 @@ impl Sideloader { ); match &self.team_selection { TeamSelection::First => teams.into_iter().next().unwrap(), - TeamSelection::Prompt(prompt_fn) => { + TeamSelection::PromptOnce(prompt_fn) + | TeamSelection::PromptAlways(prompt_fn) => { let selection = prompt_fn(&teams).ok_or_else(|| report!("No team selected"))?; teams @@ -242,6 +248,10 @@ impl Sideloader { } } } - }) + }; + if !matches!(&self.team_selection, TeamSelection::PromptAlways(_)) { + self.team = Some(team.clone()); + } + Ok(team) } }