Improve documentation and clean up temporary files

This commit is contained in:
nab138
2026-02-14 17:37:48 -05:00
parent eca2f98e72
commit f7926ad9d7
3 changed files with 25 additions and 1 deletions

View File

@@ -79,9 +79,11 @@ pub struct SideloaderBuilder {
//extensions_behavior: Option<ExtensionsBehavior>,
storage: Option<Box<dyn SideloadingStorage>>,
machine_name: Option<String>,
delete_app_after_install: bool,
}
impl SideloaderBuilder {
/// Create a new `SideloaderBuilder` with the provided Apple developer session and Apple ID email.
pub fn new(developer_session: DeveloperSession, apple_email: String) -> Self {
SideloaderBuilder {
team_selection: None,
@@ -90,6 +92,7 @@ impl SideloaderBuilder {
machine_name: None,
apple_email,
max_certs_behavior: None,
delete_app_after_install: true,
// extensions_behavior: None,
}
}
@@ -128,6 +131,12 @@ impl SideloaderBuilder {
self
}
/// Set whether to delete the signed app from the temporary storage after installation. Defaults to `true`.
pub fn delete_app_after_install(mut self, delete: bool) -> Self {
self.delete_app_after_install = delete;
self
}
// pub fn extensions_behavior(mut self, behavior: ExtensionsBehavior) -> Self {
// self.extensions_behavior = Some(behavior);
// self
@@ -145,6 +154,7 @@ impl SideloaderBuilder {
.unwrap_or_else(|| Box::new(crate::util::storage::new_storage())),
// self.extensions_behavior
// .unwrap_or(ExtensionsBehavior::RegisterAll),
self.delete_app_after_install,
)
}
}

View File

@@ -30,6 +30,7 @@ pub struct Sideloader {
apple_email: String,
max_certs_behavior: MaxCertsBehavior,
//extensions_behavior: ExtensionsBehavior,
delete_app_after_install: bool,
}
impl Sideloader {
@@ -44,6 +45,7 @@ impl Sideloader {
machine_name: String,
storage: Box<dyn SideloadingStorage>,
//extensions_behavior: ExtensionsBehavior,
delete_app_after_install: bool,
) -> Self {
Sideloader {
team_selection,
@@ -53,10 +55,11 @@ impl Sideloader {
apple_email,
max_certs_behavior,
//extensions_behavior,
delete_app_after_install,
}
}
/// Sign and install an app
/// Sign the app at the provided path and return the path to the signed app bundle (in a temp dir). To sign and install, see [`Self::install_app`].
pub async fn sign_app(
&mut self,
app_path: PathBuf,
@@ -178,10 +181,12 @@ impl Sideloader {
}
#[cfg(feature = "install")]
/// Sign and install an app to a device.
pub async fn install_app(
&mut self,
device_provider: &impl IdeviceProvider,
app_path: PathBuf,
// this is gross but will be replaced with proper entitlement handling later
increased_memory_limit: bool,
) -> Result<Option<SpecialApp>, Report> {
let device_info = IdeviceInfo::from_device(device_provider).await?;
@@ -203,8 +208,15 @@ impl Sideloader {
.await
.context("Failed to install app on device")?;
if self.delete_app_after_install {
if let Err(e) = tokio::fs::remove_dir_all(signed_app_path).await {
tracing::warn!("Failed to remove temporary signed app file: {}", e);
};
}
Ok(special_app)
}
/// Get the developer team according to the configured team selection behavior
pub async fn get_team(&mut self) -> Result<DeveloperTeam, Report> {
let teams = self.dev_session.list_teams().await?;

View File

@@ -3,6 +3,7 @@ use std::{collections::HashMap, sync::Mutex};
use base64::prelude::*;
use rootcause::prelude::*;
/// A trait for storing and retrieving sideloading related data, such as anisette state and certificates.
pub trait SideloadingStorage: Send + Sync {
fn store(&self, key: &str, value: &str) -> Result<(), Report>;
fn retrieve(&self, key: &str) -> Result<Option<String>, Report>;
@@ -24,6 +25,7 @@ pub trait SideloadingStorage: Send + Sync {
}
}
/// Factory function to create a new storage instance based on enabled features. The priority is `keyring-storage`, then `fs-storage`, and finally an in-memory storage if neither of those features are enabled.
pub fn new_storage() -> impl SideloadingStorage {
#[cfg(feature = "keyring-storage")]
{